utkuozbulak / pytorch-cnn-visualizations

Pytorch implementation of convolutional neural network visualization techniques
MIT License
7.81k stars 1.49k forks source link

Custom model #58

Closed Auth0rM0rgan closed 4 years ago

Auth0rM0rgan commented 4 years ago

Hey @utkuozbulak,

Nice Work! I wonder how can I adapt the cnn_layer_visualization.py for my own model? I tried to change the code where you load the Vgg pretrained model with my own but I faced an error.

I have tried to load my checkpoint like below:

    model = Net()
    model.load_state_dict(torch.load("Last_checkpoint.pth"))
    pretrained_model = model.exit.weight()   
    layer_vis = CNNLayerVisualization(pretrained_model, cnn_layer, filter_pos)

Am I doing wrong?

Thanks!

utkuozbulak commented 4 years ago

Hello,

For custom models or models that are not standard (i.e., the ones that do not have features and classifier with no nested layers within), you need to make modifications to the layer selection in order to target the correct layer(s). Try to understand how hook functions and how selecting the target layer works.

Auth0rM0rgan commented 4 years ago

Hey @utkuozbulak,

Thanks for your guide. Do you know any resources to learn them or help me more :)

utkuozbulak commented 4 years ago

I don't have a specific resource to read but you might have a look at model.modules() and model.children() to get an idea about accessing layers.