pythontensorflow2.0tensortensorflow-probability

tensorflow probabitily wrong output type


UP DATE and ANSWER: My error was using tf.dataset to feed my model like y_hat=model(x_tst) using numpy array data give me the good type of output and work as supposed

I try to run tensorflow probality, but get stuck on output type problem. Followinfg this exemple at cell #3, with

y_hat=model(x_tst)

the y_hat type is: tensorflow_probability.python.layers.internal.distribution_tensor_coercible._TensorCoercible

my input are dataset type build like that (2 heads model)

input_1 = tf.data.Dataset.from_tensor_slices(X)
input_2 = tf.data.Dataset.from_tensor_slices(Xphysio)
output = tf.data.Dataset.from_tensor_slices(y)
combined_dataset = tf.data.Dataset.zip(((input_1, input_2), output))
input_dataset = combined_dataset.batch(32)

but if I use directly (like in exemple)

y_hat=model(x_tst)

instead of (who seem work well and produce results):

y_hat=model.predict(x_tst) 

I get this error

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

If I use model.predict() the next step using tf probability don't work


Solution

  • Finaly find it, to use y_hat=model(x_tst) instead of model.predict and get the good type, I need to feed the model with numpy array in lieu of tf.dataset.