国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

在運(yùn)行反向傳播函數(shù)之后,立即再次運(yùn)行它,看看會發(fā)生什么

2021-12-01 14:21 作者:如果我是泡橘子  | 我要投稿

正常運(yùn)行反向傳播函數(shù)

輸出結(jié)果如下:
tensor([ ?0., ? 4., ? 8., ?12., ?16., ?20., ?24., ?28., ?32., ?36., ?40., ?44., ? ? ? ? 48., ?52., ?56., ?60., ?64., ?68., ?72., ?76., ?80., ?84., ?88., ?92., ? ? ? ? 96., 100., 104., 108., 112., 116., 120., 124., 128., 132., 136., 140., ? ? ? ?144., 148., 152., 156.])


如果再次運(yùn)行反向傳播

輸出結(jié)果如下:

RuntimeError: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward.

大概的意思好像是說在調(diào)用backward()進(jìn)行第二次反向傳播時(shí),計(jì)算圖中保存的中間值(這里我的理解是第一次求導(dǎo)后的值)已經(jīng)被釋放掉了,所以報(bào)錯(cuò)


上面也對二次反向傳播提出了解決的方案:在backward()函數(shù)中設(shè)置參數(shù)retain_graph=True

設(shè)置了參數(shù)后的輸出如下:

tensor([ ?0., ? 4., ? 8., ?12., ?16., ?20., ?24., ?28., ?32., ?36., ?40., ?44., ? ? ? ? 48., ?52., ?56., ?60., ?64., ?68., ?72., ?76., ?80., ?84., ?88., ?92., ? ? ? ? 96., 100., 104., 108., 112., 116., 120., 124., 128., 132., 136., 140., ? ? ? ?144., 148., 152., 156.])


嘗試進(jìn)行二次反向傳播

輸出結(jié)果如下:

tensor([ ?0., ? 8., ?16., ?24., ?32., ?40., ?48., ?56., ?64., ?72., ?80., ?88., ? ? ? ? 96., 104., 112., 120., 128., 136., 144., 152., 160., 168., 176., 184., ? ? ? ?192., 200., 208., 216., 224., 232., 240., 248., 256., 264., 272., 280., ? ? ? ?288., 296., 304., 312.])


成功完成了二次反向傳播!





----end----

在運(yùn)行反向傳播函數(shù)之后,立即再次運(yùn)行它,看看會發(fā)生什么的評論 (共 條)

分享到微博請遵守國家法律
永清县| 禹城市| 靖西县| 灵璧县| 澜沧| 营口市| 德惠市| 耿马| 南京市| 项城市| 阳山县| 崇义县| 百色市| 扶风县| 太和县| 修武县| 临桂县| 嵩明县| 宜都市| 光山县| 同仁县| 镶黄旗| 汉源县| 夹江县| 望城县| 张掖市| 肥乡县| 始兴县| 大姚县| 惠来县| 宜阳县| 济阳县| 白山市| 平昌县| 龙岩市| 阳高县| 长寿区| 松江区| 合江县| 永昌县| 自贡市|