Fix filter must sum=0

This commit is contained in:
colin 2019-10-03 19:50:45 +08:00
parent 9628b2c17e
commit febad1f9c3
9 changed files with 23 additions and 19 deletions

2
.gitignore vendored
View File

@ -7,4 +7,4 @@ Dataset/
.vscode .vscode
/*/__pycache__ /*/__pycache__
.mypy_cache .mypy_cache
/FilterEvaluator/image* /*/image*

View File

@ -71,26 +71,27 @@ traindata, testdata = Loader.Cifar10Mono(batchsize, num_workers=0, shuffle=False
for batch_idx, (data, target) in enumerate(traindata): # for batch_idx, (data, target) in enumerate(traindata):
utils.NumpyToImage(data.cpu().detach().numpy(), CurrentPath+"image", title="TrainData") # utils.NumpyToImage(data.cpu().detach().numpy(), CurrentPath+"image", title="TrainData")
break # break
weight,active = EvaluatorUnsuper.UnsuperLearnSearchWeight(model, layer, traindata, NumSearch=1,SaveChannel=8,SearchChannelRatio=1, Interation=128) # weight, active = EvaluatorUnsuper.UnsuperLearnSearchWeight(
utils.NumpyToImage(weight, CurrentPath+"image",title="SearchWeight") # model, layer, traindata, NumSearch=10, SaveChannel=4000, SearchChannelRatio=32, Interation=10)
b =0
# weight,active = EvaluatorUnsuper.UnsuperLearnSearchWeight(model, layer, traindata, NumSearch=100000, SearchChannelRatio=32, Interation=10)
# np.save("WeightSearch.npy", weight)
# weight = np.load(CurrentPath+"WeightSearch.npy")
# utils.NumpyToImage(weight, CurrentPath+"image",title="SearchWeight") # utils.NumpyToImage(weight, CurrentPath+"image",title="SearchWeight")
# b =0
weight,active = EvaluatorUnsuper.UnsuperLearnSearchWeight(model, layer, traindata, NumSearch=100000, SearchChannelRatio=32, Interation=10)
np.save("WeightSearch.npy", weight)
weight = np.load(CurrentPath+"WeightSearch.npy")
utils.NumpyToImage(weight, CurrentPath+"image",title="SearchWeight")
# weight = np.load(CurrentPath+"WeightSearch.npy") # weight = np.load(CurrentPath+"WeightSearch.npy")
# bestweight,index = EvaluatorUnsuper.UnsuperLearnFindBestWeight(model,layer,weight,traindata,128,100000) # bestweight,index = EvaluatorUnsuper.UnsuperLearnFindBestWeight(model,layer,weight,traindata,128,100000)
# np.save(CurrentPath+"bestweightSearch.npy", bestweight) # np.save(CurrentPath+"bestweightSearch.npy", bestweight)

View File

@ -53,6 +53,9 @@ def UnsuperLearnSearchWeight(model, layer, dataloader, NumSearch=10000, SaveChan
minactive = np.empty((0)) minactive = np.empty((0))
minweight = np.empty([0,newweightshape[-3],newweightshape[-2],newweightshape[-1]]) minweight = np.empty([0,newweightshape[-3],newweightshape[-2],newweightshape[-1]])
newweight = np.random.uniform(-1.0,1.0,newweightshape).astype("float32") newweight = np.random.uniform(-1.0,1.0,newweightshape).astype("float32")
newweight = newweight.reshape((-1,newweightshape[-1]*newweightshape[-2]))
newweight = np.swapaxes(newweight,0,1)-np.mean(newweight,-1)
newweight = np.swapaxes(newweight,0,1).reshape(newweightshape)
dataset = [] dataset = []
for batch_idx, (data, target) in enumerate(dataloader): for batch_idx, (data, target) in enumerate(dataloader):

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB