[Build Alexnet from scratch] Realize training your own data set

This is a blog in a paid column. If you buy this column, it means that you are not a person who only knows whoring for nothing. I hope you can further communicate and discuss with me, and we will make progress together.


----"Talk is Cheap, Show me the {code.}"
----"Okay ~ the code is at the end"

Training a classification network is nothing more than a few steps:

Brief version:

Step 1: Build datasets and data loader dataloader
Step 2: Build network structure
Step 3: Set optimizer, loss function, and some hyperparameters
Step 4: Perform model training {gradient cleared, from dataloader Take data for forward propagation, calculate loss, backpropagation} and verify {gradient off, take data from dataloader for forward propagation, calculate loss} Step 5: Model saving Step 6: Model loading
and
testing

A slightly more detailed version:

Step 1: Build your own dataset datasets and define your own data loader dataloader.
In more complex networks, we may need to define our own datasets (including data preprocessing, how to match data with labels, rewrite getitem, etc.)
Since Alexnet is relatively simple, we will directly use most classification problems. A data set format: torchvision.datasets.ImageFolder format, this format is to put images of the same category in a folder, and the name of the folder is the name of the image category in the folder.
Then we directly use torch.utils.data.DataLoader to load the data

おすすめ

転載: blog.csdn.net/vibration_xu/article/details/126390858