当前位置:网站首页>【Pytorch】nn.ReLU(inplace=True)
【Pytorch】nn.ReLU(inplace=True)
2022-08-11 06:28:00 【二进制人工智能】
nn.ReLU(inplace=False)中inplace的默认为False
当inplace = False 时,nn.ReLU不会修改输入对象的值,而是创建一个新的对象作为输出。
当inplace = True 时,nn.ReLU会修改输入对象的值作为输出,而不是创建一个新的对象。
import torch
import torch.nn as nn
input = torch.randn(5)
relu_F = nn.ReLU(inplace=False)
relu_T = nn.ReLU(inplace=True)
output_F = relu_F(input)
output_T = relu_T(input)
print('输入:', input, 'id:', id(input))
print('inplace=False,输出:', output_F, 'id:', id(output_F))
print('inplace=Ture,输出:', output_T, 'id:', id(output_T))

利用inplace = True 计算可以节省内存,同时还可以省去反复申请和释放内存的时间。但是会对原变量覆盖,只要不带来错误就用。
参考:
边栏推荐
- linux 安装mysql服务报错
- 下一代 无线局域网--强健性
- Daily sql-statistics of the number of professionals (including the number of professionals is 0)
- Redis源码-String:Redis String命令、Redis String存储原理、Redis字符串三种编码类型、Redis String SDS源码解析、Redis String应用场景
- sql--Users who have purchased more than 3 times (inclusive) within 7 days (including the current day), and the purchase amount in the past 7 days exceeds 1,000
- Redis测试
- Tidb二进制集群搭建
- 【深度学习】什么是互信息最大化?
- Taobao API interface reference
- 详述MIMIC 的ICU患者检测时间信息表(十六)
猜你喜欢

ssh服务攻防与加固

STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比

ROS 话题通信理论模型

unable to extend table xxx by 1024 in tablespace xxxx

Douyin API interface

Resolved EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo

Trill keyword search goods - API

空间金字塔池化 -Spatial Pyramid Pooling(含源码)

拼多多API接口(附上我的可用API)

radix-4 FFT 原理和C语言代码实现
随机推荐
Unity3D 学习路线?
从苹果、SpaceX等高科技企业的产品发布会看企业产品战略和敏捷开发的关系
博途PLC 1200/1500PLC ModbusTcp通信梯形图优化汇总(多服务器多从站轮询)
unable to extend table xxx by 1024 in tablespace xxxx
每日sql-求2016年成功的投资总和
Get Pinduoduo product information operation details
Attitude solution - gyroscope + Euler method
语音信号处理:预处理【预加重、分帧、加窗】
从 dpdk-20.11 移植 intel E810 百 G 网卡 pmd 驱动到 dpdk-16.04 中
PIXHAWK飞控使用RTK
ROS 话题通信理论模型
拼多多API接口大全
Implement general-purpose, high-performance sorting and quicksort optimizations
Redis源码:Redis源码怎么查看、Redis源码查看顺序、Redis外部数据结构到Redis内部数据结构查看源码顺序
2022-08-09 Group 4 Self-cultivation class study notes (every day)
Do not add the is prefix to the variables of the boolean type in the POJO class of the Alibaba specification
docker安装mysql5.7(仅供测试使用)
Cobbleland 博览会 基础系列 1
pytorch,numpy两种方法实现nms类间+类内
Pinduoduo API interface