当前位置:网站首页>Basic skeleton of neural network nn Use of moudle
Basic skeleton of neural network nn Use of moudle
2022-07-01 04:45:00 【booze-J】
article
Module yes Contains The most commonly used modules in ,Contains It is used to build neural network architecture .
Contains Official documents
The basic skeleton of neural network -nn.Moudle Use official documents of
According to the example of official documents :
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 20, 5)
self.conv2 = nn.Conv2d(20, 20, 5)
def forward(self, x):
x = F.relu(self.conv1(x))
return F.relu(self.conv2(x))
step : Use the basic skeleton of neural network -nn.Moudle, It can be divided into three steps .
- Create a class inheritance nn.Module
- Inherit nn.Module The initialization of plus their own initialization
- rewrite forword Method
Explanation of the code in this part of the official document :
def forward(self, x):
x = F.relu(self.conv1(x))
return F.relu(self.conv2(x))

Look at the picture , Very vivid .
nn.Moudle Examples of use :
import torch
from torch import nn
# Create a class inheritance nn.Module
class Tudui(nn.Module):
# Inherit nn.Module The initialization
def __init__(self):
super().__init__()
# rewrite forword Method
def forward(self,input):
output = input+1
return output
# Create a class object
obj = Tudui()
x = torch.tensor(1.0)
# Pass parameters into the class object and receive the results
output = obj(x)
# Output results
print(output)
Code run results :
边栏推荐
- JS rotation chart
- Matters behind the construction of paint testing laboratory
- Section 27 remote access virtual private network workflow and experimental demonstration
- Pytest automated testing - compare robotframework framework
- 【FTP】FTP常用命令,持续更新中……
- STM32 光敏电阻传感器&两路AD采集
- 【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
- Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
- STM32 extended key scan
- Seven crimes of counting software R & D Efficiency
猜你喜欢

How to do the performance pressure test of "Health Code"

Grey correlation cases and codes

常用的Transforms中的方法

【硬十宝典】——1.【基础知识】电源的分类

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling

Dual contractual learning: text classification via label aware data augmentation reading notes

The longest increasing subsequence and its optimal solution, total animal weight problem

About the transmission pipeline of stage in spark

神经网络-卷积层

数据加载及预处理
随机推荐
C language games (I) -- guessing games
2022 question bank and answers for safety production management personnel of hazardous chemical production units
Leecode question brushing record 1332 delete palindrome subsequence
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
【FTP】FTP常用命令,持续更新中……
Kodori tree board
Section 27 remote access virtual private network workflow and experimental demonstration
RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead
Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
Ten wastes of software research and development: the other side of research and development efficiency
软件研发的十大浪费:研发效能的另一面
STM32 光敏电阻传感器&两路AD采集
测量三相永磁同步电机的交轴直轴电感
2022 polymerization process test questions and simulation test
CF1638E. Colorful operations Kodori tree + differential tree array
总结全了,低代码还需要解决这4点问题
Daily question - line 10
Dede collection plug-in does not need to write rules
如何看待智慧城市建设中的改变和机遇?