当前位置:网站首页>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 :
边栏推荐
- Applications and features of VR online exhibition
- C#读写应用程序配置文件App.exe.config,并在界面上显示
- Shell之一键自动部署Redis任意版本
- Day 52 - tree problem
- LeetCode_58(最后一个单词的长度)
- Introduction to JVM stack and heap
- STM32扩展板 温度传感器和温湿度传感器的使用
- One click shell to automatically deploy any version of redis
- 2022年上海市安全员C证考试题模拟考试题库及答案
- CUDA development and debugging tool
猜你喜欢

Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and

神经网络-卷积层

Odeint et GPU

2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

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

TCP server communication flow

最长递增子序列及最优解、动物总重量问题
![[godot] unity's animator is different from Godot's animplayer](/img/51/48f40a7b6736d7f78040eabbbd3395.jpg)
[godot] unity's animator is different from Godot's animplayer

Grey correlation cases and codes
随机推荐
One click shell to automatically deploy any version of redis
How to use maixll dock
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
LeetCode_66(加一)
总结全了,低代码还需要解决这4点问题
Shell之分析服务器日志命令集锦
Openresty rewrites the location of 302
This sideline workload is small, 10-15k, free unlimited massage
Common UNIX Operation and maintenance commands of shell
Day 52 - tree problem
Pytorch(二) —— 激活函数、损失函数及其梯度
STM32 photoresistor sensor & two channel AD acquisition
2022 gas examination question bank and online simulation examination
Thoughts on the construction of Meizhou cell room
RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead
Introduction to JVM stack and heap
CF1638E. Colorful operations Kodori tree + differential tree array
常用的Transforms中的方法
Codeforces Round #771 (Div. 2) ABCD|E
Research on medical knowledge atlas question answering system (I)