comparison deep/stacked_dae/v_sylvain/nist_sda.py @ 282:698313f8f6e6

rajout de methode reliant toutes les couches cachees a la logistic et changeant seulement les parametres de la logistic durant finetune
author SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
date Wed, 24 Mar 2010 14:45:02 -0400
parents f14fb56b3f8d
children ed0443f7aad4
comparison
equal deleted inserted replaced
281:a8b92a4a708d 282:698313f8f6e6
66 examples_per_epoch=examples_per_epoch, \ 66 examples_per_epoch=examples_per_epoch, \
67 series=series, 67 series=series,
68 max_minibatches=rtt) 68 max_minibatches=rtt)
69 69
70 parameters=[] 70 parameters=[]
71 optimizer.pretrain(datasets.nist_P07()) 71 #Number of files of P07 used for pretraining
72 nb_file=0
73 if state['pretrain_choice'] == 0:
74 print('\n\tpretraining with NIST\n')
75 optimizer.pretrain(datasets.nist_all())
76 elif state['pretrain_choice'] == 1:
77 #To know how many file will be used during pretraining
78 nb_file = state['pretraining_epochs_per_layer']
79 state['pretraining_epochs_per_layer'] = 1 #Only 1 time over the dataset
80 if nb_file >=100:
81 sys.exit("The code does not support this much pretraining epoch (99 max with P07).\n"+
82 "You have to correct the code (and be patient, P07 is huge !!)\n"+
83 "or reduce the number of pretraining epoch to run the code (better idea).\n")
84 print('\n\tpretraining with P07')
85 optimizer.pretrain(datasets.nist_P07(min_file=0,max_file=nb_file))
72 channel.save() 86 channel.save()
73 87
74 #Set some of the parameters used for the finetuning 88 #Set some of the parameters used for the finetuning
75 if state.has_key('finetune_set'): 89 if state.has_key('finetune_set'):
76 finetune_choice=state['finetune_set'] 90 finetune_choice=state['finetune_set']
87 else: 101 else:
88 max_finetune_epoch_P07=max_finetune_epoch_NIST 102 max_finetune_epoch_P07=max_finetune_epoch_NIST
89 103
90 #Decide how the finetune is done 104 #Decide how the finetune is done
91 105
92 if finetune_choice==0: 106 if finetune_choice == 0:
93 print('\n\n\tfinetune avec nist\n\n') 107 print('\n\n\tfinetune with NIST\n\n')
94 optimizer.reload_parameters() 108 optimizer.reload_parameters('params_pretrain.txt')
95 optimizer.finetune(datasets.nist_all(),datasets.nist_P07(),max_finetune_epoch_NIST,ind_test=1) 109 optimizer.finetune(datasets.nist_all(),datasets.nist_P07(min_file=nb_file),max_finetune_epoch_NIST,ind_test=1)
96 if finetune_choice==1: 110 channel.save()
97 print('\n\n\tfinetune avec P07\n\n') 111 if finetune_choice == 1:
98 optimizer.reload_parameters() 112 print('\n\n\tfinetune with P07\n\n')
99 optimizer.finetune(datasets.nist_P07(),datasets.nist_all(),max_finetune_epoch_P07,ind_test=0) 113 optimizer.reload_parameters('params_pretrain.txt')
100 if finetune_choice==2: 114 optimizer.finetune(datasets.nist_P07(min_file=nb_file),datasets.nist_all(),max_finetune_epoch_P07,ind_test=0)
101 print('\n\n\tfinetune avec nist suivi de P07\n\n') 115 channel.save()
102 optimizer.reload_parameters() 116 if finetune_choice == 2:
103 optimizer.finetune(datasets.nist_all(),datasets.nist_P07(),max_finetune_epoch_NIST,ind_test=1) 117 print('\n\n\tfinetune with NIST followed by P07\n\n')
104 optimizer.finetune(datasets.nist_P07(),datasets.nist_all(),max_finetune_epoch_P07,ind_test=0) 118 optimizer.reload_parameters('params_pretrain.txt')
105 119 optimizer.finetune(datasets.nist_all(),datasets.nist_P07(min_file=nb_file),max_finetune_epoch_NIST,ind_test=21)
120 optimizer.finetune(datasets.nist_P07(min_file=nb_file),datasets.nist_all(),max_finetune_epoch_P07,ind_test=20)
121 channel.save()
122 if finetune_choice == 3:
123 print('\n\n\tfinetune with NIST only on the logistic regression on top (but validation on P07).\n\
124 All hidden units output are input of the logistic regression\n\n')
125 optimizer.reload_parameters('params_pretrain.txt')
126 optimizer.finetune(datasets.nist_all(),datasets.nist_P07(min_file=nb_file),max_finetune_epoch_NIST,ind_test=1,special=1)
127
128
106 if finetune_choice==-1: 129 if finetune_choice==-1:
107 print('\nSerie de 3 essais de fine-tuning') 130 print('\nSERIE OF 3 DIFFERENT FINETUNINGS')
108 print('\n\n\tfinetune avec nist\n\n') 131 print('\n\n\tfinetune with NIST\n\n')
109 optimizer.reload_parameters() 132 optimizer.reload_parameters('params_pretrain.txt')
110 optimizer.finetune(datasets.nist_all(),datasets.nist_P07(),max_finetune_epoch_NIST,ind_test=1) 133 optimizer.finetune(datasets.nist_all(),datasets.nist_P07(min_file=nb_file),max_finetune_epoch_NIST,ind_test=1)
111 channel.save() 134 channel.save()
112 print('\n\n\tfinetune avec P07\n\n') 135 print('\n\n\tfinetune with P07\n\n')
113 optimizer.reload_parameters() 136 optimizer.reload_parameters('params_pretrain.txt')
114 optimizer.finetune(datasets.nist_P07(),datasets.nist_all(),max_finetune_epoch_P07,ind_test=0) 137 optimizer.finetune(datasets.nist_P07(min_file=nb_file),datasets.nist_all(),max_finetune_epoch_P07,ind_test=0)
115 channel.save() 138 channel.save()
116 print('\n\n\tfinetune avec nist suivi de P07\n\n') 139 print('\n\n\tfinetune with NIST (done earlier) followed by P07 (written here)\n\n')
117 optimizer.reload_parameters() 140 optimizer.reload_parameters('params_finetune_NIST.txt')
118 optimizer.finetune(datasets.nist_all(),datasets.nist_P07(),max_finetune_epoch_NIST,ind_test=1) 141 optimizer.finetune(datasets.nist_P07(min_file=nb_file),datasets.nist_all(),max_finetune_epoch_P07,ind_test=20)
119 optimizer.finetune(datasets.nist_P07(),datasets.nist_all(),max_finetune_epoch_P07,ind_test=0) 142 channel.save()
143 print('\n\n\tfinetune with NIST only on the logistic regression on top.\n\
144 All hidden units output are input of the logistic regression\n\n')
145 optimizer.reload_parameters('params_pretrain.txt')
146 optimizer.finetune(datasets.nist_all(),datasets.nist_P07(min_file=nb_file),max_finetune_epoch_NIST,ind_test=1,special=1)
120 channel.save() 147 channel.save()
121 148
122 channel.save() 149 channel.save()
123 150
124 return channel.COMPLETE 151 return channel.COMPLETE