当前位置:网站首页>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 :
边栏推荐
- Quelques outils dont les chiens scientifiques pourraient avoir besoin
- Codeforces Round #771 (Div. 2) ABCD|E
- Leecode question brushing record 1332 delete palindrome subsequence
- 手动实现一个简单的栈
- MySQL winter vacation self-study 2022 12 (5)
- 【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
- 细数软件研发效能的七宗罪
- C -- array
- C#读写应用程序配置文件App.exe.config,并在界面上显示
- Introduction to JVM stack and heap
猜你喜欢

Extension fragment

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

Maixll dock quick start

LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver

Ten wastes of software research and development: the other side of research and development efficiency
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

2022年T电梯修理题库及模拟考试

CF1638E. Colorful operations Kodori tree + differential tree array

Pytorch(一) —— 基本语法

2022年上海市安全员C证考试题模拟考试题库及答案
随机推荐
STM32扩展板 数码管显示
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
LeetCode_58(最后一个单词的长度)
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
Difficulties in the development of knowledge map & the importance of building industry knowledge map
How to do the performance pressure test of "Health Code"
js解决浮点数相乘精度丢失问题
2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
Ten wastes of software research and development: the other side of research and development efficiency
Leecode question brushing record 1332 delete palindrome subsequence
Shell之分析服务器日志命令集锦
Shell之一键自动部署Redis任意版本
Talk about testdeploy
【硬十宝典】——1.【基础知识】电源的分类
2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
分布式事务-解决方案
2022 t elevator repair question bank and simulation test
Cmake selecting compilers and setting compiler options
VIM简易使用教程