【发布时间】:2018-10-28 21:53:49
【问题描述】:
我正在使用语义分割网络 (SegNet)。我正在尝试减少类的数量,从而重新安排网络。
因此,我还要更改预测的颜色编码。我的问题是我没有在输出图像中得到预期的颜色。
例如
pascal_palette = np.array([(0, 0, 0),
(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
(0, 0, 128), (0, 128, 0), (0, 0, 0), (0, 0, 0), (128, 0, 0),
(0, 0, 0), (0, 0, 0)
], dtype=np.uint8)
上一行给出了三个类的完美结果,因为像素仅在 1 个通道中。
输出如下:
但是,如果我修改该行并将值添加到不同的通道,它会给出奇怪的输出。输出附在下面:
pascal_palette = np.array([(0, 0, 0),
(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
(0, 0, 128), (124, 252, 0), (0, 0, 0), (0, 0, 0), (128, 0, 0),
(0, 0, 0), (0, 0, 0)
], dtype=np.uint8)
将颜色代码更改为 (124, 252, 0)。代码应该是草坪绿色。我也在RBG codes之类的网站上查过
我在这里缺少什么?任何解释都会有所帮助。
预测代码:
prob = model.predict(net_in)[0]
# Reshape to 2d here since the networks outputs a flat array per channel
prob_edge = np.sqrt(prob.shape[0]).astype(np.int)
prob = prob.reshape((prob_edge, prob_edge, 13))
# Upsample
if args.zoom > 1:
prob = interp_map(prob, args.zoom, image_size[1], image_size[0])
# Recover the most likely prediction (actual segment class)
prediction = np.argmax(prob, axis=2)
# Apply the color palette to the segmented image
color_image = np.array(pascal_palette)[prediction.ravel()].reshape(
prediction.shape + (3,))
print('Saving results to: ', args.output_path)
with open(args.output_path, 'wb') as out_file:
Image.fromarray(np.multiply(color_image,255)).save(out_file)
PS。在这两种情况下,我都使用相同的模型进行预测
【问题讨论】:
-
你是如何绘制这些图像的?你怎么能用这么少的像素制作完整的图像?
-
预测没有错,如果你的眼睛和监视器足够好,当你仔细观察时,你会看到与“正确”图像相同的区域,但使用稍微暗一点红色的。 --- 整个问题在于你如何绘制图像。
-
彩色像素是道路、汽车和电线杆 3 个对象。预测图像是高速公路。因此,大部分内容都被覆盖了。
-
@DanielMöller 我只是使用 Image.fromarray(np.multiply(color_image,255)).save(out_file) 转储图像
-
我想我应该看到一些黄绿色像素而不是红色的值 (124, 252,0)。它应该是红色(浅色或深色)。
标签: python tensorflow keras semantic-segmentation