dvgodoy / PyTorchStepByStep

Official repository of my book: "Deep Learning with PyTorch Step-by-Step: A Beginner's Guide"
https://pytorchstepbystep.com
MIT License
866 stars 332 forks source link

Went from "train_step" in helper fn 1, to "step" in helper fn 2? #11

Closed minertom closed 3 years ago

minertom commented 3 years ago

I am missing the place where "step" is used as the returned function to "train_step"

First: train_step = make_train_step(model, loss_fn, optimizer) loss = **train_step**(x_train_tensor, y_train_tensor)

In model_training/v2.py we see mini_batch_loss = **train_step**(x_batch, y_batch)

in helper function #2 we see mini_batch_loss = **step**(x_batch, y_batch)

So far, I have been able to follow the thread of higher level functions. But I missed the above.

Thank You Tom

dvgodoy commented 3 years ago

Hi Tom,

The step function in Helper Function #2 is an argument. It is abstracting the training step function. Since the function can be used with both training and validation steps, it was easier to make the function itself an argument instead of duplicating the code (one for training, one for validation).

You'll see that in model_training/v3.py it calls Helper Function #2 passing train_step as an argument:

for epoch in range(n_epochs):

inner loop

loss = mini_batch(device, train_loader, train_step)
losses.append(loss)

So, when mini_batch is executed there, its step function will be exactly the same train_step function used before.

Does it help?

Best, Daniel

minertom commented 3 years ago

Danial, I see it now. It was a bit tough to spot, because I was not thinking "abstraction".

I am learning a great deal from your step by step approach. I'm not there yet but I am looking forward to the "convolutions" chapter, which is not yet available.

Thank You Tom

On Wed, Dec 2, 2020 at 11:13 AM Daniel Voigt Godoy notifications@github.com wrote:

Hi Tom,

The step function in Helper Function #2 https://github.com/dvgodoy/PyTorchStepByStep/issues/2 is an argument. It is abstracting the training step function. Since the function can be used with both training and validation steps, it was easier to make the function itself an argument instead of duplicating the code (one for training, one for validation).

You'll see that in model_training/v3.py it calls Helper Function #2 https://github.com/dvgodoy/PyTorchStepByStep/issues/2 passing train_step as an argument:

for epoch in range(n_epochs):

inner loop

loss = mini_batch(device, train_loader, train_step) losses.append(loss)

So, when mini_batch is executed there, its step function will be exactly the same train_step function used before.

Does it help?

Best, Daniel

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dvgodoy/PyTorchStepByStep/issues/11#issuecomment-737437879, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADHGGHGQFRVUVZYR7PCVUIDSS2GVRANCNFSM4UKXVTMQ .

minertom commented 3 years ago

Hi Danial, I am eagerly waiting to start the next chapter in the Book, Pytorch step by step. I had not realized, until just now, that you had already published it.

May I ask you a question? I am, if you remember, a senior electronics design engineer who is no longer working at electronics. I have been changing my education emphasis to data science and machine learning.

Aside from the 100 youtube videos describing programs for learning data science, could you, briefly, outline a plan that you would give to someone that is already versed in mathematics (mathematical image processing, convolution and statistics), is learning pytorch, has had some experience with pandas, matplotlib and opencv. What would be your suggestion for a program of study be ?

Thank You Tom Cipollone

On Sat, Dec 12, 2020 at 4:44 AM Daniel Voigt Godoy notifications@github.com wrote:

Closed #11 https://github.com/dvgodoy/PyTorchStepByStep/issues/11.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dvgodoy/PyTorchStepByStep/issues/11#event-4104128666, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADHGGHCS2CZGNMJKU345WMTSUNQUHANCNFSM4UKXVTMQ .

dvgodoy commented 3 years ago

Hi Tom,

Sure! The answer depends on how deep you want to go, though. The way I see, there are three "tracks" one can pursue:

1) going deep into the math, calculus and linear algebra behind each algorithm - I would call that a researcher-inclined track 2) going full hands-on and basically trying stuff out - I would call that a coding-first track 3) something in between - which is my favorite

I've seen many people following 2), but it can only take you so far, because there is generally a fundamental lack of understanding of WHY things are the way they are. Most of the material written on blogs and all follow this approach.

Academics surely follow 1), but I don't like that either, because it goes into details you don't really need in practical applications - assuming you're not trying to invent new algorithms or techniques, or publish a paper.

I developed this course: https://github.com/dvgodoy/ML_Fundamentals to teach my students WHY things work the way they do, without going crazy on the math behind it.

One of the best books for starting learning stuff is this one: https://www.amazon.com/Hands-Machine-Learning-Scikit-Learn-TensorFlow/dp/1491962291 (even if it is Tensorflow :D)

You can also check Fast.AI courses (most of them are here: https://www.fast.ai/) and, for some reason, the ML one is kinda "hidden" now: https://course18.fast.ai/ml.html