Closed SarfarazHabib closed 4 years ago
Hi @SarfarazHabib,
Thanks for your question.
The reason why it's giving an error is that currently the visualize
method is passing the output of the gradient ascent to matplotlib which expects the input to be an RBG image.
It is on my todo list to make the API more generalisable to various custom inputs and not just RGB or grayscale images.
As a quick solution meanwhile, I suggest below:
if isinstance(module, nn.modules.conv.Conv2d):
Use optimize
api, rather than visualize
, which returns raw gradients accumulated over the number of iterations as a list
Plot the gradients/channels of your interest
This is untested, but hope this helps - let me know how it goes.
@SarfarazHabib please feel free to reopen the issue or open a new one if required.
Hi, Thanks for your work. I am trying to use "Activation maximization" notebook with my own custom model. The difference is that my model takes an input of (56,56,24). The gradient ascent function accepts my model without an error. I perform my own transformation on a random generated input and the input shape is torch.Size([1, 24, 56, 56]).
When I call visualize function giving it any intermediate layer and filter, it throws below error:
TypeError Traceback (most recent call last)