batchA_images, batchB_images = img_process.shuffle_data( trainA_paths, trainB_paths) train_feed_dict = { image_u: batchA_images, image_r: batchB_images, learning_rate: epoch_learning_rate, training_flag: True } _, summary_str = sess.run([train_op, all_sum], feed_dict=train_feed_dict) train_summary_writer.add_summary(summary=summary_str, global_step=counter) # batch_loss = sess.run(errG, feed_dict=train_feed_dict) # total_loss.append(batch_loss) counter += 1 end_time = time.time() # train_loss = np.mean(total_loss) line = "epoch: %d/%d, time cost: %.4f\n" % ( epoch, total_epochs, float(end_time - start_time)) # line = "epoch: %d/%d, train loss: %.4f, time cost: %.4f\n" % (epoch, total_epochs, float(train_loss), float(end_time - start_time)) print(line) if epoch % 10 == 0: U_NET.save(sess=sess, model_path=ckpt_path + str(epoch) + 'u_net.ckpt')
print('--------------Loaded Data----------------') # Import Unet model model = UNet() # Train the model history = model.fit(trainx_cropped, trainy_hot, validation_data=(validationx_cropped, validationy_hot), epochs=50, batch_size=16, verbose=1) # Save the model model.save("/home/data/IIRS/PS1-Project/src/trained_model.h5") print('--------------Training Completed----------------') # list all data in history print(history.history.keys()) # summarize history for accuracy plt.plot(history.history['acc']) plt.plot(history.history['val_acc']) plt.title('Model accuracy') plt.ylabel('Accuracy') plt.xlabel('Epoch') plt.legend(['train', 'val'], loc='upper left') plt.savefig('Accuracy_Plot.png')
### print('--------------Loaded Data----------------') # Import Unet model model = UNet() # Load trained weights # model.load_weights(weights_file) # Train the model history = model.fit(trainx_cropped, trainy_hot, validation_data=( validationx_cropped, validationy_hot), epochs=30, batch_size=16, verbose=1) # Save the model model.save("/home/data/IIRS/December-Testing/TrainedModels/trained_model_sar-v2.h5") print('--------------Training Completed----------------') # list all data in history print(history.history.keys()) # summarize history for accuracy plt.plot(history.history['acc']) plt.plot(history.history['val_acc']) plt.title('Model accuracy') plt.ylabel('Accuracy') plt.xlabel('Epoch') plt.legend(['train', 'val'], loc='upper left') plt.savefig('Accuracy_Plot-SAR-2.png')