-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinference.py
36 lines (27 loc) · 1.03 KB
/
inference.py
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
35
36
import matplotlib.pyplot as plt
import numpy as np
import os
import cv2
from keras.optimizers import Adam
from segmentation_models.losses import bce_dice_loss
from segmentation_models.metrics import dice_score, jaccard_score
from keras.models import model_from_json
HEIGHT, WIDTH, DEPTH = 224, 224, 3
if __name__ == '__main__':
json = 'models/linknet_layers_3_classes.json'
weight = 'models/linknet_layers_3_classes.h5'
json = open(json, 'r')
model = model_from_json(json.read())
model.load_weights(weight)
model.compile(optimizer=Adam(1e-3), loss=bce_dice_loss, metrics=[dice_score, jaccard_score])
model.summary()
image = cv2.imread('161.jpg', cv2.IMREAD_UNCHANGED)
original = cv2.resize(image, (HEIGHT, WIDTH))
image = original.reshape(1, HEIGHT, WIDTH, DEPTH)
predict = model.predict(image)
fig, axes = plt.subplots(2, 2)
axes[0, 0].imshow(original)
axes[0, 1].imshow(predict[0, :, :, 0])
axes[1, 0].imshow(predict[0, :, :, 1])
axes[1, 1].imshow(predict[0, :, :, 2])
plt.show()