Convolutional Neural Network from Scratch | Mathematics & Python Code

Поділитися
Вставка
  • Опубліковано 19 чер 2024
  • In this video we'll create a Convolutional Neural Network (or CNN), from scratch in Python. We'll go fully through the mathematics of that layer and then implement it. We'll also implement the Reshape Layer, the Binary Cross Entropy Loss, and the Sigmoid Activation. Finally, we'll use all these objects to make a neural network capable of classifying hand written digits from the MNIST dataset.
    😺 GitHub: github.com/TheIndependentCode...
    🐦 Twitter: / omar_aflak
    Chapters:
    00:00 Intro
    00:33 Video Content
    01:26 Convolution & Correlation
    03:24 Valid Correlation
    03:43 Full Correlation
    04:35 Convolutional Layer - Forward
    13:04 Convolutional Layer - Backward Overview
    13:53 Convolutional Layer - Backward Kernel
    18:14 Convolutional Layer - Backward Bias
    20:06 Convolutional Layer - Backward Input
    27:27 Reshape Layer
    27:54 Binary Cross Entropy Loss
    29:50 Sigmoid Activation
    30:37 MNIST
    ====
    Corrections:
    23:45 The sum should go from 1 to d
    ====
    Animation framework from @3Blue1Brown: github.com/3b1b/manim

