From 6fb0fed58c90f14e604650e0817077b510a42c63 Mon Sep 17 00:00:00 2001 From: Neta Zmora <neta.zmora@intel.com> Date: Sun, 25 Nov 2018 12:50:17 +0200 Subject: [PATCH] Activation statistics: fix computation of Channel-wise APoZ Instead of returning the average-percentage-of-zeros, we returned the average-percentage-of-non-zeros. So inverted the results, and also multiplied by 100, because the name of the statistic has "percentage" not "fraction" (not very important, but still...) --- distiller/utils.py | 2 +- tests/test_basic.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/distiller/utils.py b/distiller/utils.py index cb000b3..29e8bde 100755 --- a/distiller/utils.py +++ b/distiller/utils.py @@ -395,7 +395,7 @@ def activation_channels_apoz(activation): featuremap_apoz_mat = activation.abs().gt(0).sum(dim=1).float() / activation.size(1) # batch x 1 else: raise ValueError("activation_channels_apoz: Unsupported shape: ".format(activation.shape)) - return featuremap_apoz_mat.mean(dim=0).cpu() + return 100 - featuremap_apoz_mat.mean(dim=0).mul(100).cpu() def log_training_progress(stats_dict, params_dict, epoch, steps_completed, total_steps, log_freq, loggers): diff --git a/tests/test_basic.py b/tests/test_basic.py index 5d57a35..942f8eb 100755 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -66,7 +66,7 @@ def test_activations(): [7., 0., 8.], [0., 9., 0.]]]]) assert all(distiller.activation_channels_l1(x) == torch.tensor([21/2, 45/2])) - assert all(distiller.activation_channels_apoz(x) == torch.tensor([6/18, 9/18])) + assert all(distiller.activation_channels_apoz(x) == torch.tensor([100*(6+6)/(9+9), 100*(4+5)/(9+9)])) assert all(distiller.activation_channels_means(x) == torch.tensor([21/18, 45/18])) -- GitLab