mirror of
https://github.com/AntoineHX/smart_augmentation.git
synced 2025-05-04 04:00:46 +02:00
MaJ example simple + Suppression Nesterov momentum
This commit is contained in:
parent
b170af076f
commit
d53b385c43
4 changed files with 22 additions and 129 deletions
|
@ -19,7 +19,7 @@ optim_param={
|
||||||
'lr':1e-1, #1e-2/1e-1 (ResNet)
|
'lr':1e-1, #1e-2/1e-1 (ResNet)
|
||||||
'momentum':0.9, #0.9
|
'momentum':0.9, #0.9
|
||||||
'decay':0.0005, #0.0005
|
'decay':0.0005, #0.0005
|
||||||
'nesterov':True,
|
'nesterov':False, #False (True: Bad behavior w/ Data_aug)
|
||||||
'scheduler':'cosine', #None, 'cosine', 'multiStep', 'exponential'
|
'scheduler':'cosine', #None, 'cosine', 'multiStep', 'exponential'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,44 +30,6 @@ epochs= 200
|
||||||
dataug_epoch_start=0
|
dataug_epoch_start=0
|
||||||
nb_run= 3
|
nb_run= 3
|
||||||
|
|
||||||
# Use available TF (see transformations.py)
|
|
||||||
'''
|
|
||||||
tf_names = [
|
|
||||||
## Geometric TF ##
|
|
||||||
'Identity',
|
|
||||||
'FlipUD',
|
|
||||||
'FlipLR',
|
|
||||||
'Rotate',
|
|
||||||
'TranslateX',
|
|
||||||
'TranslateY',
|
|
||||||
'ShearX',
|
|
||||||
'ShearY',
|
|
||||||
|
|
||||||
## Color TF (Expect image in the range of [0, 1]) ##
|
|
||||||
'Contrast',
|
|
||||||
'Color',
|
|
||||||
'Brightness',
|
|
||||||
'Sharpness',
|
|
||||||
'Posterize',
|
|
||||||
'Solarize', #=>Image entre [0,1] #Pas opti pour des batch
|
|
||||||
|
|
||||||
## Bad Tranformations ##
|
|
||||||
# Bad Geometric TF #
|
|
||||||
#'BShearX',
|
|
||||||
#'BShearY',
|
|
||||||
#'BTranslateX-',
|
|
||||||
#'BTranslateX-',
|
|
||||||
#'BTranslateY',
|
|
||||||
#'BTranslateY-',
|
|
||||||
|
|
||||||
#'BadContrast',
|
|
||||||
#'BadBrightness',
|
|
||||||
|
|
||||||
#'Random',
|
|
||||||
#'RandBlend'
|
|
||||||
]
|
|
||||||
tf_dict = {k: TF.TF_dict[k] for k in tf_names}
|
|
||||||
'''
|
|
||||||
tf_config='../config/base_tf_config.json'
|
tf_config='../config/base_tf_config.json'
|
||||||
TF_loader=TF_loader()
|
TF_loader=TF_loader()
|
||||||
tf_dict, tf_ignore_mag =TF_loader.load_TF_dict(tf_config)
|
tf_dict, tf_ignore_mag =TF_loader.load_TF_dict(tf_config)
|
||||||
|
@ -91,7 +53,7 @@ if __name__ == "__main__":
|
||||||
### Benchmark ###
|
### Benchmark ###
|
||||||
#'''
|
#'''
|
||||||
n_inner_iter = 1
|
n_inner_iter = 1
|
||||||
dist_mix = [0.5]#[0.5, 1.0]
|
dist_mix = [0.5, 1.0]
|
||||||
N_seq_TF= [3, 4]
|
N_seq_TF= [3, 4]
|
||||||
mag_setup = [(False, False)] #[(True, True), (False, False)] #(FxSh, Independant)
|
mag_setup = [(False, False)] #[(True, True), (False, False)] #(FxSh, Independant)
|
||||||
|
|
||||||
|
@ -117,7 +79,8 @@ if __name__ == "__main__":
|
||||||
mix_dist=dist,
|
mix_dist=dist,
|
||||||
fixed_prob=False,
|
fixed_prob=False,
|
||||||
fixed_mag=m_setup[0],
|
fixed_mag=m_setup[0],
|
||||||
shared_mag=m_setup[1]),
|
shared_mag=m_setup[1],
|
||||||
|
TF_ignore_mag=tf_ignore_mag),
|
||||||
model).to(device)
|
model).to(device)
|
||||||
else:
|
else:
|
||||||
aug_model = Augmented_model(RandAug(TF_dict=tf_dict, N_TF=n_tf), model).to(device)
|
aug_model = Augmented_model(RandAug(TF_dict=tf_dict, N_TF=n_tf), model).to(device)
|
||||||
|
|
|
@ -2,31 +2,12 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from model import *
|
from LeNet import *
|
||||||
from dataug import *
|
from dataug import *
|
||||||
from train_utils import *
|
from train_utils import *
|
||||||
|
|
||||||
# Use available TF (see transformations.py)
|
tf_config='../config/base_tf_config.json'
|
||||||
tf_names = [
|
TF_loader=TF_loader()
|
||||||
## Geometric TF ##
|
|
||||||
'Identity',
|
|
||||||
'FlipUD',
|
|
||||||
'FlipLR',
|
|
||||||
'Rotate',
|
|
||||||
'TranslateX',
|
|
||||||
'TranslateY',
|
|
||||||
'ShearX',
|
|
||||||
'ShearY',
|
|
||||||
|
|
||||||
## Color TF (Expect image in the range of [0, 1]) ##
|
|
||||||
'Contrast',
|
|
||||||
'Color',
|
|
||||||
'Brightness',
|
|
||||||
'Sharpness',
|
|
||||||
'Posterize',
|
|
||||||
'Solarize', #=>Image entre [0,1] #Pas opti pour des batch
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
device = torch.device('cuda') #Select device to use
|
device = torch.device('cuda') #Select device to use
|
||||||
|
|
||||||
|
@ -48,19 +29,19 @@ if __name__ == "__main__":
|
||||||
},
|
},
|
||||||
'Inner':{
|
'Inner':{
|
||||||
'optim': 'SGD',
|
'optim': 'SGD',
|
||||||
'lr':1e-2, #1e-2
|
'lr':1e-2, #1e-2/1e-1 (ResNet)
|
||||||
'momentum':0.9, #0.9
|
'momentum':0.9, #0.9
|
||||||
|
'decay':0.0005, #0.0005
|
||||||
|
'nesterov':False, #False (True: Bad behavior w/ Data_aug)
|
||||||
|
'scheduler':'cosine', #None, 'cosine', 'multiStep', 'exponential'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Models
|
#Models
|
||||||
model = LeNet(3,10)
|
model = LeNet(3,10)
|
||||||
#model = ResNet(num_classes=10)
|
|
||||||
#model = MobileNetV2(num_classes=10)
|
|
||||||
#model = WideResNet(num_classes=10, wrn_size=32)
|
|
||||||
|
|
||||||
#Smart_aug initialisation
|
#Smart_aug initialisation
|
||||||
tf_dict = {k: TF.TF_dict[k] for k in tf_names}
|
tf_dict, tf_ignore_mag =TF_loader.load_TF_dict(tf_config)
|
||||||
model = Higher_model(model) #run_dist_dataugV3
|
model = Higher_model(model) #run_dist_dataugV3
|
||||||
aug_model = Augmented_model(
|
aug_model = Augmented_model(
|
||||||
Data_augV5(TF_dict=tf_dict,
|
Data_augV5(TF_dict=tf_dict,
|
||||||
|
@ -68,7 +49,8 @@ if __name__ == "__main__":
|
||||||
mix_dist=0.8,
|
mix_dist=0.8,
|
||||||
fixed_prob=False,
|
fixed_prob=False,
|
||||||
fixed_mag=False,
|
fixed_mag=False,
|
||||||
shared_mag=False),
|
shared_mag=False,
|
||||||
|
TF_ignore_mag=tf_ignore_mag),
|
||||||
model).to(device)
|
model).to(device)
|
||||||
|
|
||||||
print("{} on {} for {} epochs - {} inner_it".format(str(aug_model), device_name, epochs, n_inner_iter))
|
print("{} on {} for {} epochs - {} inner_it".format(str(aug_model), device_name, epochs, n_inner_iter))
|
||||||
|
|
|
@ -7,58 +7,7 @@ from dataug import *
|
||||||
#from utils import *
|
#from utils import *
|
||||||
from train_utils import *
|
from train_utils import *
|
||||||
|
|
||||||
# Use available TF (see transformations.py)
|
postfix=''
|
||||||
'''
|
|
||||||
tf_names = [
|
|
||||||
## Geometric TF ##
|
|
||||||
'Identity',
|
|
||||||
'FlipUD',
|
|
||||||
'FlipLR',
|
|
||||||
'Rotate',
|
|
||||||
'TranslateX',
|
|
||||||
'TranslateY',
|
|
||||||
'ShearX',
|
|
||||||
'ShearY',
|
|
||||||
|
|
||||||
#'TranslateXabs',
|
|
||||||
#'TranslateYabs',
|
|
||||||
|
|
||||||
## Color TF (Expect image in the range of [0, 1]) ##
|
|
||||||
'Contrast',
|
|
||||||
'Color',
|
|
||||||
'Brightness',
|
|
||||||
'Sharpness',
|
|
||||||
'Posterize',
|
|
||||||
'Solarize',
|
|
||||||
|
|
||||||
#Color TF (Common mag scale)
|
|
||||||
#'+Contrast',
|
|
||||||
#'+Color',
|
|
||||||
#'+Brightness',
|
|
||||||
#'+Sharpness',
|
|
||||||
#'-Contrast',
|
|
||||||
#'-Color',
|
|
||||||
#'-Brightness',
|
|
||||||
#'-Sharpness',
|
|
||||||
#'=Posterize',
|
|
||||||
#'=Solarize',
|
|
||||||
|
|
||||||
## Bad Tranformations ##
|
|
||||||
# Bad Geometric TF #
|
|
||||||
#'BShearX',
|
|
||||||
#'BShearY',
|
|
||||||
#'BTranslateX-',
|
|
||||||
#'BTranslateX-',
|
|
||||||
#'BTranslateY',
|
|
||||||
#'BTranslateY-',
|
|
||||||
|
|
||||||
#'BadContrast',
|
|
||||||
#'BadBrightness',
|
|
||||||
|
|
||||||
#'Random',
|
|
||||||
#'RandBlend'
|
|
||||||
]
|
|
||||||
'''
|
|
||||||
TF_loader=TF_loader()
|
TF_loader=TF_loader()
|
||||||
|
|
||||||
device = torch.device('cuda') #Select device to use
|
device = torch.device('cuda') #Select device to use
|
||||||
|
@ -84,7 +33,7 @@ if __name__ == "__main__":
|
||||||
}
|
}
|
||||||
#Parameters
|
#Parameters
|
||||||
n_inner_iter = 1
|
n_inner_iter = 1
|
||||||
epochs = 20
|
epochs = 2
|
||||||
dataug_epoch_start=0
|
dataug_epoch_start=0
|
||||||
optim_param={
|
optim_param={
|
||||||
'Meta':{
|
'Meta':{
|
||||||
|
@ -96,7 +45,7 @@ if __name__ == "__main__":
|
||||||
'lr':1e-1, #1e-2/1e-1 (ResNet)
|
'lr':1e-1, #1e-2/1e-1 (ResNet)
|
||||||
'momentum':0.9, #0.9
|
'momentum':0.9, #0.9
|
||||||
'decay':0.0005, #0.0005
|
'decay':0.0005, #0.0005
|
||||||
'nesterov':True,
|
'nesterov':False, #False (True: Bad behavior w/ Data_aug)
|
||||||
'scheduler':'cosine', #None, 'cosine', 'multiStep', 'exponential'
|
'scheduler':'cosine', #None, 'cosine', 'multiStep', 'exponential'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +110,6 @@ if __name__ == "__main__":
|
||||||
if 'aug_model' in tasks:
|
if 'aug_model' in tasks:
|
||||||
tf_config='../config/base_tf_config.json'
|
tf_config='../config/base_tf_config.json'
|
||||||
tf_dict, tf_ignore_mag =TF_loader.load_TF_dict(tf_config)
|
tf_dict, tf_ignore_mag =TF_loader.load_TF_dict(tf_config)
|
||||||
#tf_dict = {k: TF_dict[k] for k in tf_names}
|
|
||||||
|
|
||||||
torch.cuda.reset_max_memory_allocated() #reset_peak_stats
|
torch.cuda.reset_max_memory_allocated() #reset_peak_stats
|
||||||
torch.cuda.reset_max_memory_cached() #reset_peak_stats
|
torch.cuda.reset_max_memory_cached() #reset_peak_stats
|
||||||
|
@ -170,7 +118,7 @@ if __name__ == "__main__":
|
||||||
model = Higher_model(model, model_name) #run_dist_dataugV3
|
model = Higher_model(model, model_name) #run_dist_dataugV3
|
||||||
aug_model = Augmented_model(
|
aug_model = Augmented_model(
|
||||||
Data_augV5(TF_dict=tf_dict,
|
Data_augV5(TF_dict=tf_dict,
|
||||||
N_TF=3,
|
N_TF=1,
|
||||||
mix_dist=0.5,
|
mix_dist=0.5,
|
||||||
fixed_prob=False,
|
fixed_prob=False,
|
||||||
fixed_mag=False,
|
fixed_mag=False,
|
||||||
|
@ -184,10 +132,10 @@ if __name__ == "__main__":
|
||||||
inner_it=n_inner_iter,
|
inner_it=n_inner_iter,
|
||||||
dataug_epoch_start=dataug_epoch_start,
|
dataug_epoch_start=dataug_epoch_start,
|
||||||
opt_param=optim_param,
|
opt_param=optim_param,
|
||||||
print_freq=1,
|
print_freq=20,
|
||||||
unsup_loss=1,
|
unsup_loss=1,
|
||||||
hp_opt=False,
|
hp_opt=False,
|
||||||
save_sample_freq=0)
|
save_sample_freq=None)
|
||||||
|
|
||||||
exec_time=time.perf_counter() - t0
|
exec_time=time.perf_counter() - t0
|
||||||
max_allocated = torch.cuda.max_memory_allocated()/(1024.0 * 1024.0)
|
max_allocated = torch.cuda.max_memory_allocated()/(1024.0 * 1024.0)
|
||||||
|
@ -204,7 +152,7 @@ if __name__ == "__main__":
|
||||||
"Param_names": aug_model.TF_names(),
|
"Param_names": aug_model.TF_names(),
|
||||||
"Log": log}
|
"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)
|
filename = "{}-{} epochs (dataug:{})- {} in_it".format(str(aug_model),epochs,dataug_epoch_start,n_inner_iter)+postfix
|
||||||
with open("../res/log/%s.json" % filename, "w+") as f:
|
with open("../res/log/%s.json" % filename, "w+") as f:
|
||||||
try:
|
try:
|
||||||
json.dump(out, f, indent=True)
|
json.dump(out, f, indent=True)
|
||||||
|
|
|
@ -19,7 +19,7 @@ import kornia
|
||||||
import random
|
import random
|
||||||
|
|
||||||
#TF that don't have use for magnitude parameter.
|
#TF that don't have use for magnitude parameter.
|
||||||
TF_no_mag={'Identity', 'FlipUD', 'FlipLR', 'Random', 'RandBlend', 'identity', 'flipUD', 'flipLR'}
|
TF_no_mag={'Identity', 'FlipUD', 'FlipLR', 'Random', 'RandBlend', 'identity', 'flip'}
|
||||||
#TF which implemetation doesn't allow gradient propagaition.
|
#TF which implemetation doesn't allow gradient propagaition.
|
||||||
TF_no_grad={'Solarize', 'Posterize', '=Solarize', '=Posterize', 'posterize','solarize'}
|
TF_no_grad={'Solarize', 'Posterize', '=Solarize', '=Posterize', 'posterize','solarize'}
|
||||||
#TF for which magnitude should be ignored (Magnitude fixed).
|
#TF for which magnitude should be ignored (Magnitude fixed).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue