pytorch framework learning (4) torchvision module & training a simple own CNN (1)

torchvision module


Don't worry about your image, only care about how to achieve your goals. ——Principles, Principles of Life


There is an introduction to torchvision in the Libraries of the English PyTorch document


The practical explanation has the following parts

Data preprocessing part
- data enhancement
- data preprocessing
Network module settings
- load pre-trained model
> model training, saving and testing (in the next article)
- selective saving
- read model and test


There are many functions we need in this (torchvision) module, such as: torchvision.datasets (encapsulates some commonly used datasets and defines data storage methods), torchvision.models (including the implementation of some classic network architectures, and and training model), torchvision.transfrom (data preprocessing module)

For the data types of pure classification tasks, please refer to the ImageFolder module. Official website link
Of course, different tasks, the construction of the data set may be different~~~

insert image description here

1 Data preprocessing

First, we import the required pip package and define the path of the dataset we want to use.
Then we perform dataToTensorNormalize.
insert image description here
Next, we build the dataset.
insert image description here
Currently our dataset is full of 1, 2, 3 In this way, we can read the json file to match the number with the name
insert image description here

Data Display

  • Note: If we want to display the data here, the data that has been converted to temsor format must be restored to numpy format, and the standardization needs to be restored
  • The transpose operation is to restore C * H * W to H * W * C
  • The role of squeeze is to reduce dimensionality. For details, please refer to other blogs

2 Network model settings

insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/vibration_xu/article/details/126157110