• Register
0 votes

Problem :

I am beginner to opencv and keras on python. Currently I am trying to apply the Keras' image classifier to my existing project, but I am facing below error.

Error: (-215:assertion failed) !ssize.empty() in function 'cv::resize'

Earlier with the same code I was able to use OpenCV to read and train my images, but recently I switching to the new batch of images and so I am facing above error. So I guess there is something wrong with the file type

Below is from a batch which got the error:

traf.204.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 480x294, frames 1

Below is from a batch that was error free:

bear.290.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 224x224, frames 3

My file type are exactly the same so now I am confused. Can somebody help me in fixing my problem ?

8 4 2
2,300 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I have gone through your question and I think solution for your problem is pretty simple.

You just need to add a try/exception so your code can bypass problematic images:

    myimg=cv2.imread(mypath, cv2.IMREAD_GRAYSCALE)
   my img=cv2.resize(myimg, (img_rows,img_cols))

except Exception as e:

Hope it fixes your problem

5 2 1
4,980 points
0 votes

You might want to check bounds of detected object’s box.

I faced the same error and the cause was that bounds were either negative or more than image size. ( Simply put, a portion of detected object was lying outside image. )

0 points

Related questions

0 votes
1 answer 2K views
Problem : I am getting following pydot error importerror: failed to import pydot. you must install pydot and graphviz for `pydotprint` to work.
asked Nov 8, 2019 peterlaw 6.9k points
0 votes
1 answer 13 views
Explain me with a example in a clear way.
asked Oct 13, 2020 jagruthi 680 points
0 votes
0 answers 12 views
Have been trying to install the latest version of "opencv-contrib-python" package in the new Raspberry Pi (RPi 4). At the time of this writing, the latest version is When I do not specify the version with command pip install opencv-contrib- ... and installing wheel. I have tried these long before. I really appreciate it if anyone can comment who might have come across this problem.
asked Oct 27, 2020 psandprop 2.4k points
0 votes
1 answer 1K views
Problem: I have recently installed opencv with all the dependencies. After the successful installation I have tried to import matplotlib for the very simple example. I have started facing below error when I only tried to install matplotlib via the pip with pip install ... linux-gnu.so' Consider using the `--user` option or check the permissions. How can I install matplotlib without any error?
asked Aug 26, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 752 views
Problem : While trying to import the OpenCV, using import cv2 I facing the below error: /usr/local/lib/python2.7/dist-packages/cv2/__init__.py in <module>() 12 13 # make IDE's (PyCharm) autocompletion happy ----> 14 from .cv2 import * 15 16 # wildcard import ... - I am trying to play around with the Google's new Colaboratory tool. Please let me know if someone have solution for the above issue.
asked Dec 18, 2019 alecxe 7.5k points
0 votes
1 answer 374 views
Problem : I am trying to execute below commands. import numpy as np import cv But I am getting following error on my console: >>> runfile('/Users/isaiahnields/.spyder2/temp.py', wdir='/Users/isaiahnields/.spyder2') RuntimeError: module compiled against API version a but this ... it is not working. I had added cv.py to the python2.7 folder in Spyder-Py2 is there anything else I need to add?
asked Dec 4, 2019 alecxe 7.5k points
0 votes
1 answer 31 views
I'm trying to visualize my model in keras using from keras.utils import plot_model plot_model (model, to_file = 'model.png') First of all it showed an error ImportError: Failed to import pydot. You need to install pydot and graphviz for `pydotprint` to work. Therefore, I ... Then I closed the spyder and reopened it. When I run the code snippet it still shows the same error. What am I missing?
asked Aug 17, 2020 game 4.6k points
0 votes
1 answer 377 views
Problem: If I try to execute the command sess = tf.Session() in the Tensorflow 2.0 environment then I am facing below error message: Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'tensorflow' has no attribute ' ... install numpy==1.16.2 Command Execution as below: Execute the command: import tensorflow as tf Execute the command: sess = tf.Session()
asked Jul 21, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 52 views
Problem: I am very new to Keras. Now a days I am trying to use Keras (Sequential) but I am facing below error if I try to import it: File "kaggle_titanic_keras.py", line 3, in <module>     from keras.models import Sequential  File "/anaconda/lib/python2.7/site- ... 2.0.3 and recently 'upgraded' to Pandas 0.20.1 which I doubt is causing a problem but above error message says nothing about it.
asked Jul 21, 2020 Raphael Pacheco 4.9k points
1 vote
1 answer 470 views
Problem: I am having basic knowledge of python, tensorflow, keras. I have read most of the possible solutions for my error they are suggesting wrapping my problematic tensor in the Lambda layer and I have already tried this method but I ... line 1665, in build_map_of_graph     layer, node_index, tensor_index = tensor._keras_history AttributeError: 'Tensor' object has no attribute '_keras_history'
asked May 23, 2020 Martin K 6.6k points