epochs=epochs, validation_data=(test_dataset_x[0], feature_test_data), verbose=verbose) print('{} train:'.format(student.name), student_history.history['mean_squared_error']) print('{} test:'.format(student.name), student_history.history['val_mean_squared_error']) #dataset_update(student_history, student,parameters) student_predictions = student(test_dataset_x[0][:evaluate_prediction_size]) return student_predictions # student1_predictions = train_student(student1(), model, ) # student2_predictions = train_student(student2(), model, ) student3_predictions = train_student( student3(), model, ) # student_cnn_predictions = train_student(studentcnn(), model, ) with open( prediction_data_path + 'predictions_2_{}_{}_{}'.format(layer_name, feature, run_index), 'wb') as file_pi: pickle.dump( (feature_test_data[:evaluate_prediction_size], student3_predictions), file_pi)
pickle.dump(all_weights, file_pi) #LOAD WITH - pickle.load - and load manualy to model.get_layer.set_weights() #save weights with keras keras_weights_path = child_folder + '{}_keras_weights/'.format( feature_list) if not os.path.exists(keras_weights_path): os.mkdir(keras_weights_path) net.save_weights(keras_weights_path + 'keras_weights_{}_{}'.format(feature_list, traject)) #LOADING WITH - load_status = sequential_model.load_weights("ckpt") student = student3(sample=sample, res=res, activation='relu', dropout=dropout, rnn_dropout=rnn_dropout, num_feature=num_feature) student.evaluate(test_dataset_x[0], feature_test_data, verbose=2) student_history = student.fit( train_dataset_x[0], feature_train_data, batch_size=32, epochs=epochs, validation_data=(test_dataset_x[0], feature_test_data), verbose=verbose, callbacks=[model_checkpoint_callback, lr_reducer, early_stopper]) print('{} train:'.format(student.name), student_history.history['mean_squared_error']) print('{} test:'.format(student.name),
t_f = True feature_list = 'all' temp_path = path + 'saved_models/{}_feature/'.format(feature_list) home_folder = temp_path + '{}_{}_saved_models/'.format(feature_list, trajectory_index) checkpoint = t_f if checkpoint: child_folder = home_folder + 'checkpoint/' else: child_folder = home_folder + 'end_of_run_model/' #loading weights as numpy array numpy_weights_path = child_folder + '{}_numpy_weights/'.format(feature_list) with open(numpy_weights_path + 'numpy_weights_{}_{}'.format(feature_list,trajectory_index), 'rb') as file_pi: np_weights = pickle.load(file_pi) numpy_student = student3(activation = 'relu', dropout = 0.2, rnn_dropout = 0, num_feature = 64) layer_index = 0 for i in range(3): layer_name = 'convLSTM{}'.format(i+1) saved_weights = [np_weights[layer_index], np_weights[layer_index+ 1], np_weights[layer_index+ 2]] numpy_student.get_layer(layer_name).set_weights(saved_weights) layer_index += 3 res = 8 sample = 10 def full_student(student, decoder): input = keras.layers.Input(shape=(sample, res,res,3))\ student_features = student(input) decoder_prediction = decoder(student_features) model = keras.models.Model(inputs=input,outputs=decoder_prediction)
student_history.history['val_mean_squared_error']) dataset_update(student_history, student, parameters, name='sample_5') print(student.get_weights()[3][:4, :4]) save_model(student, save_model_path, parameters, checkpoint=False) student.load_weights(checkpoint_filepath) save_model(student, save_model_path, parameters, checkpoint=True) student.evaluate(test_dataset_x[0], feature_test_data, verbose=2) student_predictions = student(test_dataset_x[0]) train_predictions = student(train_dataset_x[0]) return student_predictions, train_predictions #jul 15 on 13:00 I chainged the activation to relu befor it was tanh (defoult) run 184770 /184790 #student1_predictions = train_student(student1(activation = 'relu'), model, ) #student2_predictions = train_student(student2(activation = 'relu'), model, ) student3_predictions, train3_predictions = train_student( student3(activation='relu', dropout=dropout, rnn_dropout=rnn_dropout), model, ) #student3_predictions = train_student(student3(activation = 'relu', dropout = dropout, rnn_dropout = rnn_dropout), model, ) #student_cnn_predictions = train_student(studentcnn(), model, ) with open( prediction_data_path + 'predictions_traject_{}_{}_{}_{}'.format( layer_name, feature, trajectory_index, run_index, ), 'wb') as file_pi: pickle.dump((feature_test_data, student3_predictions), file_pi)
validation_data=(test_dataset_x[0], feature_test_data), verbose = verbose, callbacks=[model_checkpoint_callback]) print('{} train:'.format(student.name), student_history.history['mean_squared_error']) print('{} test:'.format(student.name), student_history.history['val_mean_squared_error']) dataset_update(student_history, student,parameters, name = 'compare_traject') print(student.get_weights()[3][:4,:4]) save_model(student, save_model_path, parameters, checkpoint = False) student.load_weights(checkpoint_filepath) save_model(student, save_model_path, parameters, checkpoint = True) student.evaluate(test_dataset_x[0], feature_test_data, verbose = 2) student_predictions = student(test_dataset_x[0]) train_predictions = student(train_dataset_x[0]) return student_predictions, train_predictions #jul 15 on 13:00 I chainged the activation to relu befor it was tanh (defoult) run 184770 /184790 #student1_predictions = train_student(student1(activation = 'relu'), model, ) #student2_predictions = train_student(student2(activation = 'relu'), model, ) student3_predictions,train3_predictions = train_student(student3(activation = 'relu', dropout = dropout, rnn_dropout = rnn_dropout), model, ) #student3_predictions = train_student(student3(activation = 'relu', dropout = dropout, rnn_dropout = rnn_dropout), model, ) #student_cnn_predictions = train_student(studentcnn(), model, ) with open(prediction_data_path + 'predictions_traject_{}_{}_{}'.format(layer_name, feature, run_index), 'wb') as file_pi: pickle.dump((feature_test_data, student3_predictions, train3_predictions), file_pi)