1

I am trying to make data augmentation for my semantic segmentation task but i got this error , could any one help me. this error appear in the line of augmented = aug(image=x, mask=y) I am trying to make data augmentation for my semantic segmentation task but i got this error , could any one help me. this error appear in the line of augmented = aug(image=x, mask=y)

  imagesfile = sorted(glob.glob("/content/drive/MyDrive/Colab 
  Notebooks/BraTS2020_TrainingData/input_data_3channels/images/*"))

  masksfile = sorted(glob.glob("/content/drive/MyDrive/Colab 
  Notebooks/BraTS2020_TrainingData/input_data_3channels/masks/*"))



  augment = True
  H = 128
  W = 128

  for x, y in tqdm(zip(imagesfile, masksfile), total=len(imagesfile)):
      name = x.split("/")[-1].split(".")
      """ Extracting the name and extension of the image and the mask. """
      image_name = name[0]
      image_extn = name[1]

      name = y.split("/")[-1].split(".")
      mask_name = name[0]
      mask_extn = name[1]

      """ Reading image and mask. """
      x = cv2.imread(x)
      y = cv2.imread(y)

     if augment:

       aug = CenterCrop(H, W, p=1.0)
       augmented = aug(image=x, mask=y)
       x1 = augmented["image"]
       y1 = augmented["mask"]

       aug = RandomRotate90(p=1.0)
       augmented = aug(image=x, mask=y)
       x2 = augmented['image']
       y2 = augmented['mask']

      aug = GridDistortion(p=1.0)
      augmented = aug(image=x, mask=y)
      x3 = augmented['image']
      y3 = augmented['mask']

      aug = HorizontalFlip(p=1.0)
      augmented = aug(image=x, mask=y)
      x4 = augmented['image']
      y4 = augmented['mask']

      aug = VerticalFlip(p=1.0)
      augmented = aug(image=x, mask=y)
      x5 = augmented['image']
      y5 = augmented['mask']

      save_images = [x, x1, x2, x3, x4, x5]
      save_masks =  [y, y1, y2, y3, y4, y5]

    else:

        save_images = [x]
        save_masks = [y]
  • you MUST check the result from `cv2.imread()`, it silently returns empty arrays on failure – berak May 26 '22 at 05:01
  • i also checked it and didnt read the image but i dont know why ??? however print(f"Original Images: {len(imagesfile)} - Original Masks: {len(masksfile)}") gives me 344 which are the size of images in folder – Ahmed mohamed May 26 '22 at 05:21
  • Ensure that the file path is loaded and corrected before passing it to cv2.imread. – Innat May 26 '22 at 05:23
  • there might be non-image files in your folder list (like apple DS_shit, or thumbnails.db) . maybe you need to filter for `*.png` in the glob() – berak May 26 '22 at 05:25
  • i am trying npy array of images so i do it *npy , in glob.glob it already read 344 file – Ahmed mohamed May 26 '22 at 05:39
  • is cv2 can not read npy images – Ahmed mohamed May 26 '22 at 05:49
  • @Ahmedmohamed please update the question with an [edit] when responding to requests for clarification. Please make sure any error messages or in the _body_ of the question, not just the title. –  May 26 '22 at 20:03

0 Answers0