-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pre.py
42 lines (40 loc) · 1.21 KB
/
Pre.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
37
38
39
40
41
42
from keras.preprocessing import image
from modelt import bulid_model
import os
import glob
import numpy as np
import matplotlib.pyplot as plt
import cv2
import keras.backend as K
img_shape = (256,256,3)
model = bulid_model(img_shape)
model.summary()
img_h = 256
img_w = 256
#img_h = 2048
#img_w = 1024
#image_path = 'ADEChallengeData2016/images/validation/ADE_val_00000731.jpg'
image_path = 'ADEChallengeData2016/images/training/ADE_train_00000693.jpg'
weights_path = 'weights/weights-163-1.78.h5'
gt_ = 'ADEChallengeData2016/annotations/training/ADE_train_00000693.png'
model.load_weights(weights_path)
## Get current learning rate
#print("model optimizer: {}".format(model.optimizer))
#print("Current lr: {}".format(K.eval(model.optimizer.lr)))
img_gt = image.load_img(gt_,target_size=(img_h,img_w))
img_gt = image.img_to_array(img_gt)
#img_gt = img_gt[:,:,0]
#cv2.imshow('gt',img_gt)
img = image.load_img(image_path,target_size=(img_h,img_w))
x = image.img_to_array(img)
x /= 255
x = np.expand_dims(x,axis=0)
pred = model.predict(x)[0]
pred = np.argmax(pred,2)
print('pred shape is {}'.format(pred.shape))
print(pred.shape[:-1])
#print(img_gt)
#pred[pred==0] = 255
pred = np.array(pred,dtype=np.uint8)
plt.imshow(pred)
plt.show()