Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOW TO FIX IT? AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'

    import numpy as np
    from keras.preprocessing import image
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    
    
    %matplotlib inline
    
    
    
    path = './test/paper2.png'
    
    img = image.load_img(path, target_size=(150,150))
    imgplot = plt.imshow(img)
    x = image.img_to_array(img)
    img_test = np.expand_dims(x, axis=0)
    
    classes = model.predict(img_test, batch_size=10)
    
    print(classes)
    paper, rock, scissors = classes[0]
    
    if paper==1.:
        print('paper')
    elif rock==1.:
        print('rock')
    else:
        print('scissors')

output :


AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'

when I try to run. What does the error mean and how can I fix it? help guys :) I'm trying to learn I don't know anymore which one is wrong

like image 862
Muhammad Syahdewa Avatar asked Sep 09 '25 17:09

Muhammad Syahdewa


1 Answers

Replace:

from keras.preprocessing import image

for:

import keras.utils as image
like image 144
F.Souza Avatar answered Sep 12 '25 13:09

F.Souza