2626#module imports
2727from utils .load_conf import load_model ,load_rbm_spec ,load_data_spec
2828from models .dbn import DBN
29- from io_modules .file_io import read_dataset
29+ from io_modules .file_reader import read_dataset
3030from io_modules import setLogger
3131from utils .learn_rates import LearningRate
32+ from io_modules .model_io import _nnet2file , _file2nnet
3233
3334from models import fineTunning ,testing
3435
@@ -73,7 +74,8 @@ def preTraining(nnetModel,train_sets,train_xy,train_x,train_y,model_config):
7374 while not train_sets .is_finish ():
7475 train_sets .make_partition_shared (train_xy )
7576 #train_sets.load_next_partition(train_xy)
76- for batch_index in xrange (train_sets .cur_frame_num / batch_size ): # loop over mini-batches
77+ for batch_index in xrange (train_sets .cur_frame_num / batch_size ):
78+ # loop over mini-batches
7779 #logger.info("Training For epoch %d and batch %d",epoch,batch_index)
7880 [reconstruction_cost , free_energy_cost ] = pretraining_fns [i ](index = batch_index ,
7981 lr = pretrain_lr ,
@@ -82,7 +84,8 @@ def preTraining(nnetModel,train_sets,train_xy,train_x,train_y,model_config):
8284 fe_c .append (free_energy_cost )
8385 train_sets .read_next_partition_data ()
8486 train_sets .initialize_read ()
85- logger .info ('Training layer %i, epoch %d, r_cost %f, fe_cost %f' % (i , epoch , numpy .mean (r_c ), numpy .mean (fe_c )))
87+ logger .info ('Training layer %i, epoch %d, r_cost %f, fe_cost %f' ,
88+ i , epoch , numpy .mean (r_c ), numpy .mean (fe_c ))
8689 end_time = time .clock ()
8790 logger .info ('The PreTraing ran for %.2fm' % ((end_time - start_time ) / 60. ))
8891
@@ -105,19 +108,22 @@ def runRBM(configFile):
105108
106109 train_sets , train_xy , train_x , train_y = read_dataset (data_spec ['training' ])
107110
108- keep_layer_num = model_config ['keep_layer_num' ]
109- batch_size = model_config ['batch_size' ]
111+ keep_layer_num = model_config ['keep_layer_num' ]
112+ batch_size = model_config ['batch_size' ]
113+ wdir = model_config ['wdir' ]
110114
111115 if keep_layer_num > 0 :
112- # current_nnet = wdir + 'nnet.ptr.current'
116+ current_nnet = wdir + '/ nnet.ptr.current'
113117 logger .info ('Initializing model from ' + str (current_nnet ) + '....' )
114118 # load model
115- #_file2nnet(dbn.sigmoid_layers, set_layer_num = keep_layer_num, filename = current_nnet, withfinal=False)
119+ _file2nnet (dbn .sigmoid_layers , set_layer_num = keep_layer_num ,
120+ filename = current_nnet , withfinal = False )
116121
117122 preTraining (dbn ,train_sets ,train_xy ,train_x ,train_y ,model_config )
118123
119124 # save the pretrained nnet to file
120- #_nnet2file(dbn.sigmoid_layers, filename=output_file, withfinal=True)
125+ logger .info ('Saving model to ' + str (model_config ['output_file' ]) + '....' )
126+ _nnet2file (dbn .sigmoid_layers , filename = model_config ['output_file' ], withfinal = True )
121127
122128
123129 ########################
@@ -146,6 +152,8 @@ def runRBM(configFile):
146152 fineTunning (dbn ,train_sets ,train_xy ,train_x ,train_y ,
147153 valid_sets ,valid_xy ,valid_x ,valid_y ,lrate ,momentum ,batch_size )
148154
155+ logger .info ('Saving model to ' + str (model_config ['output_file' ]) + '.final ....' )
156+ _nnet2file (dbn .sigmoid_layers , filename = model_config ['output_file' ]+ '.final' , withfinal = True )
149157
150158 try :
151159 test_sets , test_xy , test_x , test_y = read_dataset (data_spec ['testing' ])
0 commit comments