no grad if frozen in forward pass
This commit is contained in:
@@ -13,6 +13,10 @@ class ViTClassifier(nn.Module):
|
|||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
# ViT -> (B, N, D)
|
# ViT -> (B, N, D)
|
||||||
|
if any(p.requires_grad for p in self.encoder.parameters()):
|
||||||
|
features = self.encoder(x)
|
||||||
|
else:
|
||||||
|
with torch.no_grad():
|
||||||
features = self.encoder(x)
|
features = self.encoder(x)
|
||||||
|
|
||||||
# Average Pool -> (B, D)
|
# Average Pool -> (B, D)
|
||||||
|
|||||||
Reference in New Issue
Block a user