TensorFlow 概率推理错误输入类型

问题描述 投票:0回答:1

我使用tensorflow_probability和分布训练模型。

为了训练它,我将数据格式化为这样(2 个头模型,因此 2 个输入集):

input_1 = tf.data.Dataset.from_tensor_slices(Xdata)
input_2 = tf.data.Dataset.from_tensor_slices(Xphysio)
output = tf.data.Dataset.from_tensor_slices(yobs)
combined_dataset = tf.data.Dataset.zip(((input_1, input_2), output))
input_dataset = combined_dataset.batch(30)

训练效果很好...但是当我尝试像 15 号单元格中的示例那样进行推理时,他们这样称呼模型:

yhats = model(combined_dataset)

我收到错误了

TypeError: Inputs to a layer should be tensors. Got: <ZipDataset element_spec=((TensorSpec(shape=(120, 9), dtype=tf.float32, name=None), TensorSpec(shape=(24,), dtype=tf.float32, name=None)), TensorSpec(shape=(), dtype=tf.float32, name=None))>

我尝试:

yhats = model([input_1, input_2])

并得到同样的错误:

TypeError: Inputs to a layer should be tensors. Got: <TensorSliceDataset element_spec=TensorSpec(shape=(120, 9), dtype=tf.float32, name=None)>

使用

yhats = model.predict([Xdata, Xphysio])
运行良好,但似乎没有返回 tfd.Distribution 的有效格式:

assert isinstance(yhat, tfd.Distribution):

Traceback (most recent call last):
  File "E:\Windows programs\PyCharm Community Edition 2021.3.1\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
AssertionError
python tensorflow machine-learning tensorflow-datasets tensorflow-probability
1个回答
0
投票

最终要求使用tensorflow 2.13,我的是2.10。 我像往常一样使用 pip 代替 conda 进行升级,一切正常。

© www.soinside.com 2019 - 2024. All rights reserved.