Open vickylibra opened 4 years ago
Hi, After you use model.predict(img), you will get logits. You have to use argmax and then you will get the label. Now you have the labels, you can directly plot them plt.imshow(labels)
In the page itself, the author has given following code, use it: import numpy as np from PIL import Image from matplotlib import pyplot as plt
from model import Deeplabv3
trained_image_width=512 mean_subtraction_value=127.5 image = np.array(Image.open('imgs/image1.jpg'))
w, h, _ = image.shape ratio = float(trained_image_width) / np.max([w, h]) resized_image = np.array(Image.fromarray(image.astype('uint8')).resize((int(ratio h), int(ratio w))))
resized_image = (resized_image / mean_subtraction_value) - 1.
pad_x = int(trained_image_width - resized_image.shape[0]) pad_y = int(trained_image_width - resized_image.shape[1]) resized_image = np.pad(resized_image, ((0, pad_x), (0, pad_y), (0, 0)), mode='constant')
deeplab_model = Deeplabv3() res = deeplab_model.predict(np.expand_dims(resized_image, 0)) labels = np.argmax(res.squeeze(), -1)
if pad_x > 0: labels = labels[:-pad_x] if pad_y > 0: labels = labels[:, :-pad_y] labels = np.array(Image.fromarray(labels.astype('uint8')).resize((h, w)))
plt.imshow(labels)
After using predict(), I get labels now, but how can I get the labeled images? Sorry, I'm new in this, thanks!