[英]Create a directory to store output mask, for image segmentation task
following the tutorial Kaggle Notebook for Unet , I am trying to create a function that could store the predicted mask in a folder.遵循Unet 的 Kaggle Notebook教程,我正在尝试创建一个可以将预测的掩码存储在文件夹中的函数。 While trying below codes, I am getting error 'built-in function imread returned NULL without setting an error'
在尝试以下代码时,我收到错误“内置函数 imread 返回 NULL 而未设置错误”
Please suggest a modification or redirect for potential solutions.请为潜在的解决方案建议修改或重定向。
import cv2
import os
image_dir = "/content/sample_data/Output"
def pred_images(sample_image, sample_mask, path):
pred_mask = model.predict(sample_image[tf.newaxis, ...])
print(pred_mask.shape)
pred_mask = pred_mask.reshape(img_size[0],img_size[1],1)
img= cv2.imread(pred_mask, 1)
cv2.imwrite(os.path.join(path, '*.png'), img)
for i in range(len(train_dataset)):
for image, mask in TRAIN.take(i):
sample_image, sample_mask= image, mask
pred_images(sample_image, sample_mask, {image_dir})
You have several errors in your code:您的代码中有几个错误:
You are using imread
for what exactly?您使用
imread
到底是为了什么? cv2.imread
ismeant to open an image file and read the image into a variable. cv2.imread
用于打开一个图像文件并将图像读入一个变量。 That is, to "convert" a string with filename into a matrix with the actual pixel values.也就是说,将带有文件名的字符串“转换”为带有实际像素值的矩阵。
However, you are applying imread
to a matrix mask_pred
-- what are you doing there?但是,您正在将
imread
应用于矩阵mask_pred
- 您在那里做什么? This makes no sense, thus the error message you got.这没有任何意义,因此您收到了错误消息。
You are trying to write your image, img
to a file name '/content/sample_data/Output/*.png'
-- this is NOT a valid file name.您正在尝试将图像
img
写入文件名'/content/sample_data/Output/*.png'
- 这不是有效的文件名。 You are not allowed to use '*'
(and a few other special characters ) in file names.不允许在文件名中使用
'*'
(和一些其他特殊字符)。
Moreover, your path
argument is set to {image_dir}
-- that is, you are making a set with one element ( image_dir
) and then try and use this set as the path
for the file.此外,您的
path
参数设置为{image_dir}
- 也就是说,您正在使用一个元素 ( image_dir
) 创建一个集合,然后尝试将此集合用作文件的path
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.