Assertion Error while training on last epoch


I have used a model from this repo. I want to train it again to improve performance.
This is my training command.

!python --snapshot efficientdet-d0.h5 --phi 0 --gpu 0 --weighted-bifpn --random-transform --compute-val-loss --freeze-bn --batch-size 4 --steps 100 coco datasets/coco

And the directory of folders:

enter image description here

The first 99 epochs work well.

99/100 [============================>.] - ETA: 0s - loss: 0.3978 - classification_loss: 0.2983 - regression_loss: 0.0995datasets/coco/images/train2017/i.rf.4eba631a9cf8fef57df45f64cf16f258.jpg
100/100 [==============================] - ETA: 0s - loss: 0.3959 - classification_loss: 0.2966 - regression_loss: 0.0993datasets/coco/images/val2017/000000061960.jpg

Afterwards, I see this error:

Traceback (most recent call last):
  File "", line 381, in <module>
  File "", line 376, in main
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/", line 324, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/", line 1482, in fit_generator
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/", line 66, in _method_wrapper
    return method(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/", line 875, in fit
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/", line 66, in _method_wrapper
    return method(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/", line 1060, in evaluate
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/", line 1112, in __init__
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/", line 908, in __init__
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/", line 772, in __init__
    peek, x = self._peek_and_restore(x)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/", line 912, in _peek_and_restore
    return x[0], x
  File "/content/drive/My Drive/EfficientDet-master/generators/", line 424, in __getitem__
    inputs, targets = self.compute_inputs_targets(group)
  File "/content/drive/My Drive/EfficientDet-master/generators/", line 373, in compute_inputs_targets
    image_group = self.load_image_group(group)
  File "/content/drive/My Drive/EfficientDet-master/generators/", line 225, in load_image_group
    return [self.load_image(image_index) for image_index in group]
  File "/content/drive/My Drive/EfficientDet-master/generators/", line 225, in <listcomp>
    return [self.load_image(image_index) for image_index in group]
  File "/content/drive/My Drive/EfficientDet-master/generators/", line 132, in load_image
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'


The error means that the image (from a file path) that is currently trying to be processed could no be found. If you look at the training output, you’ll see that all the image paths come from datasets/coco/images/train2017/, but the very last line says is looking for a file in datasets/coco/images/val2017.

The script is done training and is looking for validatioon/testing data, which I suspect it can’t find. Check that the val2017 directory exists, and that there are images in the directory that can be loaded with cv.imread().

Answered By – Jay Mody

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.