Hi,
I want to extract all features from first convolution Layer in ResNet Model.
So, i construct the codes like below
# Model file
class ResNet(nn.Module):
    def __init__().__init__()
         .....
        # First Convolution Layer
        self.conv1 = nn.Conv2d(...)
        ....
        # Fully-Connected Layer
        self.fc = nn.Linear(...)

    def forward(self, data):
        .....
    def extract_features(self, data):
        # Extract First Convolution features
        return self.conv1(data)

# Implement code
model = ResNet()

with torch.no_grad():
    for batch_idx, (inputs, targets) in enumerate(train_loader):
         outputs = model.extract_features(inputs) # <- It causes memory leakage
        

Running this code, i encountered an error
CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 11.91 GiB total capacity; 11.33 GiB already allocated; 2.88 MiB free; 11.34 GiB reserved in total by PyTorch)

I know that  torch.no_grad()  means do not using gradient options when inference time
But in my code, GPU memories are increase every iteration.
Anybody can help?