代码
import torch
import gc
for obj in gc. get_objects( ) :
try :
if torch. is_tensor( obj) or ( hasattr ( obj, 'data' ) and torch. is_tensor( obj. data) ) :
print ( type ( obj) , obj. size( ) )
except :
pass
输出
< class 'torch.Tensor' > torch. Size( [ 9 , 2 ] )
< class 'torch.Tensor' > torch. Size( [ 153 , 2 ] )
< class 'torch.Tensor' > torch. Size( [ 24633 , 2 ] )
< class 'torch.Tensor' > torch. Size( [ 25040000 , 2 ] )
< class 'torch.Tensor' > torch. Size( [ 25040000 , 2 ] )
< class 'torch.nn.parameter.Parameter' > torch. Size( [ 0 ] )
< class 'torch.Tensor' > torch. Size( [ 1 , 1 ] )
< class 'torch.Tensor' > torch. Size( [ 1 , 1 ] )
< class 'torch.Tensor' > torch. Size( [ 9 ] )
< class 'torch.Tensor' > torch. Size( [ 9 , 9 ] )
< class 'torch.Tensor' > torch. Size( [ 9 , 9 ] )
< class 'torch.Tensor' > torch. Size( [ 153 ] )
< class 'torch.Tensor' > torch. Size( [ 153 , 153 ] )
< class 'torch.Tensor' > torch. Size( [ 153 , 153 ] )
< class 'torch.Tensor' > torch. Size( [ 24633 ] )
< class 'torch.Tensor' > torch. Size( [ 5000 ] )
< class 'torch.Tensor' > torch. Size( [ 5000 , 5000 ] )
< class 'torch.Tensor' > torch. Size( [ 5000 , 5000 ] )
< class 'torch.Tensor' > torch. Size( [ 25040000 ] )
< class 'torch.Tensor' > torch. Size( [ 5000 ] )
< class 'torch.Tensor' > torch. Size( [ 5000 , 5000 ] )
< class 'torch.Tensor' > torch. Size( [ 5000 , 5000 ] )
< class 'torch.Tensor' > torch. Size( [ 25040000 ] )
< class 'torch.Tensor' > torch. Size( [ 100 , 1 ] )
< class 'torch.Tensor' > torch. Size( [ 100 ] )
< class 'torch.Tensor' > torch. Size( [ 100 ] )
< class 'torch.Tensor' > torch. Size( [ 100 , 1 ] )
< class 'torch.Tensor' > torch. Size( [ 100 , 1 ] )