I am extracting Resnet features for videos(1000-2000 frames each). I am looping for each video, each frame to extract feature for that frame.
But after 10-12 videos I get the error:
Error : Torch: not enough memory: you tried to allocate 38GB. Buy new RAM!
Sample code for feature extraction of one frame
import torch
import torch.nn as nn
import torchvision.models as models
from torch.autograd import Variable
resnet152 = models.resnet152(pretrained=True)
modules=list(resnet152.children())[:-1]
resnet152=nn.Sequential(*modules)
for p in resnet152.parameters():
p.requires_grad = False
img = torch.Tensor(3, 224, 224).normal_() # random image
img = img.unsqueeze(0) # add batch dimension
img_var = Variable(img) # assign it to a variable
features_var = resnet152(img_var) # get the output from the last hidden layer of the pretrained resnet
features = features_var.data # get the tensor out of the variable
Solutions tried:
-
ps -elf | grep python
kill -9 [pid]
-
sudo nvidia-smi --gpu-reset
Can anyone please tell how to handle this?