Add more train to test entropy resualt.
This commit is contained in:
parent
e0de909d62
commit
18126824ee
|
@ -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)
|
||||
utils.NumpyToImage(bestweight, CurrentPath+"image",title="EntropySearchWerightBest")
|
||||
EvaluatorUnsuper.SetModelConvWeight(model,layer,bestweight)
|
||||
|
|
|
@ -137,7 +137,7 @@ def UnsuperLearnTrainWeight(model, layer, dataloader, NumTrain=500, TrainChannel
|
|||
|
||||
# search best weight from weight input
|
||||
def UnsuperLearnFindBestWeight(netmodel, layer, weight, dataloader, databatchs=128, interation=10000):
|
||||
interationbar = tqdm(total=interation)
|
||||
interationbar = tqdm(total=interation)
|
||||
weight = weight.astype("float32")
|
||||
netmodel.eval()
|
||||
tl = netmodel.features[layer]
|
||||
|
@ -179,10 +179,6 @@ def UnsuperLearnFindBestWeight(netmodel, layer, weight, dataloader, databatchs=1
|
|||
interationbar.close()
|
||||
return bestweight,indexs[sortindex]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# search best weight from random data
|
||||
def UnsuperLearnSearchBestWeight(netmodel, layer, dataloader, databatchs=128, stepsize=1000, interation=1000):
|
||||
interationbar = tqdm(total=interation)
|
||||
|
@ -295,9 +291,6 @@ def UnsuperLearnSearchBestWeight(netmodel, layer, dataloader, databatchs=128, st
|
|||
interationbar.close()
|
||||
return bestweight
|
||||
|
||||
|
||||
|
||||
|
||||
def SetModelConvWeight(model, layer, weight):
|
||||
w = utils.SetDevice(torch.from_numpy(weight))
|
||||
model.features[layer].weight.data = w
|
||||
|
|
|
@ -40,7 +40,7 @@ batchsize = 128
|
|||
|
||||
|
||||
# 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="Horizontal")
|
||||
# traindata, testdata = Loader.RandomMnist(batchsize, num_workers=4, style="VerticalOneLine")
|
||||
|
@ -54,7 +54,8 @@ window = WebVisual.LineWin()
|
|||
lineNoPre = WebVisual.Line(window, "NoPre")
|
||||
lineNoPreBN = WebVisual.Line(window, "NoPreBN")
|
||||
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())
|
||||
# bestweight = np.ones((model.features[0].weight.data.shape),dtype="float32")
|
||||
# EvaluatorUnsuper.SetModelConvWeight(model,0,bestweight)
|
||||
optimizer = optim.SGD(model.parameters(), lr=0.1)
|
||||
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.LoadModel(model, CurrentPath+"/checkpointEntropySearch.pkl")
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue