It means that somewhere a function which should return a image just returned None and therefore has no shape attribute. Try "print img" to check if your image is None or an actual numpy object.
Answer from asc11 on Stack OverflowIt means that somewhere a function which should return a image just returned None and therefore has no shape attribute. Try "print img" to check if your image is None or an actual numpy object.
I faced the same problem today, please check for the path of the image as mentioned by cybseccrypt. After imread, try printing the image and see. If you get a value, it means the file is open.
Code:
Copyimg_src = cv2.imread('/home/deepak/python-workout/box2.jpg',0)
print img_src
Hope this helps!
I used the ControlNet extension & the Realistic Vision checkpoint, and it keeps giving me this error, "AttributeError: 'NoneType' object has no attribute 'shape'" whenever I try to generate a image. Even not using them, I still get this error.
What is the issue and how can I fix it?
Edit: it turns out when trying to use ControlNet, I was matching one of the preprocessors with the wrong models.
NoneType' object has no attribute 'shape' problem
machine learning - 'NoneType' object has no attribute 'get_shape' in standard AdamOptimizer Initialization - Data Science Stack Exchange
python - AttributeError: 'NoneType' object has no attribute 'shape' - Stack Overflow
Error: AttributeError: 'NoneType' object has no attribute 'shape' when prompt tuning with Chatglm2
Videos
Answering, because the community brought it back. Adding my two objects (cents).
The only reason you see that error is because you are trying to get information or perform operations on an object that doesn't exist in the first place. To check, try printing the object. Like, adding -
print img # such as this case
print contours # if you are working with contours and cant draw one
print frame # if you are working with videos and it doesn't show
gives you a None. That means you haven't read it properly. Either the image name you gave does not exist or the path to it is wrong. If you find such an error here's the quick things to do-
- Check the path or bring your image to the working directory
- Check the name you gave is right (including the extension- .jpg, .png etc)
- Put the entire code in a if statement with the object and the code to proceed if true
- Will add more if suggested in the comments.
First of all
python img.py AB.jpg
will not work as you expect (load AB.jpg from the current directory). The file to load is hardcoded in line 6 of the provided example: to work as intended, it should be something like this:
import sys
img = cv2.imread(sys.argv[1])
The error is returned because AB.jpg does not exist in the directory img.py is being run from (the current working directory), and there is no verification for a missing file before trying to read it.