第320行,in predictImage img = image.load_img(img_path)AttributeError:模块“keras.preprocessing.image”没有属性“load_img”
` def predictImage(img_path ='Normal2.jpg ',arrayImg=None,printData=True):作物= []
if arrayImg is None:
img = image.load_img(img_path)
crops = np.array(getCropImgs(img, needRotations=False), dtype=np.float16)
crops /= 255.0
Image.fromarray(np.array(crops[2], dtype=np.uint8), "RGB").show()
classes = ["Freundlich", "Anstehend", "Übergriffig", "Normal"]
compProbs = [0, 0, 0, 0]
for i in range(len(crops)):
if printData:
print("\n\nCrop " + str(i + 1) + " Vohersage:\n")
_, probs = predict(crops[i], modelSavePath, showImg=False)
for j in range(len(classes)):
if printData:
print(f"{classes[j]} : {round(probs[j], 4)}%")
compProbs[j] += probs[j]
if printData:
print("\n\nDurchschnitt aus allen\n")
for j in range(len(classes)):
if printData:
print(f"{classes[j]} : {round(compProbs[j] / len(crops), 4)}%")`
1条答案
按热度按时间jchrr9hc1#
要解决问题错误,您应该导入函数'tensorflow.keras. preprocing'而不是'keras.preprocing'