C4W3_Assignment Error when calling the VAE model

After putting the Encoder, the sampling class and the decoder together in the VAE Model I get an EXCEPTION when I try to call:
encoder, decoder, vae = get_models(input_shape=(64,64,3,), latent_dim=LATENT_DIM)

It is the following StackTrace:


ValueError Traceback (most recent call last)
in <cell line: 1>()
----> 1 encoder, decoder, vae = get_models(input_shape=(64,64,3,), latent_dim=LATENT_DIM)

4 frames
/usr/local/lib/python3.10/dist-packages/keras/engine/base_layer.py in _split_out_first_arg(self, args, kwargs)
3092 inputs = kwargs.pop(self._call_fn_args[0])
3093 else:
→ 3094 raise ValueError(
3095 ‘The first argument to Layer.call must always be passed.’)
3096 return inputs, args, kwargs

ValueError: The first argument to Layer.call must always be passed.

I tried to find a solution on StackOverflow, but couldn’t solve the problem :frowning:

Hello Peter,

Based on your error, you need to go back and check your input codes lines related to encoder and decoder grader cell where you selected a value which is not passing the coding layers. You are recalling your inputs codes with an incorrect value in one of these cells.

start looking from this grader cell

class Sampling(tf.keras.layers.Layer):
def call(self, inputs):

if not able to find, share your notebook via DM.

Regards
DP

Hello Peter,

You have indentation error in the following grader cells

  1. class Sampling(tf.keras.layers.Layer):
    def call(self, inputs):

2.def encoder_layers(inputs, latent_dim):
“”"Defines the encoder’s layers.

  1. def vae_model(encoder, decoder, input_shape):
    “”"Defines the VAE model

  2. def get_models(input_shape, latent_dim):
    “”“Returns the encoder, decoder, and vae models”“”

START CODE HERE

  1. Training loop. Display generated images each epoch

  2. Use this hint

  • compute the reconstruction loss (hint: use the mse_loss defined above instead of bce_loss in the ungraded lab, then multiply by the flattened dimensions of the image (i.e. 64 x 64 x 3) in your training loop grader cell

in the same grader cell, you do not need to do summation of loss.

Extra hint : P.S. note in any case, when you don’t get desired output, you can always check with iteration cycles while you train your model.

Just let me know once you clear the test.

Happy Learning!!!

Regards
DP

I just copied all my code to npp and inspected it there and removed tailing blanks. Then I reopend the lab and copied my code into the functions and then it worked.
Somehow strange, but okay happens :wink:

That corrected your indentation error!!! which was major part of correction :slight_smile: