Flatten, Reshape, and Squeeze Explained - Tensors for Deep Learning with PyTorch

Поділитися
Вставка
  • Опубліковано 14 жов 2024

КОМЕНТАРІ • 115

  • @deeplizard
    @deeplizard  6 років тому +9

    Check out the corresponding blog and other resources for this video at: deeplizard.com/learn/video/fCVuiW9AFzY

    • @reb5642
      @reb5642 5 років тому

      thank you so much

  • @prakhardixit2597
    @prakhardixit2597 5 років тому +10

    thanks deeplizard for making pytorch so easy to understand , an excellent series!!!

    • @deeplizard
      @deeplizard  5 років тому +3

      Hey Prakhar - You are welcome!

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

    Gratulations on your 100.000 followers here! :)

  • @philtrem
    @philtrem 5 років тому +43

    def flatten(t):
    return t.reshape(-1)

  • @sethatkins3731
    @sethatkins3731 5 років тому +6

    This was very helpful. I came here looking for what the squeeze operation does. Was happy to find answers to some other questions in the back of my mind. (what does the -1 mean in resize operations) I will say though, that sometimes the visuals can be a little distracting. (Mainly the pancake one. I was having a hard time listening to what you were saying.) Other than that, this was very helpful. I might watch more of your videos in the future!

  • @luis.barragan
    @luis.barragan 5 років тому +2

    When you're writing code, it sounds in the background like airplane cabin white sound and it's relaxing. Nice tutorial! I'm a PyTorch Scholar and since the resources in Udacity aren't good enough for me, I'm watching your very helpful tutorials. Thanks.

    • @deeplizard
      @deeplizard  5 років тому +1

      Hey Felipe - You are welcome! Definitely appreciate your feedback. It helps a lot to hear weather subtle things make a difference. 🙏

    • @DivyaThakur
      @DivyaThakur 5 років тому +1

      @@deeplizard I'm a Pytorch Scholar too! And share the same feelings as Felipe. Thanks a ton deeplizard :)

  • @philtrem
    @philtrem 5 років тому +4

    Really love the analogy ! And I'm really enjoying the course so far.

  • @AIRoboticsCreator
    @AIRoboticsCreator 5 років тому +1

    Great video! I’m halfway thru the playlist!

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

    best work u guys are doing, lot of hard work u both did ,to get this knowledge , love from India

  • @SaiKrishna-tr1dz
    @SaiKrishna-tr1dz 5 років тому +2

    awesome content and the way you deliver hats off!

  • @hosseinaboutalebi9998
    @hosseinaboutalebi9998 5 років тому +2

    Great videos. Best content. Nice animations.
    The fact that you make your videos like a meme is exceptional and make watching them enjoyable.
    Keep up the good work! I am your fan :)

  • @amaytrivedi
    @amaytrivedi 5 років тому +1

    Hi there ,
    i followed your tutorials and they seem great!!
    I implemented in the following manner (Squeeze function in reshape)
    def flatten_by_reshaping():
    rdata = data.reshape(1,-1)
    rd = rdata.reshape(rdata.shape[1] , )
    return rd
    print(flatten_by_reshaping() , len(flatten_by_reshaping()))

    • @deeplizard
      @deeplizard  5 років тому +1

      Make sure you add the "data" parameter to the function signature.

  • @thak456
    @thak456 4 роки тому +1

    @deeplizard thank you very much for this video and the full playlist. Can you make a series on NLP with Pytorch ?

    • @deeplizard
      @deeplizard  4 роки тому

      Currently working out the details about which direction we'll go in terms of content. Thank you for the suggestion.

  • @Aditya-ne4lk
    @Aditya-ne4lk 4 роки тому +25

    i was waiting for the pancakes to be squished 'flat'...

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

      Haha! 🤣

    • @salvindsouza7053
      @salvindsouza7053 4 роки тому

      same here , hahahaha

    • @utkar1
      @utkar1 4 роки тому

      me too .. lol

    • @13RedCorpse
      @13RedCorpse 4 роки тому

      I couldn't concentrate on what he was talking about, I was thinking about how delicious these pancakes look. I guess I should go get something to eat before I continue.

  • @Sikuq
    @Sikuq 4 роки тому +1

    Very good.

  • @M0481
    @M0481 6 років тому +9

    I haven’t installed PyTorch yet, but assuming that it works the same as a list, would the answer be: reshape(1,-1)[0]?

    • @deeplizard
      @deeplizard  6 років тому +7

      Hey Mick - Nice! I didn't think of this one. It works!

    • @roros2512
      @roros2512 5 років тому +2

      I did the same and it worked =B

    • @philtrem
      @philtrem 5 років тому +2

      It works but it wouldn't be the most straightforward approach. But it's good you came up with this, the more ways the merrier.

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

      t.reshape(t.numel()) or t.reshape(-1)

  • @kafaayari
    @kafaayari 4 роки тому +1

    What's your keyboard? loved the sound too much!

  • @aamirmustafa7731
    @aamirmustafa7731 6 років тому +25

    t=t.reshape(-1)

    • @TerragonDE
      @TerragonDE 6 років тому +2

      @Phil Ad why?

    • @gabrielemazzola9652
      @gabrielemazzola9652 5 років тому +5

      @Phil Ad I am flattened by it.

    • @MohammedNoureldin
      @MohammedNoureldin 4 роки тому

      Please explain how does this work.

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

      @@MohammedNoureldin a little late answer but 7:06 basically tells it.
      I think reshape() determines the number of individual elements in the tensor and reshapes it as one axis with 12 elements in it. Sorry if i'm wrong.

  • @DanielWeikert
    @DanielWeikert 6 років тому +1

    Thanks a lot! Great video

    • @deeplizard
      @deeplizard  6 років тому

      Hey Daniel - You are welcome!

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

    6:00 why you are showing food, I am hungry 😅. But it look like delicious :)

  • @narroric
    @narroric 5 років тому +3

    I don't know what the low rumbling sound is, but it is ridiculously soothing. Like doing coding on a star trek starship.

  • @robosergTV
    @robosergTV 6 років тому +4

    link for the ted talk? Come on, its expected to have a link.

    • @deeplizard
      @deeplizard  6 років тому +2

      Agree. Added to the description. Link: ua-cam.com/video/aR5N2Jl8k14/v-deo.html

  • @srikarvalluri8173
    @srikarvalluri8173 5 років тому +4

    def flatten(t):
    t = t.reshape(1, t.size()[0] * t.size()[1])
    t = t.squeeze()
    return t
    I know this is terribly ineffective but it's something different then all the other ones out there. ;)

    • @deeplizard
      @deeplizard  5 років тому +1

      I like it. It's good practice for us to see different approaches and be able to reason about their validity. Thanks for adding it.

    • @deeplizard
      @deeplizard  5 років тому

      Created a couple of quiz questions that use your example:
      deeplizard.com/learn/video/fCVuiW9AFzY

  • @Normalizing-polyamory
    @Normalizing-polyamory 5 років тому +7

    def flatten(t):
    numel = t.numel()
    return t.reshape(numel)

    • @deeplizard
      @deeplizard  5 років тому +1

      Hey Erik - I like. 🚀

  • @philtrem
    @philtrem 5 років тому +2

    When you have a sentence like this: "The primary ingredient we use to produce our product, a function that maps inputs to correct outputs, is data.", it's better to write it as: "The primary ingredient we use to produce our product - a function that maps inputs to correct outputs - is data." (ie. using dashes instead of commas). Otherwise it's confusing and difficult to make out that it's a 'parenthetical statement'.

    • @deeplizard
      @deeplizard  5 років тому +1

      Hey Philippe - I like your point here. The sentence is a bit hard to interpret. I'll keep this in mind going forward. Appreciate your input!

  • @TerragonDE
    @TerragonDE 6 років тому +1

    If you only reshape there is a bracket inside the bracket so that it is not a real one Dimensional Tensor but it stays the two-dimensional Tensor that has only the first Zero Index filled?

    • @deeplizard
      @deeplizard  6 років тому +1

      Hey Terragon - You are correct! 🚀

    • @TerragonDE
      @TerragonDE 6 років тому +1

      Thanks to your great tutorial series with best style of explanation i found on the web! cant wait for the next episodes ;-)

  • @heller4196
    @heller4196 5 років тому +12

    5:45 why you distracting me with food !

  • @Akiiii009
    @Akiiii009 5 років тому +1

    Why not to use directly t.flatten() instead of t.reshape(-1) OR t.reshape(1,-1).squeeze() ?

    • @deeplizard
      @deeplizard  5 років тому

      Hey Akash - It's good to use flatten directly. The method also comes with the start_dim parameter. It is important to understand that flatten is a special case of the more general idea of reshaping. The presentation here was meant to explore the various concepts.

    • @Akiiii009
      @Akiiii009 5 років тому +1

      @@deeplizard Okay got it, thanks

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

    Answer for flattening with reshaping : t.reshape([-1])

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

    The other way to flatten the tensor is by using t = t.reshape( -1 ) in flatten(t) function

  • @Livakivi
    @Livakivi 6 років тому +1

    t.view(t.numel())
    or
    t.view(-1)

    • @deeplizard
      @deeplizard  6 років тому +2

      Hey Ulm - Nice! I didn't think of passing t.numel(). Passing -1 was on my mind though. :)
      Also, thanks for introducing the view() alternative. I didn't mention it in the video, but I did include it in the blog post.

    • @Livakivi
      @Livakivi 6 років тому +2

      Keep up the great work! :)

  • @robosergTV
    @robosergTV 6 років тому +1

    ted talk www.ted.com/talks/maurice_conti_the_incredible_inventions_of_intuitive_ai?language=en

  • @mohammadsadilkhan1875
    @mohammadsadilkhan1875 5 років тому +1

    What to do if I want to append a tensor with another tensor?

    • @deeplizard
      @deeplizard  5 років тому

      We have cat and stack options. See this one: deeplizard.com/learn/video/kF2AlpykJGY

  • @golangshorts
    @golangshorts 5 років тому +2

    t.reshape(-1)
    or
    t.reshape(t.numel())

    • @golangshorts
      @golangshorts 5 років тому +1

      your tutorials really worth than the paid courses. Huge thanks from my heart.

    • @deeplizard
      @deeplizard  5 років тому

      Thank you! Glad these videos are helpful. You are welcome!

  • @3bdo3id
    @3bdo3id Рік тому

    t.reshape(12) or t.reshape(-1)

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

    t.reshape(t.numel()) or t.reshape(tensor(t.shape).prod().... Either of these should work

  • @tomgt428
    @tomgt428 4 роки тому +1

    cool

  • @tallwaters9708
    @tallwaters9708 5 років тому +2

    OMG I wish people wouldn't use "rank" in this way. Rank refers to the number of linearly independant columns in a matrix...

    • @deeplizard
      @deeplizard  5 років тому

      Do you have a typo?

    • @tallwaters9708
      @tallwaters9708 5 років тому +2

      @@deeplizard Yes! Thanks, corrected :) It is strange that they'd pick that word 'rank' though, pretty confusing in my opinion. Nevertheless, great videos!

  • @Makwayne
    @Makwayne 5 років тому +2

    you made me hungry around the 6th minute

  • @EunYeoWoo
    @EunYeoWoo 5 років тому

    t = t.reshape(12) works fine but the other ppl's t = t.reshape(-1) seems way more elegant

    • @deeplizard
      @deeplizard  5 років тому

      Thanks MinJoong! Yes. Agree.

  • @keyurparalkar9535
    @keyurparalkar9535 5 років тому

    t.reshape(3,4)

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

    Oof, i think the bing chat can take that picture and be able to tell that the bridge is dangerous to cross right now meaning the future is now🎉

  • @utkar1
    @utkar1 4 роки тому

    t.reshape(12)
    t.reshape(-1)

  • @DeltaSleepy
    @DeltaSleepy 5 років тому +2

    eazy peezy...
    t.reshape(-1)

  • @themelankolis1922
    @themelankolis1922 4 роки тому

    Nice tutorial! It would be really great if you change the backsound while you write the code. Because it is not that comfortable to hear, especially when you hear with earphone.

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

    t.reshape(1,-1)[0], better late than never :p

  • @manuelbevilacqua2490
    @manuelbevilacqua2490 6 років тому +1

    numel = t.numel()
    nt = t.reshape(numel)

  • @prabhatale1135
    @prabhatale1135 4 роки тому

    def flatten():
    return t.reshape(-1)

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

    my answer (t.reshape(-1)). Without looking, I swear

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

    t = t.reshape(12)

  • @akshooter_5010
    @akshooter_5010 4 роки тому

    print(t.reshape(t.numel()))

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

    t.reshape(-1)

  • @GeNiaaz
    @GeNiaaz 4 роки тому

    I'm sorry, zucchini on a pizza ????

  • @believeit5450
    @believeit5450 5 років тому +1

    Thanks the video for the t.reshape(1,-1) is It this the same explanation for numpy using reshape ?
    By Julu Ahamed : stackoverflow.com/questions/18691084/what-does-1-mean-in-numpy-reshape

    • @deeplizard
      @deeplizard  5 років тому +1

      You are welcome! Yes. That's right.

  • @janmichaelbesinga3867
    @janmichaelbesinga3867 4 роки тому

    t.reshape(12)

  • @acidtears
    @acidtears 4 роки тому

    Great series but wow that sped up keyboard typing makes it very annoying to go back and go through the video again. Not sure if silence would be any better but it sounds like a rat on amphetamines.

  • @ca7ax_xinyu
    @ca7ax_xinyu 4 роки тому

    t = t.reshape(t.numel()) :)

  • @baqerghezi1342
    @baqerghezi1342 4 роки тому

    reshape(-1,)

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

    r.reshape(1,torch.tensor(r.shape).prod()).squeeze() for a tensor r

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

    Now do scatter()

  • @nikosmparoutis221
    @nikosmparoutis221 5 років тому

    i do not like the comment and the tone "Bakers flat to make goods instead we do it to make intelligence". The snobbish tone of programmers who think they know it all but they are scared because they do not. The analogy is good the way it is said is not

  • @CoolDude911
    @CoolDude911 5 років тому +1

    t.reshape(t.numel())

  • @muthukamalan.m6316
    @muthukamalan.m6316 Рік тому +1

    t.flattern() makes my life simpler😅😂

  • @deeplizard
    @deeplizard  6 років тому +1

    Check out the corresponding blog and other resources for this video at: deeplizard.com/learn/video/fCVuiW9AFzY

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

    def flatten(t):
    return t.reshape(-1)

  • @jorgec7028
    @jorgec7028 5 років тому +1

    t=t.reshape(-1)

  • @Muhammad_Al-Barham
    @Muhammad_Al-Barham 3 роки тому

    t.reshape(-1)

  • @yuntaozhang666
    @yuntaozhang666 4 роки тому

    t.reshape(-1)