Skip to content

Instantly share code, notes, and snippets.

@ryujaehun
Created February 13, 2019 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryujaehun/523f583a0d798e70b1fccf1fabaa3ade to your computer and use it in GitHub Desktop.
Save ryujaehun/523f583a0d798e70b1fccf1fabaa3ade to your computer and use it in GitHub Desktop.
import torch
import torchvision
import numpy as np
model=torchvision.models.vgg19(pretrained=True)
input=torch.rand(1,3,224,224)
def get_features_hook(self, input, output):
_max = output.data.cpu().numpy().max()
_min = output.data.cpu().numpy().min()
np.save(str(self),output.data.cpu().numpy())
print("self: ",str(self),'max: ',_max,'\nmin: ',_min)
model=torchvision.models.vgg19(pretrained=True)
for i,_ in model.named_children():
for k in range(len(model._modules.get(i))):
model._modules.get(i)[k].register_forward_hook(get_features_hook)
model(input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment