【发布时间】:2022-01-26 03:02:27
【问题描述】:
我正在尝试通过加载我的模型的保存版本来预测值。 这是它的代码-
def classifier(img, weights_file):
# Load the model
model = tf.lite.TFLiteConverter.from_keras_model(weights_file)
# Create the array of the right shape to feed into the keras model
data = np.ndarray(shape=(1, 200, 200, 3), dtype=np.float32)
image = img
# image sizing
size = (200, 200)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
# turn the image into a numpy array
image_array = np.asarray(image)
# Normalize the image
normalized_image_array = image_array.astype(np.float32) / 255
# Load the image into the array
data[0] = normalized_image_array
# run the inference
prediction_percentage = model.predict(data)
prediction = prediction_percentage.round()
return prediction, prediction_percentage
我的模型抛出错误“'TFLiteKerasModelConverterV2'对象没有属性'predict'” 谁能告诉我我可以在这里改变什么?
【问题讨论】:
标签: python machine-learning keras data-science tensorflow-lite