using TorchRay and extremal_perturbation method for custom datasets
Opened this issue · 2 comments
Dear TorchRay team,
Is it possible to use Torchray and especially extremal_perturbation method for the custom data sets?
I didn't find any mentions in the documentation of how it could be used for other datasets not only for the ImageNet. In the extremal_perturbation
function as the target could be used only int
0...999. I have tried to go through the source code of the class Perturbation
for sources of the ImageNet classes or methods to change it for my classes however I didn't succeed. Could you help me and give an example of the code of how it could be done?
Hi @mrdupadupa, thanks for your question and interest in extremal perturbations.
The reward_func
parameter to the extremal_perturbation
function handles setting the target class. By default, it uses simple_reward
function, which expects an integer target
(it's not restricted to be between 0-999 for ImageNet).
If you have a custom model that is similar to an image classifier --- i.e. the output is typically a 2D tensor -- batch x number of classes and the input is typically a 4D tensor -- batch x color channels x height x width), then you don't need to modify the code at all.
Depending on your dataset, you might want to play around with the following parameters to the extremal_perturbation
function:
step
(int; default: 7): the size of a single mask unit in pixels (you might want to decrease step if you're working with fine-grain image data),smooth
(int; default: 20): the amount of smoothing applied to an unsmoothed mask unit (if you decrease, the mask units will use less smoothing).areas
(list; default: [0.1]): you might want to change / add more areas to the list.
If you want to use a model that has a different kind of output, then you would need to create your own reward function --- this can be done by adapting simple_reward
.
Let us know if you have any other questions.
If you are looking for script to run pointing game on ImageNet, you can reach me!