-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
32 lines (24 loc) · 669 Bytes
/
Copy pathtest.py
File metadata and controls
32 lines (24 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import matplotlib.pyplot as plt
import cv2
import numpy as np
from tensorflow.keras.models import load_model
# Load the model
model = load_model("models/transpose_seg/deconv_bnoptimized_munet.h5")
# Load a test image
im = cv2.imread(sys.argv[1])
# Inference
im = cv2.resize(im, (128, 128))
img = np.float32(np.array(im) / 255.0)
img = img[:, :, 0:3]
# Reshape input and threshold output
out = model.predict(img.reshape(1, 128, 128, 3))
out = np.float32((out > 0.5)).reshape(128, 128, 1)
# Input image
plt.figure("Input")
plt.imshow(img)
# Output image
plt.figure("Output")
plt.imshow(out * img)
plt.show()
# Sample run: python test.py test/four.jpeg