MCPcopy Create free account
hub / github.com/breeze-sys/Label-Only-MIA-Go / MemGuard

Class MemGuard

python_server/classifier.py:66–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64 return nn.Sequential(*layers)
65
66class MemGuard(nn.Module):
67 def __init__(self):
68 super(MemGuard, self).__init__()
69
70 def forward(self, logits):
71 scores = F.softmax(logits, dim=1)#.cpu().numpy()
72 n_classes = scores.shape[1]
73 epsilon = 1e-3
74 on_score = (1. / n_classes) + epsilon
75 off_score = (1. / n_classes) - (epsilon / (n_classes - 1))
76 predicted_labels = scores.max(1)[1]
77 defended_scores = torch.ones_like(scores) * off_score
78 defended_scores[np.arange(len(defended_scores)), predicted_labels] = on_score
79 return defended_scores
80

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected