Reputation: 29
Hello i am currently getting this error, when i try to test the CNN model.
import cv2
import tensorflow as tf
CATEGORIES = ["cats","dogs"]
def prepare(file):
IMG_SIZE = 50
img_array = cv2.imread(file, cv2.IMREAD_GRAYSCALE)
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("CNN.model")
image = "datasets/test_set/dogs/dog.4001.jpg"
prediction = model.predict([image])
prediction = list(prediction[0])
print(CATEGORIES[prediction.index(max(prediction))])
When I run the code I get the error:
File "C:\Anaconda\lib\site-packages\tensorflow\python\keras\engine\training_utils.py", line 265, in standardize_single_array
if (x.shape is not None and len(x.shape) == 1 and
AttributeError: 'str' object has no attribute 'shape'
Anyone who can tell me my mistake?
Upvotes: 0
Views: 2708
Reputation: 13022
You forgot to call prepare
... So, your image
variable should look like this:
image = prepare("datasets/test_set/dogs/dog.4001.jpg")
Upvotes: 1