import numpy as np
import matplotlib.pyplot as plt
label = ds.class_indices
label = dict(zip(label.values(),label.keys()))
model = load_model('model_vgg16.h5')
def predict(image):
# 导入图片
image = load_img(image)
plt.imshow(image)
plt.show()
image = image.resize((224,224))
image = img_to_array(image)
image = image/255
# (1,224,224,3)
image = np.expand_dims(image,0)
return model.predict_classes(image)[0]
label
pre = predict('datasets/flower_photos/u=1910309642,1420354939&fm=200&gp=0.jpg')
print(label[pre])
AttributeError Traceback (most recent call last)
in ()
3 import matplotlib.pyplot as plt
4
5 label = ds.class_indices
6 label = dict(zip(label.values(),label.keys())
7 # 载入模型
AttributeError: 'PrefetchDataset' object has no attribute 'class_indices'
前面必须要有train_generator = train_datagen.flow_from_directory这个定义才能有class_indices字典
import numpy as np
import matplotlib.pyplot as plt
代码不全,DS从哪里来的?
label = ds.class_indices
上面说得很清楚,ds没有这个class_indices属性
就是你的这个调用的这个没有定义