当前位置:网站首页>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 :
边栏推荐
- Shell analysis server log command collection
- VIM简易使用教程
- 分布式全局唯一ID解决方案详解
- Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
- Dual contractual learning: text classification via label aware data augmentation reading notes
- 分布式事务-解决方案
- 先有网络模型的使用及修改
- LeetCode_66(加一)
- Simple implementation of slf4j
- Maixll dock quick start
猜你喜欢

Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling

2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities

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

2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试

测量三相永磁同步电机的交轴直轴电感

Kodori tree board

pytorch 卷积操作

C - detailed explanation of operators and summary of use cases

VR线上展览所具备应用及特色

无器械健身
随机推荐
pytorch 卷积操作
Pytest automated testing - compare robotframework framework
2022 t elevator repair question bank and simulation test
【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead
Pytorch(三) —— 函数优化
2022-02-15 (399. Division evaluation)
PgSQL failed to start after installation
Basic usage, principle and details of session
[ue4] event distribution mechanism of reflective event distributor and active call event mechanism
总结全了,低代码还需要解决这4点问题
VR线上展览所具备应用及特色
Fitness without equipment
2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
The design points of voice dialogue system and the importance of multi round dialogue
LeetCode_53(最大子数组和)
Grey correlation cases and codes
Seven crimes of counting software R & D Efficiency
手动实现一个简单的栈
[FTP] common FTP commands, updating continuously