Small mound video: P4. Use and comparison of PyCharm and Jupyter_bilibili_bilibili
The pytorch official website explains detailed knowledge points PyTorch documentation — PyTorch 2.0 documentation
1. Detailed knowledge
shift+enter to enter the beginning of the next line
ctrl+P prompts for input parameters
2. Pytorch loads data: dataset and Dataloader
dataset just provides this data set (a deck of playing cards)
The dataloader is equivalent to a hand. Every time you go to the dataset, how do you get the cards? How many cards do you get?
3、Tensorboard
You can use images to show the results of training
4. Transforms transforms images
ToTensor: Convert image to tensor
5. Convolution
in_channels and out_channels are the number of input and output channels
The image input is three-channel RGB, and the colors of the three channels form one image.
batch_size: Indicates the number of data (samples) passed to the program for training at a time . For example, our training set has 1,000 data. This is if we set batch_size=100, then the program will first use the first 100 parameters in the data set, that is, the 1-100th data to train the model. When the training is completed, the weights are updated, and then the 101-200th data are used for training until the tenth time 1000 data in the training set are used.
6. Pooling
dilation: dilated convolution, the convolution kernels are separated from each other
floor and ceil mode: choose the smaller value from the bottom or the larger value from the top, ceil is retained
Use pooling to get the largest value in this block
torch.Resize(20,100,30,30): bitchsize, channels, height, width
7. Nonlinear layer activation function
followed by convolution
8. Linear layer
Expand a 5*5 picture into a row of 25, and then into a row of 3 (the last 3 here is because it is divided into three categories)
In total there are two linear layers
The final output is 10, which means it is classified into 10
9. Loss: Cross-entropy loss function for classification
For example, in a 10-class classification problem, the final output of the neural network is 10 numbers representing the probability value of each category.
Substitute this probability value and target to calculate the loss value
10. Backpropagation
Use backward to calculate the gradient value grad of each parameter W that needs to be adjusted,
11. The optimizer updates based on this gradient.
Define the optimizer and learning rate lr
optim.step for optimization
12. Distinguish
Definition: Softmax regression is a form of logistic regression that normalizes input values into a vector of values that follows a probability distribution that sums to 1