tensorflow 如何使用Keras加载图像?

x759pob2  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(152)

第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)}%")`
jchrr9hc

jchrr9hc1#

要解决问题错误,您应该导入函数'tensorflow.keras. preprocing'而不是'keras.preprocing'

相关问题