0

following the tutorial Kaggle Notebook for Unet, I am trying to create a function that could store the predicted mask in a folder. While trying below codes, I am getting error 'built-in function imread returned NULL without setting an error' enter image description here

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})

Shai
  • 111,146
  • 38
  • 238
  • 371

1 Answers1

0

You have several errors in your code:

  1. You are using imread for what exactly? cv2.imread ismeant to open an image file and read the image into a variable. 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? 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. 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.

Shai
  • 111,146
  • 38
  • 238
  • 371