简体   繁体   English

创建一个目录来存储输出掩码,用于图像分割任务

[英]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:您的代码中有几个错误:

  1. 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.这没有任何意义,因此您收到了错误消息。

  2. 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.不允许在文件名中使用'*' (和一些其他特殊字符)。

  3. 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.

相关问题 如何从 output 分类器创建分割掩码? - How to create segmentation mask from output classifier? 如何在图像分割任务中填充掩码内的分割区域? - How to fill segmented area within a mask in image segmentation task? (图像,掩码)对在语义分割任务中彼此不匹配 - (image, mask) pair do not match one another in a semantic segmentation task 如何为图像分割任务创建混淆矩阵? - How to create a confusion matrices for an image segmentation task? 如何从 Python 中的蒙版分割图像创建轮廓(厚度可控)? - How to create an outline (with controllable thickness) from a mask segmentation image in Python? Python中的平滑二进制分割掩码图像 - Smooth binary segmentation mask image in Python coco json的图像分割掩码到多边形 - Image segmentation mask to polygon for coco json 如何在python中显示地面实况图像分割掩码图像? - How to display a ground truth image segmentation mask image in python? 如何加载具有多个掩码的数据集(图像分割) - How to load dataset with multiple mask (Image-Segmentation) 在从实例分割掩码中提取的二值对象掩码图像中提取感兴趣对象的二值边界图像 - Extracting a binary boundary image for object of interest in a binary object mask image extracted from an instance segmentation mask
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM