我有72张图像要用我的模型进行分类,现在我正尝试用我的分类进行预测,但是遇到了关于 索引32超出了尺寸为32的轴0的范围。
test_datagen = image.ImageDataGenerator(rescale=1./255)
img_batch = test_datagen.flow_from_directory(images_dir, target_size=
test_datagen = image.ImageDataGenerator(rescale=1./255)
img_batch = test_datagen.flow_from_directory(images_dir, target_size=(img_width, img_height), shuffle=False)
predictions = model.predict_generator(img_batch, steps=1)
filenames = img_batch.filenames
predicted_class_indices = np.argmax(predictions,axis=1)
classnames = []
print(len(classnames))
for i in range(72):
classnames.append(class_names[predicted_class_indices.item(i)])
results = pd.DataFrame({"Filename":filenames,
"Prediction":classnames})
results.head(72)
我收到这样的错误:
Found 72 images belonging to 3 classes.
0
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-37-1d228169f5c1> in <module>
9 print(len(classnames))
10 for i in range(72):
---> 11 classnames.append(class_names[predicted_class_indices.item(i)])
12 results = pd.DataFrame({"Filename":filenames,
13 "Prediction":classnames})
IndexError: index 32 is out of bounds for axis 0 with size 32