179 - Variational autoencoders using keras on MNIST data

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • Code generated in the video can be downloaded from here:
    github.com/bns...

Комментарии • 150

  • @sanketgadge9060
    @sanketgadge9060 3 года назад +15

    This is pure gold! I was working with the worldmodel and wanted to gain some knowledge of CNN-VAE, and I stumbled upon this video.......you have explained really, really well. Thanks a lot.

  • @mizupof
    @mizupof 3 года назад +9

    "Let me put it back to 42 or I cannot sleep". Best line ever haha

  • @sreejithpro
    @sreejithpro 3 года назад +9

    I am getting this error while executing vae.fit function
    TypeError: Tensors are unhashable. (KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='tf.math.reduce_sum/Sum:0', description="created by layer 'tf.math.reduce_sum'"))Instead, use tensor.ref() as the key.
    I am using Tensorflow and Keras 2.4.0 can you please help me. I was trying to do this on CelbA dataset you mentioned at the end.

    • @hygorsantiago8018
      @hygorsantiago8018 11 месяцев назад

      Someone solved this problem? I'm in the same situation.

    • @kroax9720
      @kroax9720 6 месяцев назад

      Stuck at the same error , please help

  • @parthnaik816
    @parthnaik816 3 года назад +7

    One of the best narrators I found for this kind of content. Thanks! Appreciate it and Hope to see more and more videos.

  • @samarafroz9852
    @samarafroz9852 2 года назад +1

    This is the best tutorial on whole RUclips for VAE

  • @jaikishank
    @jaikishank 3 года назад +1

    Thanks for the great explanation of VAE. Got more clarity on viewing your video after several attempts to understand VAE.

  • @swethanandyala
    @swethanandyala 5 месяцев назад +1

    This explanation is like a Gem!!

  • @chid3835
    @chid3835 3 года назад +6

    For anyone who is trying to do this and encounters an error saying "TypeError: Tensors are unhashable." during fitting, it is due to version incompatibility. Replacing "import keras" to "from tensorflow import keras" for TF >2.0 will solve the issue. As Keras is default API for TF > 2.0

    • @dwijokosuroso8970
      @dwijokosuroso8970 2 года назад

      I did change to "from tensorflow import keras" but the results of epoch is weird.

    • @talhahafeez5309
      @talhahafeez5309 2 года назад

      @@dwijokosuroso8970 Did you find any solution to this ? TIA

  • @user-or7ji5hv8y
    @user-or7ji5hv8y 3 года назад

    I cannot believe that RUclips algo took this long to recommend this channel.

  • @nickstaresinic9933
    @nickstaresinic9933 3 года назад

    Very informative content wrapped in a particularly personable style. A real stand-out among available videos on the subject matter. Thanks.

  • @HI_YT66
    @HI_YT66 Год назад

    Pure Gold!
    Please keep us updated about recent developments in AI.
    Thanks!

  • @meeribad6784
    @meeribad6784 3 года назад

    Man i can't appreciate it enough, I was trying to learn VAE implementation this was the best tutorial I watched thanks sreeni keep it up!!

  • @micaelmarquez6225
    @micaelmarquez6225 Год назад +2

    good video! Try not apologizing too much. You don't need to apologize for anything you do.

  • @samhuguet861
    @samhuguet861 2 года назад +1

    Hi @DigitalSreeni on line 152: If you want to return the output of the decoder, shouldn't you return z_decoded instead of x? Thanks for the video

  • @harshadlokhande_veditekk
    @harshadlokhande_veditekk 2 года назад

    One of the best tutorial on youtube to actually code VAE...👏👏

    • @DigitalSreeni
      @DigitalSreeni  2 года назад +1

      Glad you think so!

    • @harshadlokhande_veditekk
      @harshadlokhande_veditekk 2 года назад

      @@DigitalSreeni What are different performance metrics / benchmarks to know which method (error correction)
      will be good for VAE?

  • @kim66003
    @kim66003 3 года назад +1

    This tutorial is a lifesaver!!!!

  • @Kerem-Ertem
    @Kerem-Ertem 8 месяцев назад

    This is kinda magic! And what exactly my homework is, appreciated!

  • @morningmoon6100
    @morningmoon6100 3 года назад +1

    You are doing a great work !!!!! Thank you and keep teaching

  • @rs9130
    @rs9130 2 года назад

    Thank you for your time in explaining all the stuffs for newbies.

  • @comrade531
    @comrade531 3 года назад

    Thanks a lot for making series of videos related to auto encoders. I was looking for this content everywhere n found yours easy to digest 😊👌

  • @s4life91
    @s4life91 2 года назад

    thanks for this great video. I think y is actually the output loss of the model not reconstructed image. the final output of the model is the overall loss after the custom loss layer. and I think the reason in compiling the model we set ' loss = none ' is this.

  • @ugursopaoglu
    @ugursopaoglu 3 года назад +5

    It was a great explanation of VAE. Thanks for your sharing. I cannot understand that how can we calculate mean and standard deviation with a linear layer?

    • @josephpareti9156
      @josephpareti9156 Год назад

      same question as mine docs.google.com/document/d/16D_vOcHAv4e7b430R5ojfLQObnjTCwt998rhzQ6sne4/edit

  • @MOTIVAO
    @MOTIVAO Год назад

    There's another error on the last double for loop, the solution is to change the dimensions of digits so that it doesn't use the last num_channels dimension:
    digit = x_decoded[0].reshape(img_width,img_height)

  • @j0shm0o1
    @j0shm0o1 2 года назад +3

    Thanks a lot for doing these videos ! Highly appreciated. I tried this program and got following error 'TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='tf.math.reduce_sum_5/Sum:0', description="created by layer 'tf.math.reduce_sum_5'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as `tf.cond`, `tf.function`, gradient tapes, or `tf.map_fn`. Keras Functional model construction only supports TF API calls that *do* support dispatching, such as `tf.math.add` or `tf.reshape`. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom Keras layer `call` and calling that layer on this symbolic input/output...Can you please help?

    • @nirmalbaishnab4910
      @nirmalbaishnab4910 2 года назад

      I am facing the same error. I think the tensorflow and/or keras version changed causing this error. Did you find any solution yet?

    • @khalidmohammed5977
      @khalidmohammed5977 2 года назад

      @@nirmalbaishnab4910 me too

    • @dimitheodoro
      @dimitheodoro Год назад

      Ηas anyone solved this????

    • @sushilkhadka8069
      @sushilkhadka8069 Год назад +5

      @@dimitheodoro
      Add this
      import tensorflow._api.v2.compat.v1 as tf
      tf.disable_v2_behavior()

    • @dimitheodoro
      @dimitheodoro Год назад +2

      @@sushilkhadka8069 thank you so much!
      it works!!

  • @kingdomman1078
    @kingdomman1078 2 года назад

    I honestly don't know how to thank you so much !

  • @ckmeher_
    @ckmeher_ 2 года назад +2

    Sir, I tried running the code in google colab but I am getting this error
    TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='tf.math.reduce_sum/Sum:0', description="created by layer 'tf.math.reduce_sum'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as `tf.cond`, `tf.function`, gradient tapes, or `tf.map_fn`. Keras Functional model construction only supports TF API calls that *do* support dispatching, such as `tf.math.add` or `tf.reshape`. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom Keras layer `call` and calling that layer on this symbolic input/output.

    • @sakibferdous5630
      @sakibferdous5630 2 года назад

      @@samedbey3548 Hello Sama, can you please clarify this a little more? What should I do to resolve the issue? Thank you in advance.

    • @mathkernel5136
      @mathkernel5136 Год назад +6

      Add this
      import tensorflow._api.v2.compat.v1 as tf
      tf.disable_v2_behavior()

    • @sushilkhadka8069
      @sushilkhadka8069 Год назад

      @@mathkernel5136 thanks this worked!

    • @TheMagic0wnz
      @TheMagic0wnz Год назад

      @@mathkernel5136 Thanks!

    • @Kerem-Ertem
      @Kerem-Ertem 8 месяцев назад

      @@mathkernel5136 Sir you are amazing!

  • @juhisrivastava4965
    @juhisrivastava4965 3 года назад +3

    Thanks for the most simplest and least intimidating video on the concepts and implementation ever. The concepts are crystal clear now. Please help in explaining how to save and then reload the same model again given that there is an Encoder/Decoder and Custom Layer as well. If I save the vae and load it back I face an error as - ValueError: Unknown layer: CustomLayer. Please help. Thanks

  • @helloworld_hereiam1402
    @helloworld_hereiam1402 3 года назад +1

    Thanks for this excellent tutorial. How do we write the samples of a certain distribution say (-3, 3) to a new folder rather than displaying on the figure? Pls include that code statement as well. Thanks in advance.

  • @howardfabio
    @howardfabio 2 года назад

    excellent video for the subject. Your effort is greatly appreciated.

  • @marwaalfouly9134
    @marwaalfouly9134 Год назад

    Thank you for the informative implementation. I am trying to use VAE for image-inpainting (starting point). I feed the network with incomplete images. I am not sure how to adapt this implementation such that loss is computed against the complete image, not the masked/incomplete ones. any leads?

  • @manbunmath
    @manbunmath 2 года назад

    First of all, thank you for your videos. I followed your model, and I am trying to tweak this VAE for anomaly detection. I trained using only 5s, and I want to see if it can detect 4s as an anomaly, for example. I tried prediction = vae.predict(sample), but the prediction and sample are identical every time! Something must be wrong because I expect that there should be a random sampling of the latent space for every prediction, thus shouldn't there at least be small variations? Could this be a biproduct of setting loss=None in the compiler and instead having the loss function defined in a custom layer?

  • @jennilthiyam1261
    @jennilthiyam1261 4 месяца назад

    when i run fit, i ran into an error of
    TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='tf.math.reduce_sum_3/Sum:0', description="created by layer 'tf.math.reduce_sum_3'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as `tf.cond`, `tf.function`, gradient tapes, or `tf.map_fn`. Keras Functional model construction only supports TF API calls that *do* support dispatching, such as `tf.math.add` or `tf.reshape`. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom Keras layer `call` and calling that layer on this symbolic input/output.

  • @josephpareti9156
    @josephpareti9156 Год назад

    is there a way to get rid of class CustomLayer(keras.layers.Layer) and write in simple python with a funtion that calculates the sum of the 2 loss terms ? The coode that follows does NOT work:
    def vae_loss(x, z_decoded):
    x = K.flatten(x)
    z_decoded = K.flatten(z_decoded)
    recon_loss = keras.metrics.binary_crossentropy(x, z_decoded)
    kl_loss = -5e-4 * K.mean(1 + z_sigma - K.square(z_mu) - K.exp(z_sigma), axis=-1)
    return K.mean(recon_loss + kl_loss)
    y = decoder(z)
    vae = Model(input_img, y, name='vae')
    vae.compile(optimizer='adam', loss=vae_loss)
    vae.fit(x_train, None, epochs = 10, batch_size = 32, validation_split = 0.2)

  • @juhisrivastava4965
    @juhisrivastava4965 3 года назад +1

    Please add one more video on VAE for Categorial Data (using categorical reparameterization with gumbel-softmax)

  • @idiotvoll21
    @idiotvoll21 Год назад

    Thanks for the great Video! P.S: Did someone find the Movistar dataset, that he talks about in the end? :)

  • @kfirdaus97
    @kfirdaus97 Год назад

    Hi Sir. Superb explanation from the start. I really appreciate it. By the way, have you try this VAE model with the movie star dataset that you mention in the last part of this video. Really looking forward for the explanation video on it

  • @surflaweb
    @surflaweb 3 года назад

    Hello sir and where is the precision of the model?

  • @unisali1432
    @unisali1432 3 года назад

    Sir i have a little concussion...
    Mean layer and variance layer are connected to the same layer then how mean layer computes mean and how variance layer computes variance?

  • @cptechno
    @cptechno 2 года назад

    Is the latent space one-dimentional or two-dimentional, like the data or something else?

  • @fabiantanne4798
    @fabiantanne4798 3 года назад

    How can I generate a sample from the underlying prior instead of a random sample vector?

  • @sc_santy
    @sc_santy 2 года назад

    Hi Sreeni, this video was really helpful. But, I am having tough time understanding, that why you used, mu + exp(sigma/2) * epsilon. The expression was mu + sigma * epsilon

    • @santysayantan
      @santysayantan 2 года назад

      @@samedbey3548 Okay makes sense, then what is the divided by 2 for?

  • @manelmhiri67
    @manelmhiri67 2 года назад

    Thanks for the video
    my data is a CSV file, and my vae is multi-input, what should I change in the customlayer() class or in this line "y = CustomLayer()([[x_in,y_in,z_in], z_decoded])" so it can work perfectly?
    thank you in advance sir

  • @varshakcolab5460
    @varshakcolab5460 2 года назад

    Hi, such a helpful video, thank you Sreeni!
    I was wondering, suppose i'm working on a different data and the latent vector dimension is say 128 instead of 2, how do we visualize and figure out each value of the sample_vector to generate data then?

  • @AhmedElsheikh-b7y
    @AhmedElsheikh-b7y 4 месяца назад

    thanks alot for this explanation.
    i am having a small error while trying to run the code.
    the fit step:
    vae.fit(x_train, None, epochs = 5, batch_size = 32, validation_split = 0.2)
    the error:
    TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='tf.math.reduce_sum_2/Sum:0', description="created by layer 'tf.math.reduce_sum_2'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as `tf.cond`, `tf.function`, gradient tapes, or `tf.map_fn`. Keras Functional model construction only supports TF API calls that *do* support dispatching, such as `tf.math.add` or `tf.reshape`. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom Keras layer `call` and calling that layer on this symbolic input/output.

  • @talhaim92
    @talhaim92 2 года назад +1

    please help.
    I'm getting this error:
    TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='tf.math.reduce_sum_1/Sum:0', description="created by layer 'tf.math.reduce_sum_1'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as `tf.cond`, `tf.function`, gradient tapes, or `tf.map_fn`. Keras Functional model construction only supports TF API calls that *do* support dispatching, such as `tf.math.add` or `tf.reshape`. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom Keras layer `call` and calling that layer on this symbolic input/output.
    what should I do?

    • @hibafaisal4129
      @hibafaisal4129 2 года назад +1

      Hi, were you able to solve this error? I am also getting same one

    • @yiweihe3194
      @yiweihe3194 2 года назад +1

      Same problem here.

    • @kfirdaus97
      @kfirdaus97 2 года назад

      Me too. Pls let us know if you able to solve it

  • @victorarayal
    @victorarayal Год назад +1

    The code does not work =(

  • @jun2705
    @jun2705 Год назад

    Amazing video!, love it🎉

  • @user-kb9rj8st7x
    @user-kb9rj8st7x 5 месяцев назад

    Which version of keras is it???

  • @angelazhang9082
    @angelazhang9082 3 года назад

    Great explanation! How do we know which file from the github references this video? I can't find it by the Title of the files, and there are LOTs of files in the Github.

    • @DigitalSreeni
      @DigitalSreeni  3 года назад +1

      This is exactly why I numbered my videos and corresponding files on Github.

  • @umairsabir6686
    @umairsabir6686 3 года назад

    Beautifully explained !

  • @yingxiaokong5233
    @yingxiaokong5233 3 года назад

    Very detailed explanation! One thing I'm not very clear is that why you said y is the reconstructed image? Shouldn't it be z_decoded?

    • @alexkoch2664
      @alexkoch2664 3 года назад

      Yes, if you want the final VAE model to return the decoded image as output, then call(self,inputs) should return z_decoded instead of x. This took me awhile to realize, so I hope this helps! This video was tremendously helpful otherwise!

  • @user-gd5ww3se3o
    @user-gd5ww3se3o 10 месяцев назад

    Thank you very much this was very useful and clear!!! Could you make a video on Beta VAE? It would be very interesting for anyone working with this models

  • @geeky_explorer9105
    @geeky_explorer9105 3 года назад

    Thanks that was a great expectation, but please help I can't train the model, as it's showing unhashable error when I applied custom layer for loss, and also when I created the loss function used by you and passed it in model.compile loss becomes null, please help in that I have wasted one whole day l, but couldn't detect the problem

  • @gravity9.84
    @gravity9.84 Год назад

    How to save this model?

  • @rogeriogouvea7278
    @rogeriogouvea7278 Год назад

    great job man

  • @talha_anwar
    @talha_anwar 3 года назад

    I did not get lambda function

  • @nandankakadiya1494
    @nandankakadiya1494 3 года назад

    This one is amazing great content

  • @razor1887
    @razor1887 2 года назад +2

    If anyone is getting a type error when trying to run the code in google colab try this,
    Create a new code block and run these two lines
    !pip install tensorflow==1.13.2
    !pip install q keras==2.0.8
    then go to -> Runtime -> Restart Runtime and try to run the code again and it should work

    • @khalidmohammed5977
      @khalidmohammed5977 2 года назад

      can you tell us what should be changed to work in latest tensorflow version??

  • @Jk-jn5ei
    @Jk-jn5ei 2 года назад

    Great job , very analytical explanation. I am tryin to run it for my model with a target y on fit method but I can't. Any suggestions? Thanks!

    • @yashpisat9267
      @yashpisat9267 Год назад

      I am facing the same problem, did you find any solution?

  • @yashpisat9267
    @yashpisat9267 Год назад

    I have been trying to implement VAE and this is the best video I have found. I followed each and every step but there is some weird error and many people are facing the same error who have watched your video. Can you help me with it?

    • @blasttrash
      @blasttrash Год назад

      Is it this error?
      TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, you may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.

    • @yashpisat9267
      @yashpisat9267 Год назад

      @@blasttrash yes! This is the error!

  • @FabioKasper
    @FabioKasper 2 года назад

    Great explanation. Thanks.

  • @RahmanIITDelhi
    @RahmanIITDelhi 2 года назад

    Awsm...sir thanks alot....

  • @zwergi1
    @zwergi1 2 года назад

    my scatterplot of the latent space is never symmetrical, yaxis: (-4,0) and xaxis: (0,5), and i had (-4,0) and (-4,0) as well one time. does anybody know what my error could be?

  • @jahcane3711
    @jahcane3711 3 года назад

    you earnt my sub with this video. thank you

  • @satyajittourani9175
    @satyajittourani9175 3 года назад

    You are awesome! 😀

  • @3washoka
    @3washoka 3 года назад

    thank you for the great tutorial !!

  • @gabrielcabas907
    @gabrielcabas907 9 месяцев назад

    Thanks!!

  • @tamzidalam8766
    @tamzidalam8766 Год назад

    Please can anyone tell how to save and reload this model?

  • @pablovaras9435
    @pablovaras9435 Год назад

    great video

  • @dimitrisexarchou5378
    @dimitrisexarchou5378 3 года назад

    I would like to thank you for your great work! You inspire many young programmers to learn more about machine learning!
    When I try to execute your code in my local GPU, I see the following error:
    Resource exhausted: OOM when allocating tensor with shape[32,32,29,29] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc.
    I tried to decrease batch size to 1 and still have an OOM error. Does anybody know what should I do next?

    • @DigitalSreeni
      @DigitalSreeni  3 года назад +2

      You are getting out of memory error. Try reducing batch size or resizing images to smaller size. OOM error is common with GPU with small memory, usually below 4GB.

  • @samarafroz9852
    @samarafroz9852 3 года назад

    Thanks so much sir.

  • @subashchandrapakhrin3537
    @subashchandrapakhrin3537 2 года назад

    Very good video on VAE's

  • @zakirshah7895
    @zakirshah7895 3 года назад

    Sir could you please make a video on Test Time Augmentation please ...

  • @sivanschwartz3813
    @sivanschwartz3813 2 года назад

    GREAT!!!!!

  • @michaelmoore7568
    @michaelmoore7568 2 года назад

    What do Conv[0] , Conv[1],Conv[2] mean?

    • @DigitalSreeni
      @DigitalSreeni  2 года назад +1

      I don't think there is anything like Conv[0] in the code. In case you are referring to conv_shape[0], it is explained in line 72 of the code. It is the shape of conv to be provided to decoder.

    • @michaelmoore7568
      @michaelmoore7568 2 года назад

      @@DigitalSreeni Yes - that's what I meant. THank you

  • @khaledbenaggoune8598
    @khaledbenaggoune8598 3 года назад

    Thanks sir

  • @mmv365
    @mmv365 Год назад

    For me it' s not intuitive why the .fit method uses (X_train,None) when it should be (X_train,X_train ) . Btw great explanation overall

    • @DigitalSreeni
      @DigitalSreeni  Год назад

      In a standard autoencoder, the input data is used both as the input and target for training. This means that the autoencoder tries to reconstruct the input data as closely as possible. The .fit method typically takes (X_train, X_train) format.
      VAE is a specific type of autoencoder that adds a constraint to the latent space by using probabilistic techniques. The objective of a VAE is not only to reconstruct the input data but also to learn a probabilistic representation of the data in the latent space. This latent space representation is then used to generate new data points by sampling from the learned distribution. So, in the context of Keras (or other deep learning frameworks), when fitting a VAE model, the .fit method often takes (X_train, None) instead of (X_train, X_train). The reason for this is that in a VAE, the model's output consists of both the reconstructed data and the parameters representing the latent space distribution. The None value is passed as the target because the target for the regularization loss is not the input data (X_train) but rather the desired shape of the latent space distribution (typically a standard normal distribution).

    • @mmv365
      @mmv365 Год назад +1

      @@DigitalSreeni Appreciate your explanation sir , really helpfull. thank you so much

  • @fjonewport
    @fjonewport 3 года назад

    FYI, I was only able to get this example to work with keras 2.0.8 and. tensorflow 1.4 in python 3.5. I tried it in. python 3.8 with keras 2.4.3 and tensorflow would crash on the training part.

    • @DigitalSreeni
      @DigitalSreeni  3 года назад +1

      Well, I am glad you found the version where this works for you.

    • @leosmi1
      @leosmi1 3 года назад

      Is the input dimension? Are you using binary categorizing?

  • @mostafahasanian5421
    @mostafahasanian5421 Год назад

    Thanks

  • @arkadeepdas7397
    @arkadeepdas7397 2 года назад

    Can anyone please explain this KL loss equation kl_loss = -5e-4 * K.mean(1 + z_sigma - K.square(z_mu) - K.exp(z_sigma), axis=-1)

  • @agsantiago22
    @agsantiago22 Год назад

    Merci !

  • @ramanathanperumal399
    @ramanathanperumal399 3 года назад

    thanks