![](/img/trans.png)
[英]How to get reproducible results using tensorflow-gpu in CNN model?
[英]In TensorFlow, how to clear the GPU memory of an intermediate variable in a CNN model?
我只是使用TensorFlow來實現CNN模型。 在訓練過程中,有一個中間變量占用較大的GPU內存,我想清除該變量的內存。
此變量稱為'rgb_concat',我只是嘗試使用'rgb_concat = []'清除其內存,不確定是否在TensorFlow中有用?
我如何在TensorFlow中實現這一目標? 提前致謝!
一個名為“ rgb_concat”的中間變量,它占用較大的GPU內存,我想清除它並為CNN模型中的其他層保存GPU內存。 如何在TensorFlow中實現它?
x = input_image
for j in range(n_sub_layers):
nn = Conv2dLayer(x, j) #
rgb_concat.append(nn)
x = nn
rgb_concat_sublayer = ConcatLayer([rgb_concat[0], rgb_concat[1]], concat_dim=3, name='rgb_concat_sublayer_{}_{}'.format(i,1))
for sub_layer in range(2, n_sub_layers): #Second 'for' loop!!!
rgb_concat_sublayer = ConcatLayer([rgb_concat_sublayer, rgb_concat[sub_layer]], concat_dim=3, name='rgb_concat_sublayer_{}_{}'.format(i,sub_layer))
由於在第二個“ for”循環之后不再需要“ rgb_concat”,因此應在“ for”循環后將其清除。
您是否嘗試過del關鍵字?
del rgb_concat
您也可以將變量設置為“無”。
rgb_concat = None
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.