Issue
I am following this tutorial series: https://www.youtube.com/watch?v=A4K6D_gx2Iw&list=PLQVvvaa0QuDfhTox0AjmQ6tvTgMBZBEXN&index=6
When I try to use the model outside the program by prediction it gives me the following error: error: OpenCV(4.1.0) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/resize.cpp:3718: error: (-215:Assertion failed) !ssize.empty() in function 'resize'
Below the code when loading the model:
import cv2
import tensorflow as tf
CATEGORIES = ["Dog", "Cat"]
import cv2
import tensorflow as tf
CATEGORIES = ["Dog", "Cat"]
def prepare(filepath):
IMG_SIZE = 50
img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
#return img_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
#
model = tf.keras.models.load_model('iyad')
#
predication = model.predict([prepare("Dog.jpg")])
print(predication)
Solution
It tells you the size of the original image is 0, corresponding to when you read from img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
. Check if you do have that picture Dog.jpg
loaded.
Answered By - stormzhou
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.