TypeError: Cannot interpret '<KerasTensor: shape=(None, 3) dtype=float32 (created by layer 'input_1')>' as a data type

Viewed 306

Very simple question. I am using tensorflow probability package to use a bijector to form a trainable_distribution from a simple distribution (let's say gaussian)

Everything works properly in jupyter notebook but as I bring it to terminal (where I am running my code file) it gives me this error:

TypeError: Cannot interpret '<KerasTensor: shape=(None, 3) dtype=float32 (created by layer 'input_1')>' as a data type

Here is my code for this part (X_data is (m,3) where m is the number of samples and trainable_distribution is already built using tensorflow_probability.distributions.TransformedDistribution(base_dist, bijector):

def train_dist_routine(X_data, trainable_distribution, n_epochs=200, batch_size=None):

    x_ = tensorflow.keras.layers.Input(shape=(3,), dtype=tf.float32)
    print(x_)
    log_prob_ = trainable_distribution.log_prob(x_)
    model = tensorflow.keras.models.Model(x_, log_prob_)

    model.compile(optimizer=tf.optimizers.Adam(),
                  loss=lambda _, log_prob: -log_prob)

    ns = X_data.shape[0]
    if batch_size is None:
        batch_size = ns



    history = model.fit(x=X_data,
                        y=np.zeros((ns, 0), dtype=np.float32),
                        batch_size=batch_size,
                        epochs=n_epochs,
                        validation_split=0.2,
                        shuffle=True,
                        verbose=False)
    return history
0 Answers
Related