forked from CSAILVision/gandissect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_ace.py
48 lines (42 loc) · 1.52 KB
/
plot_ace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json, os
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.ticker import MaxNLocator
import matplotlib
from netdissect.easydict import EasyDict
metric = 'iqr'
basedir = 'dissect/ganunified'
scene = 'churchoutdoor'
classname = 'tree'
layername = 'layer4'
xlim = 30
test_metric = 'acez'
for scene, classname in [
('churchoutdoor', 'door'),
('churchoutdoor', 'tree'),
]:
fig = Figure(figsize=(4.5,3.5))
FigureCanvas(fig)
ax = fig.add_subplot(111)
for metric in [test_metric, 'iou']:
# Plot line graph
with open(os.path.join(basedir, scene, layername, 'ablation',
'%s-%s.json' % (classname, metric))) as f:
data = EasyDict(json.load(f))
ax.plot([0] +
[(data.baseline - data.ablation_effects[str(i)]) / data.baseline
for i in range(1, xlim + 1)],
label='Top units by IoU' if metric is 'iou' else
'Units by ACE')
ax.set_title('Effect of ablating units for %s' % (classname))
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
ax.grid(True)
ax.legend()
ax.set_ylim(0, 1.0)
ax.set_xlim(0, xlim)
ax.set_xticks(range(0, xlim + 1, 5))
ax.set_ylabel('Portion of %s pixels removed' % classname)
ax.set_xlabel('Number of units ablated')
fig.tight_layout()
fig.savefig('dissect/figure/aceablation/%s-ablate-%s-%s-lines.svg' %
(test_metric, scene, classname))