КОМЕНТАРІ • 260

  • @KCOANIKETSINGH
    @KCOANIKETSINGH 3 роки тому +216

    This is one of the best explanation of CNN on the internet for me, and that 3b1b video format is cherry on the cake. Please keep on making these videos.

    • @zozodejante8350
      @zozodejante8350 2 роки тому +1

      Yeah , for sure !

    • @mysticlunala8020
      @mysticlunala8020 5 місяців тому

      Honestly, this is barely an explanation. He just showed you the steps to achieve CNN from scratch. He did not explain why we did some of the stuff we did, like the cross-correlation and stuff.

    • @flips4life892
      @flips4life892 5 місяців тому

      @@mysticlunala8020that's what other videos out there already do. The focus of this video was how to actually put all the concepts into code concisely and intuitively.

  • @TenzinDayoe-vy6vu
    @TenzinDayoe-vy6vu Рік тому +6

    Cannot believe that tutorials like this exist. Thank you so much. I have been looking for a tutorial for a long time and I finally found it. This is definitely one of the best tutorials out there!

  • @JPTL-bl4js
    @JPTL-bl4js Рік тому +3

    This is for real one of the best videos related to any type of NN I've ever seen. Most videos just scratch the surface of how these NNs work, but you went deeper and in an understandable way. Congratulations and keep the good work!

  • @FahmiNoorFiqri
    @FahmiNoorFiqri 2 роки тому +8

    Thank you so much! I've been searching for this kind of explanation of CNN, especially the backprop process. I'll for sure cite this video in my thesis. Thank you!

  • @3dascension744
    @3dascension744 2 роки тому +1

    I love your teaching! This is perfect for me and exactly what I have been looking for. Thank you for your contribution. These videos are gold!

  • @animeshpande1915
    @animeshpande1915 Рік тому +5

    After going through many blogs, this helped me just fully understand these networks. Such a great teacher you are!!!

  • @agredo0o388
    @agredo0o388 2 роки тому +4

    Thank you!! I'm making a machine learning library from scratch for fun and I've been confused with some details that thanks to you now I understand. It's my favorite explanation of CNNs on youtube

  • @BassMarineBeatz
    @BassMarineBeatz Рік тому +6

    This is the best and calm explanation in NNs that I have ever seen on Internet! Amazing work, definitely sharing it to my colleagues

  • @moopoo123
    @moopoo123 2 роки тому +1

    please please please keep making more videos. This is so insightful and relaxing to watch.

  • @user-wb3dh2ki9x
    @user-wb3dh2ki9x Рік тому +1

    the "from scratch" series you made is pure gold!!

  • @jamesnguyen3459
    @jamesnguyen3459 Рік тому +6

    Please produce more high quality videos like this. Your 30-minute video explains CNN better than my 1-semester AI class in college

  • @coreytaylor5406
    @coreytaylor5406 2 роки тому +2

    This is too much underrated.
    Keep doing the good work. I really appreciate your contribution.

  • @victorstafymegdarosa9751
    @victorstafymegdarosa9751 2 роки тому

    The best explanation of CNN I have ever seen. Thank you!

  • @Noname11251
    @Noname11251 Рік тому +1

    I am really so fortunate to have found this amazing video. I will really mention reference of this video at multiple places. Thanks for the hardwork :)

  • @rishabhgoel9971
    @rishabhgoel9971 Рік тому

    I am making a CNN from scratch and I was a little bit stuck on how to find the gradients of convolutional layers but that little digression about how the equation of a convolutional layer is really just a more general version of the equation of the dense layer output really made it clear for me! This video is gold

  • @dark_gamer4550
    @dark_gamer4550 2 роки тому +3

    I really love this explanation of CNNs. It almost makes them look easy

  • @ThePeacefulRulerOfRaspberries
    @ThePeacefulRulerOfRaspberries Рік тому +1

    You are a gifted teacher bro. I can't believe you've only got 50k views. But then again with how esoteric the content you're teaching is, it's impressive that your videos are so popular! Thank you

  • @hasanhuseyinyurdagul5403
    @hasanhuseyinyurdagul5403 2 роки тому

    Man, I hope you channel become very huge. Thanks, this is the one of the best videos on youtube and not just about this topic, it is in general one of the best video in youtube

  • @bhaveshachhada7242
    @bhaveshachhada7242 Рік тому

    True that. After reading so many blogs on Medium, none could solve all my doubts. You did it. Kudos to you.

  • @delete7316
    @delete7316 9 місяців тому +12

    I know it’s a bit late, but I thought I should mention how well this video is paced and structured. The listing and crossing out of what topics are to be covered makes the video very clear, concise and easy to follow.

  • @xiaojieyuan5336
    @xiaojieyuan5336 2 роки тому

    Finally understood backprop of conv. Thank you for the great video!

  • @Rafael_7891
    @Rafael_7891 2 роки тому

    You are one of the best had ever explained this topic. Keep up your easy and succinct style. thumbs up

  • @jameslannister3743
    @jameslannister3743 2 роки тому

    Came across this while trying to code Resnet in pure CUDA
    The best explanation on the topic!
    Great Thanks!!

  • @rocksbox156
    @rocksbox156 6 місяців тому

    I'm an undergrad student studying CS at Georgia Tech. This video explained the backprop in CNN's better than my professors. A true gem.

  • @guyco_beats
    @guyco_beats Рік тому +2

    this is definitely one of the better videos on the topic, surprised it doesn't have more views (:

  • @Elonimous
    @Elonimous 6 місяців тому

    This video is amazing, It really helped me understand the math behind CNNs - thank you!

  • @mr.anderson5077
    @mr.anderson5077 2 роки тому +1

    GREATEST LECTURE EVER ON CORE DEEP LEARNING.... THANK YOU MATE

  • @methsiri123
    @methsiri123 19 днів тому

    One of the best tutorial I have gone through. Thank you so much.

  • @jamespogg
    @jamespogg 2 роки тому

    I dont know if its the music but this video is incredibly calming, thanks for this!

  • @mohammadhomsee8640
    @mohammadhomsee8640 2 роки тому

    It's really the best explanation I have ever seen about convolution neural network
    Thank you pro.

  • @inconnuinconnu3105
    @inconnuinconnu3105 6 місяців тому

    Thank you so much for those tutorials. They are really clear and well explained. Pls do that in every domain you know, even if its plumbery

  • @splash_frack0275
    @splash_frack0275 2 роки тому

    I've been reading about CNN and image recognition for a while to make my own one for my project idea, but never thought or found something that brought me light into how to implement a CNN, because I want to do it from scratch, with the maths and all staff.
    You have thought me a lot on 33min of video, now I know how I can make my own CNN, and also that I need to go over derivatives UwU
    Thanks a lot!!!

    • @independentcode
      @independentcode  2 роки тому +1

      Thank you for the kind message, I'm really glad if it helped :)

  • @marvinmartin1373
    @marvinmartin1373 3 роки тому

    Another piece of art! Thank you

  • @tridunghuynh5573
    @tridunghuynh5573 2 роки тому

    Thank you for your time and effort, this is the best so far for me

  • @bob-ym3gk
    @bob-ym3gk Рік тому +1

    Great thanks!This is the clearest video about CNN's on the whole internet!😀

  • @denismerigold486
    @denismerigold486 2 роки тому +11

    Your lessons are works of art!!!

  • @jacobjonm0511
    @jacobjonm0511 2 роки тому +1

    Finally, a tutorial where I got to know how the 3-channel RGB is being mapped mathematically into features. It is surprising to watch so many tutorials and none mentioned that for every channel there is a corresponding kernel and the summation of the convolutions was used to get the result for the next step. They all show h*w*3 and then a single 3*3 kernel. Example this video: C4W1L08 Simple Convolutional Network Example

  • @fuat7775
    @fuat7775 Рік тому

    Thank you for explaining very clearly!

  • @talibdaryabi9434
    @talibdaryabi9434 Рік тому

    The best-ever tutorial. thank you.

  • @VimalKumar-oy4uw
    @VimalKumar-oy4uw 7 місяців тому

    Man , I am mind blown by your content . Such a great video 👌

  • @shantanunath7927
    @shantanunath7927 2 роки тому +1

    It is really help me to understand the whole concept of Convolutional Network. Especially the backpropagation. Please make some video on RNN, LSTN. Thank you.

  • @Bapll
    @Bapll 2 місяці тому

    Thanks for making this. You're really good at doing what you do.

  • @swapnilmasurekar5431
    @swapnilmasurekar5431 2 роки тому +1

    One of the best explanations for CNN on internet! Your channel would be Big in future.

  • @yaaryany
    @yaaryany 8 місяців тому

    Thanks a lot for this video. Couldn't be more grateful!

  • @psychedeliccoffee2737
    @psychedeliccoffee2737 Рік тому

    This is amazing man. Very informative!

  • @Misscrazy3957
    @Misscrazy3957 3 роки тому +4

    Perfect Perfect i like this channel. Bravo, i found what i was looking for. Really thank you Sir.💚

  • @user-su4jh4sp9b
    @user-su4jh4sp9b 2 роки тому

    Thank you so much of those two excellent videos !!!

  • @easyBob100
    @easyBob100 2 роки тому +10

    Your "from scratch" videos are great! I was able to convert them into c++/cuda neural net classes and they work better than my old code. Thank you!
    Also, is there any way you can do one for an "Unconvolutional" layer? I would love to mess around with different types of autoencoders for images. :)

    • @VincentKun
      @VincentKun Рік тому

      Deconvolution is just a convolution, you just pick your convolved image, and use a bigger filter and add some padding.

  • @bradleyadjileye1202
    @bradleyadjileye1202 7 місяців тому +1

    thank you very much for this masterclass

  • @WasimAbdul_1994
    @WasimAbdul_1994 Рік тому

    best video on Convolutional layer. Good job!

  • @pitiwatkittiwimonchai4656
    @pitiwatkittiwimonchai4656 2 роки тому

    Great sir !! i find about backward kernel so long time thank you

  • @ThePiotrusZ
    @ThePiotrusZ Рік тому

    Great video - first I saw that really shows how to thing about implementation

  • @jordanbuwa
    @jordanbuwa Рік тому

    This in a very good tutorial to learn about CNN. Thank you so much.

  • @xiangqi_in_russia
    @xiangqi_in_russia 3 місяці тому

    3b1b video format & amazing calming voice
    OMG, you are a treasure

  • @ekopurnomo9221
    @ekopurnomo9221 9 місяців тому

    awsome, thank you for the tutorial it really help me out to understand about cnn with easily

  • @robehickmann
    @robehickmann Рік тому

    This is amazing work, thank you so much :)

  • @erron7682
    @erron7682 2 роки тому +4

    Thanks a lot!

  • @louisdasselaar7806
    @louisdasselaar7806 Рік тому

    very high quality video and amazing explanation!

  • @gemuruhpratama8100
    @gemuruhpratama8100 Рік тому

    Exceptional explanation, thank you for sharing this.

  • @quantumsoul3495
    @quantumsoul3495 Рік тому

    You could implement the hypermatrix operation you talked about in the beginning of the video in order to simplify the forward and backward functions of the Convolutional layer, removing all the loops

  • @Murraythis
    @Murraythis 2 роки тому

    Incredible video!

  • @shivangitomar5557
    @shivangitomar5557 Рік тому

    BEST video! Thanks a ton!

  • @jvnganesh4943
    @jvnganesh4943 24 дні тому

    really found this video very interesting and informative . I really appreciate it a lot. Thanks!

  • @thelivingarc5838
    @thelivingarc5838 2 роки тому

    Best ever video on CNN, hats off!

  • @user-bx7xh3wy1b
    @user-bx7xh3wy1b 6 місяців тому

    wonderful, fantastic, thanks a million

  • @mohammed_amine_7173
    @mohammed_amine_7173 4 місяці тому

    Just amazing work ❤

  • @gleasons64
    @gleasons64 2 роки тому

    Excelent Video!!! Thanks for inspiration.

  • @yubrajsharmadhakal6446
    @yubrajsharmadhakal6446 2 роки тому +1

    Great video! helped me a lot!!!

  • @chrissass3178
    @chrissass3178 Рік тому

    Great explanations! For completeness, it would have been nice to include an implementation of pooling layers, but those are quite easy in comparison to convolutional layers. And they might destroy too much information in the small 28x28 images from MNIST.

  • @b.v.r.r.jayasinghe415
    @b.v.r.r.jayasinghe415 10 місяців тому

    Best Explanation... lv ur teaching style and animations

  • @hossamel2006
    @hossamel2006 7 місяців тому +2

    Numpy needs to add this operation and give it a name for real 8:46
    Edit: Ammmazing video btw!!

  • @pkurian1211
    @pkurian1211 3 роки тому

    woow amazing explanation..thank you!

  • @ashwithchandra2622
    @ashwithchandra2622 Рік тому

    excellent video on CNN ever thanks buddy. Do more videos like this!!

  • @roha12
    @roha12 2 роки тому

    interesting and well organized demo!!!!

  • @ali-ates
    @ali-ates Рік тому

    heavy logical equations like poetry, the only channel I activate the bell :D thanks for all.

  • @ohgay_
    @ohgay_ Рік тому +1

    Great explanation! it has really helped my wary mind but I want to point out that it is a bit tricky what depth signifies in the forward propagation explanation. Depth is used to represent the number of input matrices and the number of filter kernels, so it would be nice to present a clear distinction. Thanks for the video

  • @babakshiri7270
    @babakshiri7270 2 місяці тому

    Thanks, This vidio was perfect also had some beauty of mathematics

  • @daniillyakhov5901
    @daniillyakhov5901 2 роки тому

    LOVE IT!!!

  • @simssim262
    @simssim262 3 роки тому

    Your videos are amazing 🙃❤

  • @Rohit-fr2ky
    @Rohit-fr2ky Рік тому +9

    Wow your content is super awesome,
    it would be super cool if you would also code RNN, LSTM, GRU and all that.. 🙂

  • @debanjandas1378
    @debanjandas1378 2 роки тому +1

    Your animation reminded me of 3Blue1Brown videos. Awesome stuffs! :)
    Thanks for sharing!

    • @independentcode
      @independentcode  2 роки тому +1

      It's because I'm using his library :)
      github.com/3b1b/manim

  • @ss_sk06
    @ss_sk06 9 місяців тому

    I have started my AI journey a month back and I have lots of confusion as how these CNN are getting parameters and how is it passing through layers and why reshaping and many more queries. I give full star to clear all the doubts on this video. This is saviour for me in my AI journey.

  • @itsarupjana
    @itsarupjana 2 роки тому

    Really a great video ❤️❤️ I also liked the neural network video very much bcz it cleared all my doubts and I was really amazed to see how we can easily implement a network by building each layer in the internet there are many implementations but this one is the best and easiest one and this CNN is the most amazing video bcz I haven't found any article where CNN is explained in such depth it was a great video🔥🔥🔥animations are also really helpful specially its 3b1b style is one thing i liked very much. I have a request that you should also make a video on RNN bcz after watching this video I think there are many deep understanding in RNN which I don:t know and also the implementation will be really helpful.

  • @arnetriesyoutube
    @arnetriesyoutube 11 місяців тому

    I had so many aha moments here! this is awesome

  • @davidorr947
    @davidorr947 2 роки тому

    Excellent!

  • @ramamunireddyyanamala973
    @ramamunireddyyanamala973 2 роки тому

    Perfect Perfect i like this channel. Bravo, i found what i was looking for. Really thank you Sir

  • @qalabeabbas6114
    @qalabeabbas6114 2 роки тому

    Thank you for this! great explaination.
    I will request you to do "Attention" next if possible.

  • @user-fv9pb3rf9i
    @user-fv9pb3rf9i Рік тому

    I feel like I don't deserve to get such content for free.. Amazing job!

  • @tradewithdani122
    @tradewithdani122 Рік тому

    Hey, thanks for your knowledge, please share more❤

  • @muze3k
    @muze3k 3 роки тому

    This is extremely in-depth and just what I needed... All the best for future videos..

  • @metanick1837
    @metanick1837 10 місяців тому

    Great Video!

  • @shivu.sonwane4429
    @shivu.sonwane4429 3 роки тому

    Wonderful explaination love from India🇮🇳

  • @user-po7ei3nl5c
    @user-po7ei3nl5c 10 місяців тому

    Thank you so much

  • @serhanciftlikci3651
    @serhanciftlikci3651 2 роки тому +1

    Simply beautiful videos, days of struggling for understanding backprop has just ended. Would you be willing to make a video on transformers?

  • @nihardomala5904
    @nihardomala5904 Рік тому

    It was a great video and the best organised code. Can you also make a video of pooling in extension of this which makes it a complete one

  • @mahmoudnady4388
    @mahmoudnady4388 10 місяців тому

    Fatnastic brother!
    I really apprciate what you are doing
    thanks🎉🎉

  • @gl4606
    @gl4606 2 роки тому

    Best video of its kind. Please do RNN's!

  • @tangomuzi
    @tangomuzi 3 роки тому +2

    Everything well explained, thank you. I think all the code still can be simplified and made faster by using numpy ndarray functionalties. Instead of using all data sets in each epoch just use batches of data so that you can train all set without needing using only two class of data. Using numpy ndarray functions will remove almost all loops and hence your code will be faster.

    • @polyfoxgames9006
      @polyfoxgames9006 2 роки тому

      Your just hiding the loops in the function call

    • @tangomuzi
      @tangomuzi 2 роки тому

      @@polyfoxgames9006 No.Not really. Most of numpy functions are optimized C functions.

    • @michaelpieters1844
      @michaelpieters1844 2 роки тому

      @@polyfoxgames9006 Vectorized Python code can be as fast as C or Julia.

    • @polyfoxgames9006
      @polyfoxgames9006 2 роки тому

      @@michaelpieters1844 no way haha. Pytorch is fast because it is cuda, being called by python

  • @semsettinturkoz6602
    @semsettinturkoz6602 2 роки тому

    please keep posting videos, thanks

  • @codybarton2090
    @codybarton2090 14 днів тому

    Great video