end_learning_rate=0.000001 decay_steps=train_steps*nb_epoch power = 0.9 p = float(global_step)/float(decay_steps) lr = (learning_rate - end_learning_rate)*np.power(1-p, power)+end_learning_rate if global_step>0: curtime = '%s' % datetime.now() info = ' - lr: %.6f @ %s %d' %(lr, curtime.split('.')[0], global_step) print info, else: print 'learning_rate: %.6f - end_learning_rate: %.6f - decay_steps: %d' %(learning_rate, end_learning_rate, decay_steps) return lr inputs = keras.layers.Input(shape=(depth, 112, 112, 3), batch_shape=(batch_size, depth, 112, 112, 3)) feature = res3d_clstm_mobilenet(inputs, depth, weight_decay) flatten = keras.layers.Flatten(name='Flatten')(feature) classes = keras.layers.Dense(num_classes, activation='linear', kernel_initializer='he_normal', kernel_regularizer=l2(weight_decay), name='Classes_Congr')(flatten) outputs = keras.layers.Activation('softmax', name='Output')(classes) model = keras.models.Model(inputs=inputs, outputs=outputs) pretrained_model = '%s/trained_models/rcm/congr_rcm_rgb_weights.h5'%model_prefix print 'Loading pretrained model from %s' % pretrained_model model.load_weights(pretrained_model, by_name=False) for i in range(len(model.trainable_weights)): print model.trainable_weights[i] optimizer = keras.optimizers.SGD(lr=0.001, decay=0, momentum=0.9, nesterov=False) model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])
train_steps = len(train_labels)/batch_size _,test_labels = data.load_iso_video_list(testing_datalist) test_steps = len(test_labels)/batch_size print 'nb_epoch: %d - seq_len: %d - batch_size: %d - weight_decay: %.6f' %(nb_epoch, seq_len, batch_size, weight_decay) def lr_polynomial_decay(global_step): learning_rate = 0.001 end_learning_rate=0.000001 decay_steps=train_steps*nb_epoch power = 0.9 p = float(global_step)/float(decay_steps) lr = (learning_rate - end_learning_rate)*np.power(1-p, power)+end_learning_rate return lr inputs = keras.layers.Input(shape=(seq_len, 112, 112, 3), batch_shape=(batch_size, seq_len, 112, 112, 3)) feature = res3d_clstm_mobilenet(inputs, seq_len, weight_decay) flatten = keras.layers.Flatten(name='Flatten')(feature) classes = keras.layers.Dense(num_classes, activation='linear', kernel_initializer='he_normal', kernel_regularizer=l2(weight_decay), name='Classes')(flatten) outputs = keras.layers.Activation('softmax', name='Output')(classes) model = keras.models.Model(inputs=inputs, outputs=outputs) #pretrained_model = '%s/isogr_%s_gatedclstm_weights.h5'%(model_prefix,str_modality) #print 'Loading pretrained model from %s' % pretrained_model #model.load_weights(pretrained_model, by_name=False) for i in range(len(model.trainable_weights)): print model.trainable_weights[i] optimizer = keras.optimizers.SGD(lr=0.001, decay=0, momentum=0.9, nesterov=False) model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])