简体   繁体   English

为什么我会收到“str”objet is not callable 错误?

[英]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....可能是这些是产生此错误的因素....

  1. You saved the model different name.您保存了 model 不同的名称。
  2. You saved the model in different directory with correct name or incorrect name您将 model 保存在名称正确或名称不正确的不同目录中
  3. your extension is wrong你的分机是错误的

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.

相关问题 为什么即使我没有使用任何“str”命名变量,我也会收到(“str”函数不可调用)错误? - Why am I getting ('str' function is not callable) error even though I haven't used any 'str' named variable? 我在这里收到错误错误是('str' object 不可调用) - I am getting errors here error is ('str' object is not callable) 当我运行此命令时,我收到TypeError:&#39;str&#39;对象不可调用..为什么呢? - When I run this , i am getting TypeError: 'str' object is not callable.. why is that? 为什么我在运行文件时会收到此可调用错误? - Why am I getting this callable error when I run the file? 为什么我在Python中得到“&#39;tuple&#39;对象不是可调用错误” - Why am I getting "'tuple' object is not callable error in python TypeError: 'Tk' object is not callable 为什么我会收到此错误消息 - TypeError: 'Tk' object is not callable Why am i Getting this error message 为什么我收到 TypeError: 'str' object is not callable when using eval() on string that is python code - Why am I getting a TypeError: 'str' object is not callable when using eval() on string that is python code 为什么我在 python 上得到一个列表 object is not callable 错误? - Why am I getting a list object is not callable error on python? 为什么我收到此 folium 模块不可调用错误? - Why I am getting this folium module is not callable error? 为什么我得到的对象不可调用? - Why am I getting object is not callable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM