【发布时间】:2020-01-30 14:21:17
【问题描述】:
我已经使用图像和掩码训练了一个模型,并预测了一个图像。
我预测的图像的形状是(1024,1024,3)
代码。
nueva_imagen = cv2.imread("../input/dataset/Training_dataset/Images/all_imgs/zanzibar_4_35_04.jpg")
print(nueva_imagen.shape)
nueva_imagen = cv2.resize(nueva_imagen,(256,256))
nueva_imagen = np.expand_dims(nueva_imagen,axis=0)
print(nueva_imagen.shape)
pred_img = model.predict(nueva_imagen)
print(pred_img.shape)
#pred_img = np.squeeze(pred_img,axis=0)
#print(pred_img.shape)
我添加另一个维度的原因是因为我的模型只拍摄 3 维度的图像。
最后我预测的图像形状是(1,256,256,1)
现在阅读 cv2 文档我无法显示 4 维图像,所以这就是我所做的。
image_to_predict = _images[789]
mask_of_image = masks_arr[789]
pred_img = np.squeeze(pred_img,axis=0)
pred_img = np.squeeze(pred_img,axis=2)
fig = plt.figure()
fig.subplots_adjust(hspace=0.4, wspace=0.4)
ax = fig.add_subplot(1, 2, 1);plt.title("original image")
ax.imshow(image_to_predict)
#ax = fig.add_subplot(1, 2, 2);plt.title("mask")
#ax.imshow(mask_of_image)
ax = fig.add_subplot(1,2,2);plt.title("Predicted image")
ax.imshow(pred_img)
我删除了轴 0 和 3 上的尺寸以显示图像,但我得到的是紫色图像。 这是预测的图像还是我做错了什么?
【问题讨论】:
标签: python tensorflow machine-learning deep-learning semantic-segmentation