当前位置:网站首页>神经网络的基本骨架-nn.Moudle的使用
神经网络的基本骨架-nn.Moudle的使用
2022-07-01 04:35:00 【booze-J】
文章
Module是Contains中最常用的模块,Contains是用来构建神经网络架构的。
Contains官方文档
神经网络的基本骨架-nn.Moudle的使用官方文档
根据官方文档的示例:
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))
步骤:使用神经网络的基本骨架-nn.Moudle,主要可以分为三步吧。
- 创建一个类继承nn.Module
- 继承nn.Module的初始化加上自己的初始化
- 重写forword方法
对官方文档这部分代码的解释:
def forward(self, x):
x = F.relu(self.conv1(x))
return F.relu(self.conv2(x))
看图,很形象的。
nn.Moudle使用示例:
import torch
from torch import nn
# 创建一个类继承nn.Module
class Tudui(nn.Module):
# 继承nn.Module的初始化
def __init__(self):
super().__init__()
# 重写forword方法
def forward(self,input):
output = input+1
return output
# 创建一个类对象
obj = Tudui()
x = torch.tensor(1.0)
# 往类对象中传入参数并接收结果
output = obj(x)
# 输出结果
print(output)
代码运行结果:
边栏推荐
- Research on medical knowledge atlas question answering system (I)
- Dede collection plug-in does not need to write rules
- Shell analysis server log command collection
- This sideline workload is small, 10-15k, free unlimited massage
- Knowledge supplement: redis' basic data types and corresponding commands
- [recommended algorithm] C interview question of a small factory
- 【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
- Knowledge supplement: basic usage of redis based on docker
- 数据加载及预处理
- OSPF notes [multiple access, two multicast addresses with OSPF]
猜你喜欢
JS image path conversion Base64 format
数据加载及预处理
Software testing needs more and more talents. Why do you still not want to take this path?
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
The index is invalid
Section 27 remote access virtual private network workflow and experimental demonstration
MySQL advanced -- you will have a new understanding of MySQL
I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
尺取法:有效三角形的个数
VIM简易使用教程
随机推荐
2022年T电梯修理题库及模拟考试
How to do the performance pressure test of "Health Code"
数据加载及预处理
如何看待智慧城市建设中的改变和机遇?
【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码
VR线上展览所具备应用及特色
2022危险化学品生产单位安全生产管理人员题库及答案
js 图片路径转换base64格式
The index is invalid
TASK04|数理统计
Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
OSPF notes [multiple access, two multicast addresses with OSPF]
(12) Somersault cloud case (navigation bar highlights follow)
2022 t elevator repair question bank and simulation test
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
[human version] Web3 privacy game in the dark forest
软件研发的十大浪费:研发效能的另一面
网站服务器:好用的网站服务器怎么选这五方面要关注
Research on medical knowledge atlas question answering system (I)
2022-02-15 (399. Division evaluation)