179 - Variational autoencoders using keras on MNIST data

Sdílet
Vložit
  • čas přidán 30. 11. 2020
  • Code generated in the video can be downloaded from here:
    github.com/bnsreenu/python_fo...
  • Věda a technologie

Komentáře • 150

  • @sanketgadge9060
    @sanketgadge9060 Před 3 lety +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 Před 3 lety +8

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

  • @parthnaik816
    @parthnaik816 Před 3 lety +7

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

  • @jaikishank
    @jaikishank Před 3 lety

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

  • @nickstaresinic9933
    @nickstaresinic9933 Před 3 lety

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

  • @rs9130
    @rs9130 Před 2 lety

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

  • @swethanandyala
    @swethanandyala Před 3 měsíci +1

    This explanation is like a Gem!!

  • @samarafroz9852
    @samarafroz9852 Před 2 lety +1

    This is the best tutorial on whole CZcams for VAE

  • @HI_YT66
    @HI_YT66 Před rokem

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

  • @user-or7ji5hv8y
    @user-or7ji5hv8y Před 3 lety

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

  • @morningmoon6100
    @morningmoon6100 Před 3 lety +1

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

  • @meeribad6784
    @meeribad6784 Před 3 lety

    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!!

  • @comrade531
    @comrade531 Před 2 lety

    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 😊👌

  • @kim66003
    @kim66003 Před 3 lety +1

    This tutorial is a lifesaver!!!!

  • @Kerem-Ertem
    @Kerem-Ertem Před 6 měsíci

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

  • @howardfabio
    @howardfabio Před 2 lety

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

  • @kingdomman1078
    @kingdomman1078 Před 2 lety

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

  • @jun2705
    @jun2705 Před rokem

    Amazing video!, love it🎉

  • @micaelmarquez6225
    @micaelmarquez6225 Před rokem +2

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

  • @chid3835
    @chid3835 Před 3 lety +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 Před 2 lety

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

    • @talhahafeez5309
      @talhahafeez5309 Před rokem

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

  • @umairsabir6686
    @umairsabir6686 Před 3 lety

    Beautifully explained !

  • @nandankakadiya1494
    @nandankakadiya1494 Před 3 lety

    This one is amazing great content

  • @harshadlokhande_veditekk

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

    • @DigitalSreeni
      @DigitalSreeni  Před 2 lety +1

      Glad you think so!

    • @harshadlokhande_veditekk
      @harshadlokhande_veditekk Před 2 lety

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

  • @rogeriogouvea7278
    @rogeriogouvea7278 Před rokem

    great job man

  • @FabioKasper
    @FabioKasper Před 2 lety

    Great explanation. Thanks.

  • @jahcane3711
    @jahcane3711 Před 3 lety

    you earnt my sub with this video. thank you

  • @sreejithpro
    @sreejithpro Před 3 lety +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 Před 9 měsíci

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

    • @kroax9720
      @kroax9720 Před 4 měsíci

      Stuck at the same error , please help

  • @3washoka
    @3washoka Před 3 lety

    thank you for the great tutorial !!

  • @samarafroz9852
    @samarafroz9852 Před 3 lety

    Thanks so much sir.

  • @s4life91
    @s4life91 Před rokem

    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.

  • @gabrielcabas907
    @gabrielcabas907 Před 7 měsíci

    Thanks!!

  • @RahmanIITDelhi
    @RahmanIITDelhi Před rokem

    Awsm...sir thanks alot....

  • @helloworld_hereiam1402
    @helloworld_hereiam1402 Před 3 lety +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.

  • @satyajittourani9175
    @satyajittourani9175 Před 2 lety

    You are awesome! 😀

  • @pablovaras9435
    @pablovaras9435 Před rokem

    great video

  • @manbunmath
    @manbunmath Před 2 lety

    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?

  • @samhuguet861
    @samhuguet861 Před rokem +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

  • @sivanschwartz3813
    @sivanschwartz3813 Před 2 lety

    GREAT!!!!!

  • @khaledbenaggoune8598
    @khaledbenaggoune8598 Před 3 lety

    Thanks sir

  • @kfirdaus97
    @kfirdaus97 Před rokem

    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

  • @marwaalfouly9134
    @marwaalfouly9134 Před rokem

    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?

  • @juhisrivastava4965
    @juhisrivastava4965 Před 3 lety +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

  • @ugursopaoglu
    @ugursopaoglu Před 3 lety +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 Před 11 měsíci

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

  • @razor1887
    @razor1887 Před rokem +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 Před rokem

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

  • @varshakcolab5460
    @varshakcolab5460 Před 2 lety

    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?

  • @user-gd5ww3se3o
    @user-gd5ww3se3o Před 8 měsíci

    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

  • @MOTIVAO
    @MOTIVAO Před rokem

    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)

  • @ramanathanperumal399
    @ramanathanperumal399 Před 3 lety

    thanks

  • @manelmhiri67
    @manelmhiri67 Před rokem

    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

  • @idiotvoll21
    @idiotvoll21 Před rokem

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

  • @mostafahasanian5421
    @mostafahasanian5421 Před 10 měsíci

    Thanks

  • @juhisrivastava4965
    @juhisrivastava4965 Před 3 lety +1

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

  • @angelazhang9082
    @angelazhang9082 Před 2 lety

    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  Před 2 lety +1

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

  • @subashchandrapakhrin3537

    Very good video on VAE's

  • @yingxiaokong5233
    @yingxiaokong5233 Před 3 lety

    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 Před 2 lety

      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!

  • @fabiantanne4798
    @fabiantanne4798 Před 3 lety

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

  • @cptechno
    @cptechno Před 2 lety

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

  • @Jk-jn5ei
    @Jk-jn5ei Před 2 lety

    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 Před rokem

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

  • @geeky_explorer9105
    @geeky_explorer9105 Před 3 lety

    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

  • @unisali1432
    @unisali1432 Před 3 lety

    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?

  • @surflaweb
    @surflaweb Před 3 lety

    Hello sir and where is the precision of the model?

  • @dimitrisexarchou5378
    @dimitrisexarchou5378 Před 3 lety

    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  Před 3 lety +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.

  • @sc_santy
    @sc_santy Před 2 lety

    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 Před 2 lety

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

  • @jennilthiyam1261
    @jennilthiyam1261 Před 2 měsíci

    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.

  • @zwergi1
    @zwergi1 Před 2 lety

    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?

  • @zakirshah7895
    @zakirshah7895 Před 3 lety

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

  • @j0shm0o1
    @j0shm0o1 Před 2 lety +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 Před rokem

      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 Před rokem

      @@nirmalbaishnab4910 me too

    • @dimitheodoro
      @dimitheodoro Před rokem

      Ηas anyone solved this????

    • @sushilkhadka8069
      @sushilkhadka8069 Před rokem +5

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

    • @dimitheodoro
      @dimitheodoro Před rokem +2

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

  • @yashpisat9267
    @yashpisat9267 Před rokem

    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 Před rokem

      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 Před rokem

      @@blasttrash yes! This is the error!

  • @user-kb9rj8st7x
    @user-kb9rj8st7x Před 3 měsíci

    Which version of keras is it???

  • @user-sd5rw7jw6t
    @user-sd5rw7jw6t Před 2 měsíci

    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.

  • @josephpareti9156
    @josephpareti9156 Před 11 měsíci

    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)

  • @talha_anwar
    @talha_anwar Před 3 lety

    I did not get lambda function

  • @talhaim92
    @talhaim92 Před 2 lety +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 Před 2 lety +1

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

    • @yiweihe3194
      @yiweihe3194 Před 2 lety +1

      Same problem here.

    • @kfirdaus97
      @kfirdaus97 Před rokem

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

  • @tamzidalam8766
    @tamzidalam8766 Před rokem

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

  • @ckmeher_
    @ckmeher_ Před 2 lety +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 Před 2 lety

      @@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 Před rokem +6

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

    • @sushilkhadka8069
      @sushilkhadka8069 Před rokem

      @@mathkernel5136 thanks this worked!

    • @TheMagic0wnz
      @TheMagic0wnz Před rokem

      @@mathkernel5136 Thanks!

    • @Kerem-Ertem
      @Kerem-Ertem Před 6 měsíci

      @@mathkernel5136 Sir you are amazing!

  • @gravity9.84
    @gravity9.84 Před 11 měsíci

    How to save this model?

  • @fjonewport
    @fjonewport Před 3 lety

    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  Před 3 lety +1

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

    • @leosmi1
      @leosmi1 Před 3 lety

      Is the input dimension? Are you using binary categorizing?

  • @victorarayal
    @victorarayal Před 10 měsíci +1

    The code does not work =(

  • @arkadeepdas7397
    @arkadeepdas7397 Před rokem

    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)

  • @michaelmoore7568
    @michaelmoore7568 Před rokem

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

    • @DigitalSreeni
      @DigitalSreeni  Před rokem +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 Před rokem

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

  • @agsantiago22
    @agsantiago22 Před rokem

    Merci !

  • @mmv365
    @mmv365 Před 11 měsíci

    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  Před 11 měsíci

      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 Před 11 měsíci +1

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