(Day 36) Intro to PyTorch

Ivan Ivanov · February 6, 2024

Hello :) Today is Day 36!

A quick summary of today:

Tesla autopilot and ChatGPT apparently use PyTorch, so for some time I have been wanting to see what PyTorch is like. Given that I wanna go deeper into computer vision and self-driving cars, I wanted to “get my hands dirty”.

IBM’s DL with PyTorch

I did IBM’s DL with PyTorch and it was good, but not very practical. It assumes I have no DL knowledge, but it was not that bad, just a refresher on loss, activations, back and forward prop, gradient descent, etc.

PyTorch’s library is something that needs to be defined more directly than TensorFlow. I thought I should apply it to something simple.

PyTorch Project: Handwritten Digit Recognition

I decided to do this tutorial project.

In fact, when I first studied machine learning in the summer of 2023, this person’s channel was very helpful. I love tutorial projects for beginners such as kn, linear regression, logistic regression, and decision tree.

Difference with TensorFlow

image

You have to load data with the DataLoader

image

Explicitly define the model, and each layer. (forward prop)

image

When training, backprop should be defined directly. Also, the model should change to the training state with model.train() (when testing/eval later, model.eval())

image

You have to calculate the loss and express the loss and accuracy in print

Facial Expression Recognition with PyTorch and Deep Learning with PyTorch : Object Localization

Here, I made a model using transfer learning. The second project consisted of a bounding box model of vegetables or apples. The first model was more interesting. These two projects used an already constructed model, and I understood a little more deeply how to do training and validation with Pytorch

The facial expression model used the following data

image

also did data augmentation here (with transforms.Compose)

image

image

image

Must include init and forward functions in model class structure

image

Training:

image

image

If you look at the results, you can see the probability of class of each image

image

Today’s study was interesting, but tomorrow, I’ll make my own Pytorch model with different data!


That is all for today!

See you tomorrow :)

Original post in Korean