-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathtest.py
More file actions
34 lines (25 loc) · 665 Bytes
/
Copy pathtest.py
File metadata and controls
34 lines (25 loc) · 665 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
33
34
import numpy as np
from PIL import Image
import keras
import sys
from keras.models import load_model
import matplotlib.pyplot as plt
# Load the model
model=load_model('models/transpose_seg/deconv_bnoptimized_munet.h5')
# Load a test image
im=Image.open(sys.argv[1])
# Inference
im=im.resize((128,128),Image.ANTIALIAS)
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