Add more train to test entropy resualt.

This commit is contained in:
c 2019-12-27 18:04:51 +08:00
parent e0de909d62
commit 18126824ee
4 changed files with 12 additions and 14 deletions

View File

@ -74,7 +74,7 @@ traindata, testdata = Loader.MNIST(batchsize, shuffle=True, resize=7)
bestweight = EvaluatorUnsuper.UnsuperLearnSearchBestWeight(model,layer,traindata,32,20,250000) bestweight = EvaluatorUnsuper.UnsuperLearnSearchBestWeight(model,layer,traindata,8,20,250000)
np.save(CurrentPath+"bestweightEntropySearch.npy", bestweight) np.save(CurrentPath+"bestweightEntropySearch.npy", bestweight)
utils.NumpyToImage(bestweight, CurrentPath+"image",title="EntropySearchWerightBest") utils.NumpyToImage(bestweight, CurrentPath+"image",title="EntropySearchWerightBest")
EvaluatorUnsuper.SetModelConvWeight(model,layer,bestweight) EvaluatorUnsuper.SetModelConvWeight(model,layer,bestweight)

View File

@ -179,10 +179,6 @@ def UnsuperLearnFindBestWeight(netmodel, layer, weight, dataloader, databatchs=1
interationbar.close() interationbar.close()
return bestweight,indexs[sortindex] return bestweight,indexs[sortindex]
# search best weight from random data # search best weight from random data
def UnsuperLearnSearchBestWeight(netmodel, layer, dataloader, databatchs=128, stepsize=1000, interation=1000): def UnsuperLearnSearchBestWeight(netmodel, layer, dataloader, databatchs=128, stepsize=1000, interation=1000):
interationbar = tqdm(total=interation) interationbar = tqdm(total=interation)
@ -295,9 +291,6 @@ def UnsuperLearnSearchBestWeight(netmodel, layer, dataloader, databatchs=128, st
interationbar.close() interationbar.close()
return bestweight return bestweight
def SetModelConvWeight(model, layer, weight): def SetModelConvWeight(model, layer, weight):
w = utils.SetDevice(torch.from_numpy(weight)) w = utils.SetDevice(torch.from_numpy(weight))
model.features[layer].weight.data = w model.features[layer].weight.data = w

View File

@ -40,7 +40,7 @@ batchsize = 128
# traindata, testdata = Loader.MNIST(batchsize, num_workers=4, trainsize=5000) # traindata, testdata = Loader.MNIST(batchsize, num_workers=4, trainsize=5000)
traindata, testdata = Loader.MNIST(batchsize, resize=7, trainsize=200) traindata, testdata = Loader.MNIST(batchsize, resize=7, trainsize=50000)
# traindata, testdata = Loader.RandomMnist(batchsize, num_workers=4, style="Vertical") # traindata, testdata = Loader.RandomMnist(batchsize, num_workers=4, style="Vertical")
# traindata, testdata = Loader.RandomMnist(batchsize, num_workers=4, style="Horizontal") # traindata, testdata = Loader.RandomMnist(batchsize, num_workers=4, style="Horizontal")
# traindata, testdata = Loader.RandomMnist(batchsize, num_workers=4, style="VerticalOneLine") # traindata, testdata = Loader.RandomMnist(batchsize, num_workers=4, style="VerticalOneLine")
@ -54,7 +54,8 @@ window = WebVisual.LineWin()
lineNoPre = WebVisual.Line(window, "NoPre") lineNoPre = WebVisual.Line(window, "NoPre")
lineNoPreBN = WebVisual.Line(window, "NoPreBN") lineNoPreBN = WebVisual.Line(window, "NoPreBN")
linePretrainSearch = WebVisual.Line(window, "PretrainSearch") linePretrainSearch = WebVisual.Line(window, "PretrainSearch")
linePretrainTrain = WebVisual.Line(window, "PretrainTrain") linePreSubGrad = WebVisual.Line(window, "linePreSubGrad")
linePreAllGrad = WebVisual.Line(window, "linePreAllGrad")
@ -87,8 +88,6 @@ linePretrainTrain = WebVisual.Line(window, "PretrainTrain")
model = utils.SetDevice(Model.Net333()) model = utils.SetDevice(Model.Net333())
# bestweight = np.ones((model.features[0].weight.data.shape),dtype="float32")
# EvaluatorUnsuper.SetModelConvWeight(model,0,bestweight)
optimizer = optim.SGD(model.parameters(), lr=0.1) optimizer = optim.SGD(model.parameters(), lr=0.1)
Train.TrainEpochs(model,traindata,optimizer,testdata,3000,10,lineNoPre) Train.TrainEpochs(model,traindata,optimizer,testdata,3000,10,lineNoPre)
@ -101,7 +100,13 @@ Train.TrainEpochs(model,traindata,optimizer,testdata,3000,10,lineNoPre)
model = utils.SetDevice(Model.Net3Grad33()) model = utils.SetDevice(Model.Net3Grad33())
model = utils.LoadModel(model, CurrentPath+"/checkpointEntropySearch.pkl") model = utils.LoadModel(model, CurrentPath+"/checkpointEntropySearch.pkl")
optimizer = optim.SGD(model.parameters(), lr=0.1) optimizer = optim.SGD(model.parameters(), lr=0.1)
Train.TrainEpochs(model,traindata,optimizer,testdata,3000,10,linePretrainSearch) Train.TrainEpochs(model,traindata,optimizer,testdata,3000,10,linePreAllGrad)
model = utils.SetDevice(Model.Net3Grad33())
model = utils.LoadModel(model, CurrentPath+"/checkpointEntropySearch.pkl")
optimizer = optim.SGD(model.parameters(), lr=0.1)
Train.TrainEpochs(model,traindata,optimizer,testdata,3000,10,linePreSubGrad)

0
train
View File