python - 图像预测不能输出:轮廓不是 numpy 数组,也不是标量
问题描述
我一直想知道为什么我在 test_id2-5 上的行可以显示我的图像预测,但在 test_id1 上却不能显示我的图像预测。但是错误出现了,我不知道为什么,因为在其他训练之前它可以显示,但现在它不能显示。因此这是我的代码:
def fungsi_vis(i,test_id1):
test_dataset = DataGen(test_id1, train_path, image_size=image_size, batch_size=1)
plt.figure(figsize=(16, 5))
image, gt_mask = test_dataset[i]
image = np.expand_dims(image[0], axis=0)
pr_mask = model.predict(image).round()
scores = model.evaluate(image,gt_mask)
b,g,r = cv2.split(image[0])
rgb_img = cv2.merge([r,g,b])
# imagess = np.expand_dims(rgb_img, axis=0)
contours1, hierarchy1 = cv2.findContours(np.array(gt_mask[0], dtype=np.uint8).squeeze(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
largest_contour1 = []
largest_area = 0
for contour in contours1:
area = cv2.contourArea(contour)
if area > largest_area:
largest_area = area
largest_contour1 = contour
cv2.drawContours(rgb_img, [largest_contour1], -2, (1, 1, 0), 1)
contours2, hierarchy2 = cv2.findContours(np.array(pr_mask, dtype=np.uint8).squeeze(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
largest_contour2 = []
largest_area = 0
for contour in contours2:
area = cv2.contourArea(contour)
if area > largest_area:
largest_area = area
largest_contour2 = contour
cv2.drawContours(rgb_img, [largest_contour2], -2, (0, 1, 1), 1)
ious = str(scores[1]*100)[:str(scores[1]*100).find(".")+3] + '%'
titles = test_id1[i]+" ("+ious+")"
plt.title(titles)
plt.imshow(denormalize(rgb_img.squeeze()))
我的图像是灰度的,我为轮廓预测加载了 rgb_img 函数,但是当我尝试显示 test_id1 时,它无法显示我的预测。但是当我删除它时cv2.drawContours(rgb_img, [largest_contour2], -2, (0, 1, 1), 1)
它会出现,有人知道如何解决这个问题吗?
解决方案
推荐阅读
- arrays - 更新一个猫鼬数组
- javascript - 在没有 id 的情况下向 postgresql 创建新用户时,sails 返回错误
- c++ - 无法摆脱控制台窗口中的退出代码
- php - 读取文件不会使用 PHP 重新启动
- activemq-artemis - 在 Windows 服务器上运行 ActiveMQ Artemis
- java - 在另一台计算机上执行 Runnable jar 时,JavaMail MimeMessage 不会发送
- php - PhpSpreadsheet 保存并保持样式
- sql - 使用 join 语句连接子查询
- react-admin - react-admin selectArrayInput 没有选择
- android - 如何更改 SeekBar 中每个刻度标记的颜色