Untitled
unknown
plain_text
a year ago
1.6 kB
12
Indexable
# Train the VAE model
epochs = 50 # Adjust as needed
batch_size = 32
vae.fit(X_train, X_train, epochs=epochs, batch_size=batch_size, validation_data=(X_test, X_test))
Epoch 1/50
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-8-51f78a6f04ec> in <cell line: 5>()
3 batch_size = 32
4
----> 5 vae.fit(X_train, X_train, epochs=epochs, batch_size=batch_size, validation_data=(X_test, X_test))
6
7
1 frames
<ipython-input-7-389aeac916a2> in vae_loss(inputs, outputs)
2 def vae_loss(inputs, outputs):
3 xent_loss = K.sum(K.categorical_crossentropy(inputs, outputs), axis=-1)
----> 4 kl_loss = - 0.5 * K.sum(1 + z_log_var - K.square(z_mean) - K.exp(z_log_var), axis=-1)
5 return K.mean(xent_loss + kl_loss)
6
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)
```Editor is loading...
Leave a Comment