Week 4. Problem with test image in do_salience with untrained model

Hello, I have a problem with Generate saliency maps with untrained model.
I load the 5 images like the notebook of C3_W4_Lab2_CatsDogs-CAM.
And when I use my function do_salience with for example the first image ‘cat1.jpg’ I get this error:

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

I dont know where is the problem, because the image is not empty.
When I check outside the function I can see the image perfectaly using this code:

img= cv2.imread(‘cat1.jpg’)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb, cmap=‘gray’)
plt.title(‘Gato 1’)
plt.show()

Wish someone can help me.

Are you sure your cat1.jpg exist in the root directory?

Just cat1.jpg means the image exists in the root directory. For example, images/cat1.jpg mean that cat1.jpg image exists in images folder.

Finally I was able to solve the problem.
I restart the kernel and run all the notebook again.

1 Like