model = load_model('..\model\\best\\' + model_name + '.h5', custom_objects={'mean_squared_error': mean_squared_error , 'root_mean_squared_error': root_mean_squared_error, 'mean_absolute_error': mean_absolute_error}) # print(len(model.layers)) training_start = 0 training_num = 464 batch_size = 32 epochs = 2000 # data_preprocess_method = name_list.data_preprocess_method all_data, testing_data = file_helper_unformatted.load_sstha_for_conv2d(training_start, training_num) all_data = data_preprocess.data_preprocess(all_data, 0, data_preprocess_method) data_x, data_y = data_preprocess.sequence_data(all_data, input_length=time_step, prediction_month=prediction_month) if is_retrain: data_x = file_helper_unformatted.exchange_rows(data_x) data_y_nino = index_calculation.get_nino34_from_data_y(data_y) # print(data_y_nino) sc = np.linspace(0, 11, 12, dtype='int32') sc = np.tile(sc, int((training_num - training_start) / 12 + 1)) data_sc = sc[:(training_num - training_start - time_step + 1 - prediction_month + 1)] # all_data, testing_data = file_helper_unformatted.load_sstha_for_conv2d(training_start, all_num) # for layer in model.layers[:]: # layer.trainable = False # for layer in model.layers[6:20]: # layer.trainable = True
beta_1=0.9, beta_2=0.999, amsgrad=False) model.compile(optimizer=adam, loss=mean_squared_error, metrics=[ root_mean_squared_error, mean_absolute_error, mean_squared_error ]) model.summary() # to train model # the data for training is ssta and ha training_data, testing_data = file_helper_unformatted.load_sstha_for_conv2d( training_start, training_num) training_data = data_preprocess.data_preprocess(training_data, 0, data_preprocess_method) data_x, data_y = data_preprocess.sequence_data(training_data, input_length=time_step) print(data_x.shape, data_y.shape) # sc = np.linspace(0, 11, 12, dtype='int32') # sc = np.tile(sc, int((training_num-training_start)/12+1)) # data_sc = sc[:(training_num-training_start)] # tesorboard = TensorBoard('..\..\model\\tensorboard\\' + model_name) save_best = ModelCheckpoint('..\..\model\\best\\' + model_name + '.h5', monitor='val_root_mean_squared_error', verbose=1, save_best_only=True, mode='min', period=1) train_hist = model.fit(data_x,
data_sc = np.empty([1, 1], dtype='int32') data_y = np.empty([1, 20, 27, 2]) if is_nino_output: nino34_output = [] rmse_sst = [] nino_temp = 0 nino34 = [] # The time step for non-sequence prediction should be 1, but it was originally written as 0. # So it caused the inconsistency. for start_month in range( file_num - prediction_month * directly_month, file_num + month - prediction_month * directly_month + 1 - time_step, interval): if not is_sequence: predict_data[0] = file_helper_unformatted.read_data_sstaha( start_month) predict_data = data_preprocess.data_preprocess(predict_data, 0) else: for i in range(time_step): predict_data[0][i] = file_helper_unformatted.read_data_sstaha( start_month + i + 1) predict_data[0] = data_preprocess.data_preprocess( predict_data[0], 0) if is_retrain: predict_data = file_helper_unformatted.exchange_rows(predict_data) if model_type == 'conv': data_x[0] = predict_data[0] elif model_type == 'dense': data_x[0] = np.reshape(predict_data[0], (1, 1080)) for i in range(directly_month):