Tag Archives: dependent

[Solved] AttributeError: module ‘keras.preprocessing.image‘ has no attribute ‘load_img‘

Original code:

from keras.preprocessing import image
img         =   image.load_img(img_path,target_size=(224,224))
x           =   image.img_to_array(img)

report errors:

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

Reason: The keras version has been updated.

Solution:

from keras.utils import image_utils
img         =   image_utils.load_img(img_path,target_size=(224,224))
x           =   image_utils.img_to_array(img)

Tensorflow Error: Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR

1. Confirm whether tensorflow corresponds to CUDA and cudnn. Check here. 2. Modify settings

os.environ['CUDA_VISIBLE_DEVICES']='0,1'
# tf 1.13
config = tf.ConfigProto()
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)
sess.run(tf.global_variables_initializer())

# tf 2.0
# gpu = tf.config.experimental.list_physical_devices('GPU')
# tf.config.experimental.set_memory_growth(gpu[0], True)
# gpu = tf.config.experimental.list_physical_devices('GPU')
# tf.config.experimental.set_memory_growth(gpu[1], True)