I’m running my model on Google Colab and I’m faced with CUDA out of memory error. I have batch_size = 20
and all the images are resized to (224,224)
. I am using vgg13 model with pre-trained weights with a custom classifier:
classifier = nn.Sequential(OrderedDict([ ('fc1', nn.Linear(25088, 25088)), ('relu', nn.ReLU()), ('dropout', nn.Dropout(0.5)), ('fc2', nn.Linear(25088, 2048)), ('relu', nn.ReLU()), ('dropout', nn.Dropout(0.5)), ('fc3', nn.Linear(2048, 1024)), ('relu', nn.ReLU()), ('dropout', nn.Dropout(0.5)), ('fc4', nn.Linear(1024, 10)) ]))
I tried deleting images and labels of each iteration but no use. What else can I do to bring down memory usage and/or why is Cuda having an out of memory error?(I just trained a densenet 121 with no problems on same data)
Notebook:
Which GPU are you using and how much memory does it have?
I just used the torchvision.models.vgg13
model with your custom classifier and have a memory allocation of ~5.2GB after running the forward and backward pass using input = torch.randn(20, 3, 224, 224, device='cuda')
.