当前位置:网站首页>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 :
边栏推荐
- The design points of voice dialogue system and the importance of multi round dialogue
- 扩展-Fragment
- LeetCode_66(加一)
- CUDA development and debugging tool
- This sideline workload is small, 10-15k, free unlimited massage
- STM32扩展板 温度传感器和温湿度传感器的使用
- C language games (I) -- guessing games
- 【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
- Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
- Applications and features of VR online exhibition
猜你喜欢
随机推荐
2022 gas examination question bank and online simulation examination
常用的Transforms中的方法
VIM简易使用教程
Basic exercise of test questions hexadecimal to decimal
Difference between cookie and session
[pat (basic level) practice] - [simple simulation] 1064 friends
The index is invalid
Overview of the construction details of Meizhou veterinary laboratory
LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
pytorch神经网络搭建 模板
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
分布式事务-解决方案
TCP server communication flow
Take a cold bath
Shell analysis server log command collection
Daily question - line 10
Leecode question brushing record 1310 subarray XOR query
pytorch 卷积操作
Leecode question brushing record 1332 delete palindrome subsequence
2022年化工自动化控制仪表操作证考试题库及答案









