JanMarcelKezmann / TensorFlow-Advanced-Segmentation-Models

A Python Library for High-Level Semantic Segmentation Models based on TensorFlow and Keras with pretrained backbones.
Other
151 stars 46 forks source link

error: OpenCV(4.5.5) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' #19

Closed sachinkmohan closed 2 years ago

sachinkmohan commented 2 years ago

I am currently running the jupyter notebook from the examples folder. The first one.

scores = model.evaluate(TestSet, steps=101)

print("Loss: {:.5}".format(scores[0]))
for metric, value in zip(metrics, scores[1:]):
    if metric != "accuracy":
        metric = metric.__name__
    print("mean {}: {:.5}".format(metric, value))

When I try to run the above block, I am getting the below error

error                                     Traceback (most recent call last)
<ipython-input-16-50d655bc0639> in <module>
----> 1 scores = model.evaluate(TestSet, steps=101)
      2 
      3 print("Loss: {:.5}".format(scores[0]))
      4 for metric, value in zip(metrics, scores[1:]):
      5     if metric != "accuracy":

~/.local/lib/python3.7/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

<ipython-input-7-23e4dfb47eb3> in DataGenerator(train_dir, label_dir, batch_size, height, width, classes, augmentation, wwo_aug, shuffle, seed)
     80             for i in range(batch_size):
     81                 image_path, label_path = next(image_label_path_generator)
---> 82                 image, label = process_image_label(image_path, label_path, classes=classes, augmentation=augmentation)
     83                 images[i], labels[i] = image, label
     84 

<ipython-input-7-23e4dfb47eb3> in process_image_label(images_paths, masks_paths, classes, augmentation, preprocessing)
     30     # read data
     31     image = cv2.imread(images_paths)
---> 32     image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
     33     mask = cv2.imread(masks_paths, 0)
     34 

error: OpenCV(4.5.5) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

Somehow the images are not getting generated I guess. Can you please help.

P.S - I replaced TestSet with ValidationSet and it works.

JanMarcelKezmann commented 2 years ago

Hi @sachinkmohan ,

this error probably occurred due to a false image path. That is the image_paths variable which is given to the cv2.imread(images_paths) function is probably not correct. There are 3 ways to solve this issue:

Further please check that the given image path contains images (in the same format as the training images) Probably and hopefully if you check all 3 options above your code should be good to go.

sachinkmohan commented 2 years ago

Thanks @JanMarcelKezmann for your reply! I checked the directories and gave the full path! I will check this again. I couldn't load the model. This is now an another problem. I will raise an another issue for this.

image