TypeError:无法将值dtype转换为TensorFlow DType

时间:2020-05-28 21:06:01

标签: pandas numpy tensorflow tensorflow2.0 tf.keras

我对tensorflow很陌生。我正在从.h5文件加载模型,并尝试使用该模型进行预测。

import tensorflow as tf
import pandas as pd
import numpy as np

file_path = '/path/to/file'
model = tf.keras.models.load_model(file_path)

query = np.array(('cat1', 69.0, 'cat2', 9.2, 'cat3', 0, 0, 1, 0, 3, 0, 43, 1200, 4380), dtype='U32, float32, U32, float32, U32, uint16, uint16, uint16, uint16, uint16, uint16, uint16, float32, float32')
result = model.predict(query)

我试图将查询格式设置为pandas.Series,但无法使其与混合数据类型一起使用。我使用np.array明确指定了dtype,但它抛出了错误:“ TypeError:无法将值dtype转换为TensorFlow DType。”

cat1,cat2和cat3是类别,并已在模型训练期间进行了标签编码。

在测试期间,我发现如果我在查询np.array中传递uint16值而不是U32,则模型将返回预测。但是我不知道如何获取类别的uint16值。或如何格式化数组以创建用于预测的张量。有什么想法吗?

0 个答案:

没有答案