Test Brutus ResNet

This commit is contained in:
Harle, Antoine (Contracteur) 2020-01-13 10:58:27 -05:00
parent 3425ba2ceb
commit 7732060eb1

View file

@ -35,16 +35,29 @@ if __name__ == "__main__":
n_inner_iter = 1 n_inner_iter = 1
epochs = 200 epochs = 150
dataug_epoch_start=0 dataug_epoch_start=0
optim_param={
'Meta':{
'optim':'Adam',
'lr':1e-2, #1e-2
},
'Inner':{
'optim': 'SGD',
'lr':1e-1, #1e-2
'momentum':0.9, #0.9
}
}
#model = LeNet(3,10) #model = LeNet(3,10)
model = MobileNetV2(num_classes=10) model = ResNet(num_classes=10)
#model = MobileNetV2(num_classes=10)
#model = WideResNet(num_classes=10, wrn_size=32) #model = WideResNet(num_classes=10, wrn_size=32)
tf_dict = {k: TF.TF_dict[k] for k in tf_names} tf_dict = {k: TF.TF_dict[k] for k in tf_names}
#### ####
'''
t0 = time.process_time() t0 = time.process_time()
aug_model = Augmented_model(RandAug(TF_dict=tf_dict, N_TF=2), model).to(device) aug_model = Augmented_model(RandAug(TF_dict=tf_dict, N_TF=2), model).to(device)
@ -60,9 +73,10 @@ if __name__ == "__main__":
with open("res/log/%s.json" % filename, "w+") as f: with open("res/log/%s.json" % filename, "w+") as f:
json.dump(out, f, indent=True) json.dump(out, f, indent=True)
print('Log :\"',f.name, '\" saved !') print('Log :\"',f.name, '\" saved !')
'''
#### ####
'''
t0 = time.process_time() t0 = time.process_time()
aug_model = Augmented_model(Data_augV5(TF_dict=tf_dict, N_TF=3, mix_dist=0.0, fixed_prob=False, fixed_mag=False, shared_mag=False), model).to(device) aug_model = Augmented_model(Data_augV5(TF_dict=tf_dict, N_TF=3, mix_dist=0.0, fixed_prob=False, fixed_mag=False, shared_mag=False), model).to(device)
@ -82,11 +96,11 @@ if __name__ == "__main__":
res_folder="res/brutus-tests/" res_folder="res/brutus-tests/"
epochs= 150 epochs= 150
inner_its = [1] inner_its = [1]
dist_mix = [1] dist_mix = [0.0, 0.5, 0.8, 1.0]
dataug_epoch_starts= [0] dataug_epoch_starts= [0]
tf_dict = {k: TF.TF_dict[k] for k in tf_names} tf_dict = {k: TF.TF_dict[k] for k in tf_names}
TF_nb = [len(tf_dict)] #range(10,len(TF.TF_dict)+1) #[len(TF.TF_dict)] TF_nb = [len(tf_dict)] #range(10,len(TF.TF_dict)+1) #[len(TF.TF_dict)]
N_seq_TF= [2, 3, 4] N_seq_TF= [2, 3]
mag_setup = [(True,True), (False, False)] mag_setup = [(True,True), (False, False)]
#prob_setup = [True, False] #prob_setup = [True, False]
nb_run= 3 nb_run= 3
@ -104,27 +118,34 @@ if __name__ == "__main__":
#for i in TF_nb: #for i in TF_nb:
for m_setup in mag_setup: for m_setup in mag_setup:
#for p_setup in prob_setup: #for p_setup in prob_setup:
p_setup=True
for run in range(nb_run): for run in range(nb_run):
if n_inner_iter == 0 and (m_setup!=(True,True) or p_setup!=True): continue #Autres setup inutiles sans meta-opti if n_inner_iter == 0 and (m_setup!=(True,True) and p_setup!=True): continue #Autres setup inutiles sans meta-opti
if n_tf ==2 and m_setup==(True,True): continue #Deja resultats
#keys = list(TF.TF_dict.keys())[0:i] #keys = list(TF.TF_dict.keys())[0:i]
#ntf_dict = {k: TF.TF_dict[k] for k in keys} #ntf_dict = {k: TF.TF_dict[k] for k in keys}
aug_model = Augmented_model(Data_augV5(TF_dict=tf_dict, N_TF=n_tf, mix_dist=dist, fixed_prob=False, fixed_mag=m_setup[0], shared_mag=m_setup[1]), LeNet(3,10)).to(device) aug_model = Augmented_model(Data_augV5(TF_dict=tf_dict, N_TF=n_tf, mix_dist=dist, fixed_prob=p_setup, fixed_mag=m_setup[0], shared_mag=m_setup[1]), model).to(device)
print(str(aug_model), 'on', device_name) #aug_model = Augmented_model(RandAug(TF_dict=tf_dict, N_TF=2), model).to(device)
#run_simple_dataug(inner_it=n_inner_iter, epochs=epochs)
log= run_dist_dataugV2(model=aug_model, epochs=epochs, inner_it=n_inner_iter, dataug_epoch_start=dataug_epoch_start, print_freq=20, loss_patience=None)
print("{} on {} for {} epochs - {} inner_it".format(str(aug_model), device_name, epochs, n_inner_iter))
log= run_dist_dataugV2(model=aug_model,
epochs=epochs,
inner_it=n_inner_iter,
dataug_epoch_start=dataug_epoch_start,
opt_param=optim_param,
print_freq=20,
KLdiv=True,
loss_patience=None)
exec_time=time.process_time() - t0
#### ####
print('-'*9) print('-'*9)
times = [x["time"] for x in log] times = [x["time"] for x in log]
out = {"Accuracy": max([x["acc"] for x in log]), "Time": (np.mean(times),np.std(times)), "Device": device_name, "Param_names": aug_model.TF_names(), "Log": log} out = {"Accuracy": max([x["acc"] for x in log]), "Time": (np.mean(times),np.std(times), exec_time), 'Optimizer': optim_param, "Device": device_name, "Param_names": aug_model.TF_names(), "Log": log}
print(str(aug_model),": acc", out["Accuracy"], "in:", out["Time"][0], "+/-", out["Time"][1]) print(str(aug_model),": acc", out["Accuracy"], "in:", out["Time"][0], "+/-", out["Time"][1])
filename = "{}-{}epochs(dataug:{})-{}in_it-{}".format(str(aug_model),epochs,dataug_epoch_start,n_inner_iter,run) filename = "{}-{} epochs (dataug:{})- {} in_it".format(str(aug_model),epochs,dataug_epoch_start,n_inner_iter)
with open(res_folder+"log/%s.json" % filename, "w+") as f: with open("res/log/%s.json" % filename, "w+") as f:
json.dump(out, f, indent=True) json.dump(out, f, indent=True)
print('Log :\"',f.name, '\" saved !') print('Log :\"',f.name, '\" saved !')
#plot_resV2(log, fig_name=res_folder+filename, param_names=tf_names)
print('-'*9) print('-'*9)
''' '''