diff --git a/FilterEvaluator/Evaluator.py b/FilterEvaluator/Evaluator.py index a93c1c8..5f82c15 100644 --- a/FilterEvaluator/Evaluator.py +++ b/FilterEvaluator/Evaluator.py @@ -28,10 +28,8 @@ from tools import utils, Train, Loader, WebVisual import EvaluatorUnsuper - batchsize = 128 - # model = utils.SetDevice(Model.Net5Grad35()) # model = utils.SetDevice(Model.Net31535()) model = utils.SetDevice(Model.Net3Grad335()) @@ -44,8 +42,6 @@ layer = 0 - - # traindata, testdata = Loader.MNIST(batchsize) # traindata, testdata = Loader.RandomMnist(batchsize, style="Vertical") # traindata, testdata = Loader.RandomMnist(batchsize, style="Horizontal") @@ -59,24 +55,27 @@ traindata, testdata = Loader.Cifar10Mono(batchsize, num_workers=0, shuffle=True) # weight = EvaluatorUnsuper.UnsuperLearnSearchWeight(model, layer, traindata, NumSearch=100000, SearchChannelRatio=8, Interation=10) # np.save("WeightSearch.npy", weight) - -# weight = EvaluatorUnsuper.UnsuperLearnTrainWeight(model, layer, traindata, NumTrain=5000) -# np.save("WeightTrain.npy", weight) - - - - # weight = np.load(CurrentPath+"WeightSearch.npy") # bestweight,index = EvaluatorUnsuper.UnsuperLearnFindBestWeight(model,layer,weight,traindata,128,100000) # np.save(CurrentPath+"bestweightSearch.npy", bestweight) +# bestweight = np.load(CurrentPath+"bestweightSearch.npy") # utils.NumpyToImage(bestweight, CurrentPath+"image") +# EvaluatorUnsuper.SetModelConvWeight(model,layer,bestweight) +# utils.SaveModel(model,CurrentPath+"/checkpointSearch.pkl") -# weight = np.load(CurrentPath+"WeightTrain.npy") -# bestweight, index = EvaluatorUnsuper.UnsuperLearnFindBestWeight( -# model, layer, weight, traindata, databatchs=16, interation=1000000) -# np.save(CurrentPath+"bestweightTrain.npy", bestweight) -# utils.NumpyToImage(bestweight, CurrentPath+"image") + + +# weight = EvaluatorUnsuper.UnsuperLearnTrainWeight(model, layer, traindata, NumTrain=5000) +# np.save("WeightTrain.npy", weight) +weight = np.load(CurrentPath+"WeightTrain.npy") +bestweight, index = EvaluatorUnsuper.UnsuperLearnFindBestWeight(model, layer, weight, traindata, databatchs=128, interation=1000000) +np.save(CurrentPath+"bestweightTrain.npy", bestweight) +bestweight = np.load(CurrentPath+"bestweightTrain.npy") +utils.NumpyToImage(bestweight, CurrentPath+"image") +# EvaluatorUnsuper.SetModelConvWeight(model,layer,bestweight) +# utils.SaveModel(model,CurrentPath+"/checkpointTrain.pkl") + @@ -95,22 +94,6 @@ traindata, testdata = Loader.Cifar10Mono(batchsize, num_workers=0, shuffle=True) - -# weight = np.load(CurrentPath+"bestweightSearch.npy") -# EvaluatorUnsuper.SetModelConvWeight(model,layer,weight) -# utils.SaveModel(model,CurrentPath+"/checkpointSearch.pkl") - - -weight = np.load(CurrentPath+"bestweightTrain.npy") -EvaluatorUnsuper.SetModelConvWeight(model,layer,weight) -utils.SaveModel(model,CurrentPath+"/checkpointTrain.pkl") - - - - - - - # utils.NumpyToImage(weight, CurrentPath+"image") # utils.SaveModel(model,CurrentPath+"/checkpoint.pkl") print("save model sucess") diff --git a/FilterEvaluator/image/0-1024.png b/FilterEvaluator/image/0-1024.png index 73aede3..be95532 100644 Binary files a/FilterEvaluator/image/0-1024.png and b/FilterEvaluator/image/0-1024.png differ diff --git a/FilterEvaluator/visdom.server.log b/FilterEvaluator/visdom.server.log index 8457fc6..950625b 100644 Binary files a/FilterEvaluator/visdom.server.log and b/FilterEvaluator/visdom.server.log differ diff --git a/tools/WebVisual.py b/tools/WebVisual.py index 1e00b4b..79a6bcd 100644 --- a/tools/WebVisual.py +++ b/tools/WebVisual.py @@ -36,11 +36,8 @@ class Line(): self.size = 0 self.win = windows - def AppendData(self, y): - self.win.AppendData(self, y) - - def AppendData(self, x, y): - self.win.AppendData(self, x, y) + def AppendData(self, y, x=None): + self.win.AppendData(self, y, x) class LineWin(): @@ -70,26 +67,16 @@ class LineWin(): ) return Line(linename, len(y)) - def AppendData(self, line, y): - if not isinstance(y, list): - y = [y] - self.viz.line( - X=np.array(range(line.size, line.size+len(y))), - Y=np.array(y), - win=self.win, - update="append", - name=line.name - ) - line.size = line.size + len(y) - - def AppendData(self, line, x, y): - if not isinstance(y, list) and not isinstance(y, np.ndarray): - y = [y] - if not isinstance(x, list) and not isinstance(x, np.ndarray): + def AppendData(self, line, y, x=None): + y = [y] + Y = np.array(y).reshape((-1)) + X = [] + if x: x = [x] - X = np.array(x) - Y = np.array(y) - X = X[0:len(Y)] + X = np.array(X).reshape((-1)) + else: + X = np.array(range(line.size, line.size+len(Y))) + self.viz.line( Y=Y, X=X, diff --git a/tools/utils.py b/tools/utils.py index 88c62d8..de090e1 100755 --- a/tools/utils.py +++ b/tools/utils.py @@ -175,7 +175,7 @@ def NumpyToImage(numpydate, foldname, title="", maxImageWidth=128, maxImageHeigh data = numpydate.reshape((-1, numpydate.shape[-2], numpydate.shape[-1])) datashape = data.shape - newdata = np.ones((datashape[0],datashape[1]+1,datashape[2]+1))*numpydatemin + newdata = np.zeros((datashape[0],datashape[1]+1,datashape[2]+1)) newdata[:, 0:datashape[1], 0:datashape[2]]=data datashape = newdata.shape