[英]Why am I getting a 'str' objet is not callable error?
my code:我的代码:
import cv2 import tensorflow as tf
CATEGORIES=['Dog','Cat']
def prepare(filepath):
IMG_SIZE=50
img_array = cv2.imread(filepath,cv2.IMGREAD_GRAYSCALE)
new_array = cv2.resize(img_array,(IMG_SIZE,IMG_SIZE))
return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
model = tf.keras.models.load_model("64x3-CNN.model")
prediction = model.predict([prepare('dog.jpg')]) print(prediction)
my error:我的错误:
TypeError Traceback (most recent call last)
<ipython-input-8-182101876678> in <module>
10 return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
11
---> 12 model = tf.keras.models.load_model("64x3-CNN.model")
13
14 prediction = model.predict([prepare('dog.jpg')])
TypeError: 'str' object is not callable
I faced the same error while loading a saved pb
model in TensorFlow. Turns out that I didn't save the model using Keras, so had to load the model using tf.saved_model.load('model_directory')
instead of using Keras.我在 TensorFlow 中加载保存的pb
model 时遇到了同样的错误。原来我没有使用 Keras 保存 model,所以不得不使用tf.saved_model.load('model_directory')
而不是 4 加载 model4
May be these are the factors to produce this error....可能是这些是产生此错误的因素....
In your case, Your extension of the model is wrong since there is no extenison like model" Check Your extension of the model. It may "h5" https://www.tensorflow.org/tutorials/keras/save_and_load#hdf5_format在您的情况下,您对 model 的扩展是错误的,因为没有类似模型的扩展”检查您对 model 的扩展。它可能是“h5” https://www.tensorflow.org/tutorials/keras/save_and_load#hdf5_format
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.