Skip to content

Commit

Permalink
fix trojannnn neuron selection #105
Browse files Browse the repository at this point in the history
  • Loading branch information
ain-soph committed Mar 3, 2022
1 parent 1ff0e82 commit 61fe81d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion trojanvision/attacks/backdoor/trojannn.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ def get_neuron_idx(self) -> torch.Tensor:
if weight.dim() > 2:
weight = weight.flatten(2).mean(2)
weight = weight.mean(0)
return weight.argsort(descending=False)[:self.neuron_num]
return weight.argsort(descending=True)[:self.neuron_num]

def get_neuron_value(self, trigger_input: torch.Tensor, neuron_idx: torch.Tensor) -> float:
r"""Get average neuron activation value of :attr:`trigger_input` for :attr:`neuron_idx`.
The feature map is obtained by calling :meth:`ImageModel.get_layer()`.
Args:
trigger_input (torch.Tensor): Triggered input tensor with shape ``(N, C, H, W)``.
neuron_idx (torch.Tensor): Neuron index list tensor with shape ``(self.neuron_num)``.
Expand All @@ -138,6 +140,8 @@ def preprocess_mark(self, neuron_idx: torch.Tensor):
:any:`torch.optim.lr_scheduler.CosineAnnealingLR`
with tanh objective funcion.
The feature map is obtained by calling :meth:`ImageModel.get_layer()`.
Args:
neuron_idx (torch.Tensor): Neuron index list tensor with shape ``(self.neuron_num)``.
"""
Expand Down

0 comments on commit 61fe81d

Please sign in to comment.