当前位置:网站首页>【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 计算可以节省内存,同时还可以省去反复申请和释放内存的时间。但是会对原变量覆盖,只要不带来错误就用。
参考:
边栏推荐
猜你喜欢

EasyPlayer针对H.265视频不自动播放设置下,loading状态无法消失的解决办法

亚马逊API接口大全

Douyin API interface

Amazon API interface Daquan

语音信号处理:预处理【预加重、分帧、加窗】

Taobao API interface reference

unable to extend table xxx by 1024 in tablespace xxxx

【latex异常和错误】Missing $ inserted.<inserted text>You can‘t use \spacefactor in math mode.输出文本要注意特殊字符的转义

淘宝API常用接口与获取方式

恒源云-Pycharm远程训练避坑指南
随机推荐
那些事情是用Unity开发项目应该一开始规划好的?如何避免后期酿成巨坑?
基于FPGA的FIR滤波器的实现(4)— 串行结构FIR滤波器的FPGA代码实现
Do not add the is prefix to the variables of the boolean type in the POJO class of the Alibaba specification
每日sql -用户两天留存率
导航定位中的坐标系
概念名词解释
矩阵分析——微分、积分、极限
EasyPlayer针对H.265视频不自动播放设置下,loading状态无法消失的解决办法
为什么我使用C#操作MySQL进行中文查询失败
【sdx62】XBL设置共享内存变量,然后内核层获取变量实现
buu—Re(5)
你是如何做好Unity项目性能优化的
sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
深度监督(中继监督)
【预约观看】Ambire 智能钱包 AMA 活动第四期即将举行
Go语言实现Etcd服务发现(Etcd & Service Discovery & Go)
unable to extend table xxx by 1024 in tablespace xxxx
concept noun
抖音获取douyin分享口令url API 返回值说明
进制转换间的那点事