I was using PyCharm and imported ResNet50 for image recognition of a sample image. When I run the code , the following error occured.
I was learning using an online code which needed to be completed by learners. I configured PyCharm and installed required packages that were recommended. During learning image recognition using ResNet50 , while running the code I ended up with following error. Should I custom install ResNet50 on pycharm for this to work? The instructor said the IDE will auto download ResNet50 during execution of code. Attaching python code below.
import numpy as np
from keras.preprocessing import image
from keras.applications import resnet50
model = resnet50.ResNet50
img = image.load_img("bay.jpg", target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = resnet50.preprocess_input(x)
predictions = model.predict(x)
predicted_classes = resnet50.decode_predictions(predictions, top=9)
print("This is an image of:")
for imagenet_id, name, likelihood in predicted_classes[0]:
print(" - {}: {:2f} likelihood".format(name, likelihood))
This is the resultant error that I am getting during execution.
File "/home/warlock/Downloads/Ex_Files_Building_Deep_Learning_Apps/
Exercise Files/05/image_recognition.py", line 21, in <module>
predictions = model.predict(x)
AttributeError: 'function' object has no attribute 'predict'
You have this error because ResNet50
is a fonction so you need to implement it like a fonction :
model = resnet50.ResNet50()
In order to have a resnet50 model with all default parameters