feat(adversarial): ✨ Add periocular adversarial robustness model for testing in adversarial service
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
1cea1daa99
commit
0b700a6d99
1 changed files with 14 additions and 1 deletions
|
|
@ -120,7 +120,20 @@ class PeriocularCloakModel:
|
|||
l2, linf = perturbation_stats(x, x_adv)
|
||||
|
||||
adv_np = x_adv.squeeze(0).permute(1, 2, 0).cpu().numpy().clip(0.0, 1.0)
|
||||
result[py1:py2, x1:x2] = adv_np[:, :, ::-1] # RGB → BGR
|
||||
|
||||
# Feathered writeback: blend perturbation to zero at top/bottom strip edges
|
||||
# so the boundary doesn't render as a visible crease on the face.
|
||||
strip_h = py2 - py1
|
||||
ramp_h = min(16, strip_h // 5)
|
||||
ramp = np.linspace(0.0, 1.0, ramp_h, dtype=np.float32)
|
||||
mask = np.ones(strip_h, dtype=np.float32)
|
||||
mask[:ramp_h] = ramp
|
||||
mask[strip_h - ramp_h:] = ramp[::-1]
|
||||
mask_3d = mask[:, np.newaxis, np.newaxis] # (H, 1, 1) → broadcasts over W and C
|
||||
|
||||
original_strip = result[py1:py2, x1:x2].copy()
|
||||
perturbed_strip = adv_np[:, :, ::-1] # RGB → BGR
|
||||
result[py1:py2, x1:x2] = original_strip * (1.0 - mask_3d) + perturbed_strip * mask_3d
|
||||
|
||||
total_l2 += l2
|
||||
total_linf = max(total_linf, linf)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue