tr_loss.result().numpy(), "val_loss:", va_loss.result().numpy()) # Save the model for each epoch model.save_weights(filepath=model_name, save_format='tf') elif sys.argv[1] == "predict": # Step 3: Loads the weights model.load_weights(model_name) my_model = tf.keras.Sequential([model]) # Step 4: Prepare the input img = cv2.imread(sys.argv[2]) image = cv2.resize(img, (height, width), interpolation=cv2.INTER_AREA) images = np.array([image]) images = loader.scaling_tech(images, method="normalization") # Step 5: Predict the class preds = my_model.predict(images) preds = (preds[0] - preds.min()) / (preds.max() - preds.min()) images = np.hstack((images[0], preds)) images = cv2.resize(images, (width * 4, height * 2)) cv2.imshow("imgs", images) cv2.waitKey(0) elif sys.argv[1] == "predict_all": # Step 3: Loads the weights model.load_weights(model_name) my_model = tf.keras.Sequential([model]) # Step 4: Prepare the input
print(epoch, "/", epochs, step, steps, "loss:", tr_loss.result().numpy(), "val_loss:", va_loss.result().numpy()) # Save the model for each epoch model.save_weights(filepath=model_name, save_format='tf') elif sys.argv[1] == "predict": # Step 3: Loads the weights model.load_weights(model_name) my_model = tf.keras.Sequential([model]) # Step 4: Prepare the input img = cv2.imread(sys.argv[2]) image = cv2.resize(img, (height, width), interpolation=cv2.INTER_AREA) image = loader.scaling_tech(image, method="normalization") images = [] origin = [] for _ in range(5): k = np.random.choice([3, 5, 7, 9, 11, 13, 15, 17]) j = np.random.randint(1, 90) res = cv2.GaussianBlur(image, (k, k), j) images.append(res) origin.append(image) # True images images = np.array(images) origin = np.array(origin) # Step 5: Predict the class preds = my_model.predict(images)