My deep learning topic is classifying images into 5 different categories. I used the ImageDataGenerator library to split my dataset into train and test. The negates the need for creating csv file which requires a lot of manual work. I've successfully developed a model architecture following the CNN method and evaluated the performance of my model on a test dataset, which gave me an accuracy of 83%. Now, when I try to predict my model to classify an image, this is the error it gives:
ValueError Traceback (most recent call last)
<ipython-input-147-51d5b018a219> in <module>()
11 images = np.vstack([X])
12 val = model.predict(images)
---> 13 if val == 0:
14 print("Clean")
15 elif val ==1:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Here is my code:
import os
test_dir = 'directory containing random images'
for i in os.listdir(test_dir ):
img = image.load_img(test_dir+ '/'+i, target_size=(200,200))
plt.imshow(img)
plt.show()
X = image.img_to_array(img)
X = np.expand_dims(X,axis = 0)
images = np.vstack([X])
val = model.predict(images)
if val == 0:
print("Clean")
elif val ==1:
print("Covered In Bird Droppings")
elif val ==2:
print ("Covered In Dust")
elif val ==3:
print("Covered In Grey Sand")
elif val ==4:
print("Covered In Sand")
I'm quite clueless as to how to fix this.