Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors in step 2 Run_VAE_Models.py #2

Open
ynpan910 opened this issue Dec 20, 2024 · 1 comment
Open

errors in step 2 Run_VAE_Models.py #2

ynpan910 opened this issue Dec 20, 2024 · 1 comment

Comments

@ynpan910
Copy link

Hi, thank you for the great work. I was using the pancreas dataset you provided to run and learn the model.

However, in step 2, I came across this error:

---> 63 kl_loss = - 0.5 * K.sum(1 + z_log_var - K.square(z_mean) - K.exp(z_log_var), axis=-1)
65 return K.mean(reconstruction_loss + (K.get_value(beta) * kl_loss))

ValueError: Tried to convert 'x' to a tensor and failed. Error: A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces keras.layers and keras.operations). You are likely doing something like:

x = Input(...)
...
tf_fn(x)  # Invalid.

What you should do instead is wrap tf_fn in a layer:

class MyLayer(Layer):
    def call(self, x):
        return tf_fn(x)

x = MyLayer()(x)

My code is: %run -i ./MODEL_TRAININGS/Run_VAE_Models.py PANCREAS 5 0 100

TensorFlow version: 2.18.0
Keras version: 3.7.0

Wondering if you could provide some instructions on how to solve it. Thank you in advance!

@ynpan910
Copy link
Author

Nevermind! I got it solved by putting this

from tensorflow.python.framework.ops import disable_eager_execution
disable_eager_execution()

Thanks anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant