Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the structure of PyTorch?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

What is the structure of PyTorch? I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

The structure of modules commonly used in PyTorch is as follows:

1. Torchvision package:

① datasets:datasets contains commonly used datasets, such as MNIST,CIFA, etc.

② models:models contains some classic trained models, such as VGG16,VGG19, ResNet and so on. These models are mainly used for transfer learning. About transfer learning, we will introduce it in the following chapters.

③ transforms: converts the contents of the dataset into tensor.

2. The torch package mainly consists of four pieces:

① autograd package. There is a Variable that defines the PyTorch variable.

② nn (neural network) package. Nn package contains the most abundant content: loss function (MSELoss, crossEntropyLoss, etc.), functional (generally expressed by F, including various activation functions, pooling correlation functions, regularization correlation functions, etc.), network layer functions (linear layer / full connection layer Linear, convolution function Conv2d, etc.). It is important to note that convolution and pooling are used together, but in different packages. The reason is that PyTorch puts all the contents that need training parameters on the network layer, and puts all the tool functions that do not need training parameters into functional. The parameters w, b and convolution of the neural network are all in the network layer, and we need to train these parameters. Whether it is the activation function, or pooling (the size and step size of the pooled convolution kernel can be calculated), dropout and so on can have no parameters. The nn package also has a Module module that contains methods such as parameters (), train (), and eval (). The parameters () method can directly get all the parameters to be trained. These parameters must be specified with self.conv1,self.fc1 and so on in _ _ init__ (). If dropout is used in the neural network model, some neurons will be discarded randomly during training, so the neural network will be specified by train () method during training. Correspondingly, if it is the prediction of the trained neural network, the eval () method should be used to specify the neural network for testing. The most amazing thing is the forward () method, the forward propagation of the model must call forward (), or even can be called directly without the name forward, such as: model (input). The process of back propagation is actually the reverse derivation of the function in the forward () method.

③ optim package. There are gradient drop related functions, such as SGD, Adam and so on. Momentum is included in the SGD as a parameter. There are also functions such as gradient zeroing (zero_grad), primary optimization (step) and so on.

There are many ways to handle tensor under the ④ torch module.

According to the above, we can at least achieve fully connected neural networks, convolutional neural networks and transfer learning. Are we looking forward to achieving these functions? Let's start with the basic data types and basic operations of PyTorch.

After reading the above, have you mastered the structure of PyTorch? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report