当前位置:网站首页>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 :
边栏推荐
- 分布式锁的实现
- RuntimeError: “max_pool2d“ not implemented for ‘Long‘
- 神经网络的基本骨架-nn.Moudle的使用
- LeetCode_ 53 (maximum subarray and)
- C language games (I) -- guessing games
- I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
- 分布式全局唯一ID解决方案详解
- OdeInt與GPU
- 2022年煤气考试题库及在线模拟考试
- [ue4] event distribution mechanism of reflective event distributor and active call event mechanism
猜你喜欢
Openresty rewrites the location of 302
pytorch中常用数据集的使用方法
Odeint et GPU
Shell之一键自动部署Redis任意版本
[pat (basic level) practice] - [simple simulation] 1064 friends
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
AssertionError assert I.ndim == 4 and I.shape[1] == 3
I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
随机推荐
细数软件研发效能的七宗罪
C -- array
Day 52 - tree problem
STM32 光敏电阻传感器&两路AD采集
TCP server communication flow
The design points of voice dialogue system and the importance of multi round dialogue
Grey correlation cases and codes
Pytorch(三) —— 函数优化
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
Question bank and answers for chemical automation control instrument operation certificate examination in 2022
2022年化工自动化控制仪表操作证考试题库及答案
Difference between cookie and session
Some tools that research dogs may need
LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
先有网络模型的使用及修改
Maixll dock quick start
分布式锁的实现
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
Leecode records the number of good segmentation of 1525 strings
Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)