I'm going to extract a feature from pictures.I first define a tensor data_feature_map
, and then use torch.cat
to stack the features of one picture.
My code is :
data_feature_map = torch.ones(1,2048)
for i, data in enumerate(train_loader, 0):
img, _ = data
img.requires_grad_=False
if torch.cuda.is_available():
img = img.cuda()
out = model(img)
# out.shape = [1,2048]
out = out.view(1,-1).cpu()
data_feature_map = torch.cat((data_feature_map, out), 0)
but when i run it, it will show the error "RuntimeError: CUDA out of memory."
please tell me why this error occurs.Thank you very much.