TensorFlow Tutorial 8 - Model Subclassing with Keras

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ธ.ค. 2024

ความคิดเห็น • 63

  • @AladdinPersson
    @AladdinPersson  2 ปีที่แล้ว +4

    I was inspired and learned the basics of TensorFlow after I completed the TensorFlow specialization on coursera. Personally I think these videos I created give a similar understanding but if you wanna check it out you can. Below you'll find both affiliate and non-affiliate links, the pricing for you is the same but a small commission goes back to the channel if you buy it through the affiliate link which helps me create more future videos.
    affiliate: bit.ly/3JyvdVK
    non-affiliate: bit.ly/3qtrK39

  • @slouma1998
    @slouma1998 4 ปีที่แล้ว +15

    Lucky that I bumped on this video, wish to see more code oriented deep learning material like this one. Great job!

    • @AladdinPersson
      @AladdinPersson  4 ปีที่แล้ว +4

      Thanks for the kind words 🙏

  • @HeyFaheem
    @HeyFaheem ปีที่แล้ว +1

    I Searched a lot fot Subclassing like pytorch in tensorflow..
    I Finally Found the Best..

  • @RanDuan-dp6oz
    @RanDuan-dp6oz ปีที่แล้ว +1

    Thanks!

  • @nikitakrasnytskyi
    @nikitakrasnytskyi 2 ปีที่แล้ว

    Thank you very much for the content! It is better than some articles in the net!

  • @AliRashidi97
    @AliRashidi97 2 ปีที่แล้ว

    This Tutorial was AWESOME!!!! TNX A TON!!!

  • @aymensekhri2133
    @aymensekhri2133 3 ปีที่แล้ว +1

    Amazing, i hated tensorflow before but now i really like it. it looks like pytroch in logic

  • @ningquanwang142
    @ningquanwang142 3 ปีที่แล้ว +9

    Thanks for the great video! I am wondering is the call() method in a class a built-in function to convert a class instance into a function? I know there is a __call__() method, but is the call() method the same with the __call__() method?

    • @egolkar
      @egolkar ปีที่แล้ว

      does anyone can answer this quetion? how Call method automatically called without calling outside of the Class?

  • @Champignon1000
    @Champignon1000 3 ปีที่แล้ว

    Man, i can't believe you don't have more followers, i love your videos and ill be here untill you reach 3.000.000 subs

  • @JuliusUnscripted
    @JuliusUnscripted 3 ปีที่แล้ว +3

    to get a summary when using subclassing you can use the build command and specify the shape in the parameter:
    # example:
    dtc2vec.build(input_shape=(BATCH_SIZE,2))
    dtc2vec.summary()
    for some reason i still get the output "multiple" for embedding layers but the other layers show the output shape

  • @hariomhudiya8263
    @hariomhudiya8263 4 ปีที่แล้ว +1

    Just what I was looking for Thanks ✌

  • @filippoguerranti
    @filippoguerranti 3 ปีที่แล้ว +1

    Thanks for the amazing videos of this playlist!
    May I ask you which IDE are you using and what theme is that?

  • @wolfisraging
    @wolfisraging 4 ปีที่แล้ว +1

    I remember when I first saw tf allowing this class sub classing like pytorch I immediately fell in love it after first usage. Still lovin it, the only complaint I have is when we summarize the model we don't get to see the shapes of intermediate blocks :} that's why sometimes I prefer functional api. Anyways, great video. 🙂

    • @AladdinPersson
      @AladdinPersson  4 ปีที่แล้ว +2

      Yeah it reminds me so much of PyTorch.. so I love it 😅 Thank you for the comment, let me know if you have any feedback, what I can improve in making these videos, etc.

    • @wolfisraging
      @wolfisraging 4 ปีที่แล้ว

      @@AladdinPersson Your videos are exceptionally excellent and unique already, even I planned to create such channel, but kinda busy for now, will see. :)

  • @coding10yearold
    @coding10yearold 3 ปีที่แล้ว +1

    Newbie question:
    @Aladdin Persson
    why are they called 3 times in a row?
    I was guessing
    (None, 28, 28, 32)
    (None, 28, 28, 64)
    (None, 28, 28, 128)
    would be called once every Epoch

  • @beizhou2488
    @beizhou2488 4 ปีที่แล้ว +1

    I never thought that the MNIST datasets could also be used this way. Haha. Taking it to the next level.

    • @AladdinPersson
      @AladdinPersson  4 ปีที่แล้ว

      Haha I guess it's bit of an overkill :)

    • @tsegaamanuel5907
      @tsegaamanuel5907 4 ปีที่แล้ว

      @@AladdinPersson That's an understatement lol

  • @coding10yearold
    @coding10yearold 3 ปีที่แล้ว +1

    @7:05 Why is it rerun again?

  • @AshishKumar-uj7ox
    @AshishKumar-uj7ox 3 ปีที่แล้ว

    Thanks a ton for this excellent series of tutorial. I have a question. Can we make execution of some layers in the subclass conditional? For example if i added maxpool layer to subclass , and I didn't want to run it for the last CNNBlock, then how can I do that.

  • @anmarali2189
    @anmarali2189 2 ปีที่แล้ว

    Can you please make a video on "custom padding" like adding a single row above the image and a single col. to the left of the image of 28 X 28 X 1 since keras does not give such flexibility, thanks in advance.

  • @DanielWeikert
    @DanielWeikert 4 ปีที่แล้ว +1

    Thanks for the video. Just one question. Normally we always need to specify the input shape/input_dim of the data we throw into the model. Here we did not do it and it still ran. Can you elaborate on that

    • @AladdinPersson
      @AladdinPersson  4 ปีที่แล้ว +1

      From my understanding we do not need to specify the input shape for the model to run, for example if we create a simple sequential model it is still able to run without specifying the input with keras.Input. However if you do specify the input you're able to run (for example) model.summary() and I'm assuming other functionality that I'm not familiar with

    • @DanielWeikert
      @DanielWeikert 4 ปีที่แล้ว

      @@AladdinPersson Thanks, do you think this true for all networks layers when we use them as the first layer, e.g. Embedding, LSTM, GRU,...)

  • @legacies9041
    @legacies9041 4 ปีที่แล้ว +2

    What is the use of call function? Please explain

    • @Roscovanul2
      @Roscovanul2 3 ปีที่แล้ว +3

      I found the answer here.
      stackoverflow.com/questions/59473267/why-in-keras-subclassing-api-the-call-method-is-never-called-and-as-an-alternat
      __call__ method is implemented in the Layer class, which is inherited by CNNBlock class
      So actually what we do is overriding the inherited call method, which new call method will be then called from the inherited __call__ method.
      So when we call our model instance, the inherited __call__ method will be executed automatically, which calls our OWN call method.

  • @vishalsingh-yj8bk
    @vishalsingh-yj8bk 3 ปีที่แล้ว

    Hi Aladdin! I was going through the GitHub repo so that I could go over the code that you have written in this tutorial; it seems the code is missing for this tutorial. Could you please post it on Github as well ?. Thank you.

  • @maddoo23
    @maddoo23 2 ปีที่แล้ว

    Hi, I constructed the subclassed layer/block and tried using it in a functional API (like you have used in sequential API). It throws an error for me (graph discnnected). Basically, its not accepting the output of the block as an input for the next layer. Can you please help me with it or better still, make a video on it?

  • @chadwinters4285
    @chadwinters4285 3 ปีที่แล้ว +1

    How does the call method work ? I know that you can call a class with MyClass(), but how does it know to run the call method ?

    • @AladdinPersson
      @AladdinPersson  3 ปีที่แล้ว +2

      The __call__ method of the parent class layers.Layer calls the call() function, hopefully that wasn't confusing lol

  • @riis08
    @riis08 4 ปีที่แล้ว

    @Aladdin Persson: amazing video once again... thanks for this great tensorflow playlist. One question, what you think when we subclassing the tf.keras.Model, can we use tf.keras.Sequential() inside of that class? And second question is can we use __call__ instead of call()??

    • @AladdinPersson
      @AladdinPersson  4 ปีที่แล้ว +3

      Yes from my understanding and experiments you can mix between sequential, functional and subclassing seemlessly and that's really powerful in my opinion. Just trying the second part of replacing __call__ instead of call it doesn't work, but I guess it's more interesting to ask why and scimming through the source code for layers. Layer does a lot of things under the hood, such as creating the graph, context managers and a bunch of things. You can read some more about it's __call__ here: github.com/tensorflow/tensorflow/blob/b36436b087bd8e8701ef51718179037cccdfc26e/tensorflow/python/keras/engine/base_layer.py#L875
      But so self.call() (that we've implemented) is just a small part of the __call__ of layers.Layer that we're inheriting and in that sense I guess it would make sense that we cannot simply replace call with __call__

  • @milak.9189
    @milak.9189 3 ปีที่แล้ว

    Please Please, can you explain how to export Keras subclassed model with 2 args as a SavedModel? I didn't can't save my subclass model ,can you help me?

  • @eliashossain4327
    @eliashossain4327 2 ปีที่แล้ว

    Could you please specify why you have considered channels[1] rather than channels [0] and channels[2] ?
    For example,
    self.identity_mapping= layers.Conv2D(channels[1], 3, padding='same')

  • @shaikrasool1316
    @shaikrasool1316 4 ปีที่แล้ว +1

    Sir, make videos on question answering in pytorch and seq to seq in keras

    • @AladdinPersson
      @AladdinPersson  4 ปีที่แล้ว +1

      Will look into it!

    • @bharath5666
      @bharath5666 4 ปีที่แล้ว

      Aladdin Persson sequence to sequence from scratch in Keras.

  • @rachidelfermi6759
    @rachidelfermi6759 3 ปีที่แล้ว

    thank you

  • @artabalt4288
    @artabalt4288 4 ปีที่แล้ว

    Just what i was looking for. I was wondering, maybe you could make a video about how to use
    M = tf.keras.Model()
    from tensorflow.keras.utils import plot_model
    plot_model(M, to_file='Example.png')
    maybe that would show the dimensions?

  • @god-son-love
    @god-son-love 3 ปีที่แล้ว

    How to train with mixed inputs and outputs ?

  • @unamattina6023
    @unamattina6023 2 ปีที่แล้ว

    what is the meaning of super(CNNBlock, self).__init__() ?
    how do we know our CNNBlock class has conv and bn attributes, where is the base CNNBlock class?

    • @Zimzode
      @Zimzode 8 หลายเดือนก่อน

      The class CNNBlock inherits all the attributes of layers.Layer from the line:
      class CNNBlock(layers.Layer)
      and then when you call super, you're initializing each instance of CNNBlock with all the attributes of layers.Layer

  • @mushahid9537
    @mushahid9537 3 ปีที่แล้ว

    I was pretty confuse when he calls for base class constructor by passing arguments the name of subclass and self in super methods, this method is used only for Python 2.x versions, we don't need to pass the parameters for super method in Python 3.X anymore.

  • @muckvix
    @muckvix 4 ปีที่แล้ว

    So what would be the problem with writing this in functional API?

    • @AladdinPersson
      @AladdinPersson  4 ปีที่แล้ว

      The skip connections for example

    • @muckvix
      @muckvix 4 ปีที่แล้ว

      @@AladdinPersson that should be ok: stackoverflow.com/a/42391339/336527

  • @pedrogalvez6399
    @pedrogalvez6399 3 ปีที่แล้ว

    Hi! thank you for this amazing series. However, when applying the ResNet_Like model, I get the following warning :
    WARNING:tensorflow:AutoGraph could not transform and will run it as-is.
    Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
    Any idea what would be causeing it? Should I ignore it?
    I'm running TF2.1
    Thank you!
    Pedro

    • @2009feedback
      @2009feedback 2 ปีที่แล้ว

      I think you need to install your tensorflow-estimator from Anaconda 3 Navigator

    • @hunterwarick5135
      @hunterwarick5135 2 ปีที่แล้ว

      Did you ever figure out the issue? because I am having the same problem

  • @rordic.y5947
    @rordic.y5947 3 ปีที่แล้ว

    The adobe premiere all of a sudden pops up makes me very shifting about the focus of the latest study aims

  • @pankajshinde475
    @pankajshinde475 4 ปีที่แล้ว

    Can you suggest some udemy courses?

    • @AladdinPersson
      @AladdinPersson  4 ปีที่แล้ว +6

      I haven't done any Udemy courses so I don't have any suggestions there. I don't know this might just be me, but I don't like the feeling I get from Udemy. Feels scammy in my opinion. Just this "5 hours left at this price!!!, 99% off, BUY now!" shit makes me super annoyed. But I should probably get some experience with it before I judge it :)

    • @hariomhudiya8263
      @hariomhudiya8263 4 ปีที่แล้ว +2

      Books + Internet >> Udemy course

  • @donfeto7636
    @donfeto7636 2 ปีที่แล้ว

    def call(self,input_tensor,training=False):
    y=self.cnn1(input_tensor,training=training)#CNN Layer and will output x as output from relu CONV,BatchNorm,Relu (this is call)
    x=self.cnn2(y,training=training)
    x=self.cnn3(x+self.identity_mapping(y),training=training)
    i think in Reset would be like that as i understand --not self.identity_mapping(tensor_input) as this would be the a[0] not a[1] as we have 3 Layers

  • @HallockW
    @HallockW 2 ปีที่แล้ว

    i copy your code from the beginning part(CNNBlock), goes to [
    E:/pythonProject1/subclass.py:20 call *
    x = self.conv(inputs)
    AttributeError: 'CNNBlock' object has no attribute 'conv']
    cant figure out whats wrong in the Class part.

    • @HallockW
      @HallockW 2 ปีที่แล้ว

      nevermind just find out that i mistake __int__ as __init__, and it take me half a day to know, fml

    • @Zimzode
      @Zimzode 8 หลายเดือนก่อน

      @@HallockW all part of the process. That half a day figuring out how to find that mistake will save you tons of time finding similar mistakes in the future