当前位置:网站首页>Use torch NN builds the simplest neural network framework
Use torch NN builds the simplest neural network framework
2022-07-19 08:37:00 【Program black】
As usual , Analyze official documents :
https://pytorch.org/docs/stable/nn.html#containers
Here is the main analysis Container class .
You can see Module Class is the parent class of all neural network modules , therefore , This paper mainly studies Module Usage of .

When we need to create a neural network model , We need to inherit torch.nn.Module class . And call the constructor of the parent class through the constructor .
The constructor of the parent class sets the trained flag The value is True.
among CONV2D It is a two-dimensional convolution algorithm , Mainly used in image operation . about CONV2D Algorithm , Share a blog here , It's very detailed :https://blog.csdn.net/qq_34107425/article/details/104117670

and forwards Used in CONV1D It is a one-dimensional convolution operation . about rule function , Its official description is :

———— The picture quotation knows itself .
Generally speaking , One dimensional convolution nn.Conv1d For text data , Only the width is convoluted , It is not necessary to adjust the height .
Conv1d For data only height perhaps weight To deal with , I personally understand that ,Conv1D It deals with linear data , That is to say tensor Low latitude data in tensor field .
And for RELU function , It means nonlinear transformation .
relu The function is to increase the nonlinear relationship between the layers of the neural network , otherwise , If there is no activation function , There is a simple linear relationship between layers , Each layer is equivalent to matrix multiplication , In this way, how can we complete the complex tasks we need neural network to complete .
This is a nonlinear transformation .
When the operation and transformation of functions are not nonlinear , Then there is the possibility of intellectualization , Otherwise, the execution process of the program is in accordance with the system regulations , There is no nonlinear change .
Neural network is equivalent to a processing module , An output is obtained by convolution and nonlinear transformation of the input data , As a result of intelligent processing .
Given in the official presentation document forwards The function shows that the function of this neural network is to carry out once 1 The convolution of dimensions is followed by nonlinear transformation , And repeat the operation once .
Here is a simple neural network skeleton
from torch import nn
import torch
class network(nn.Module):
def __init__(self):
super().__init__()
def forward(self,input):
output = input + 1
return output
net = network()
x = torch.tensor(1.0)
output = net(x)
print(output)
among init Method calls the constructor of the parent class ,forwards The method is to do a right input The data is processed once +1 The operation of , The operation here is linear transformation , But he is still the skeleton of a neural network .
边栏推荐
猜你喜欢

Redis6 new data type geospatial

60. Initial knowledge of wsgiref handwritten web framework +jinja2 module

STM32CUBEIDE(9)----USART通过DMA收发

深度学习第四周Key Concepts on Deep Neural Networks习题整理

46. IO model

1. Flask Foundation

OpenCV极坐标转换函数warpPolar的使用

6-9 vulnerability exploitation telnet login rights lifting

Redis常用数据类型——Redis列表(List)和Redis 集合(Set)

5G正当时,无人驾驶未来将驶向何方?
随机推荐
Can seaport and erc-4907 become new ways to release NFT liquidity| Tokenview
石墨厚度测量
Li Kou 1669 merges two linked list notes
Filesourcestrategy, datasourcestrategy and datasourcev2strategy in spark
凭借左程云(左神)的这份 “程序员代码面试指南”我入职了字节
oop_ Reference type variable transfer value
Redis6 new data type geospatial
最新一代互联网:WEB 3.0
1. Flask Foundation
微服务与微服务架构
Super dry! Thoroughly understand golang memory management and garbage collection
Dark horse programmer - software testing -16 stage 3 - function testing -175-198, URL composition introduction, request content and composition description line function test and database, URL composi
Application of SCA on devsecops platform
深度学习之线性回归+基础优化
JS学习笔记01-03——this的引用,全局作用域,方法
openpyxl跨工作簿复制sheet页
5g at that time, where will driverless driving go in the future?
使用toruch.nn搭建最简单的神经网络骨架
Stm32subeide (9) -- USART sends and receives via DMA
JS学习笔记04-05——构造函数的修改以及使用工厂方法创建