forked from chrodan/pottics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_paper_plots.py
188 lines (153 loc) · 6.99 KB
/
generate_paper_plots.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# -*- coding: utf-8 -*-
"""
Generation of paper plots
Created on Thu Apr 19 21:02:05 2012
@author: Christoph Dann <cdann@cdann.de>
"""
import matplotlib as mpl
#mpl.use('PDF')
import predict.base
import predict.post
import util.visual
import dataset as ds
import subprocess
import numpy as np
import segments
import regions
import os
import loading
import unaries.densecrf
#import prediction.evaluation
import latentsvm
import util.visual
import predict.base
import predict.evaluation
import matplotlib.pyplot as plt
name_list=("2007_000733", # person, motorbike
"2007_001149", # monitor, sofa, pottedplant
"2007_002597", # dog, cat
"2007_003503", # bus, car,
"2007_003957", # train
"2011_003066", # chair, person, diningtable, bottle
"2007_004459", # person aeroplane
"2007_004537", # horse, cow, person
"2007_005107", # bike, person
"2007_005130", # bird
"2008_000120", # boat
"2008_001601") # sheep)
def prepare_jpg_plot():
plt.clf()
ax = plt.axes([0,0,1,1])
ax.set_axis_off()
return ax
def save_plot(fn, path):
plt.savefig(path+fn, bbox_inches="tight", pad_inches=0.1, quality=95)
subprocess.call("convert -trim "+fn+" "+fn, shell=True, cwd=path)
def cb_gt(name, ax):
util.visual.show_annotated_image(name, ax, alpha=0.8, show_bg=False)
def make_predictions(image):
w2 = np.loadtxt("../data/voc10train_t50_c1e3.lsvm")
predict.base.predict_pixel_unaries_on_regions(image, lambda x, y: unaries.densecrf.pixel_unary(x, '{dspath}/densecrf_unaries/{name}.unary'), w2)
image.rawconf,_ = predict.evaluation.get_confusion_mat(image.prediction, image.ground_truth, image.ds.classnum)
_,_,image.hacc_unary = predict.evaluation.get_hamming_score_img([image])
image.unary_prediction = image.prediction
del image.prediction
latentsvm.predict_latentsvm(image, unaries.densecrf.region_unary, w2, Psi_f=None, randinit_num=3)
image.rawconf,_ = predict.evaluation.get_confusion_mat(image.prediction, image.ground_truth, image.ds.classnum)
_,_,image.hacc = predict.evaluation.get_hamming_score_img([image])
image.improvement = image.hacc- image.hacc_unary
if __name__=="__main__":
path = '../../../dagm12/images/rider/'
plt.figure()
n = "2007_005331"
img = ds.voc2010_trainval[ds.voc2010_trainval.names.index(n)]
masks = img.top_masks
scores = img.get_top_scores()
num = 12
for i in range(num):
ax = prepare_jpg_plot()
mask = masks[:,:,i]
mask[mask > 0] = 6
util.visual.show_image_mask(img, mask, ax, alpha=0.9)
fn = 'segment_{:0=2d}.jpg'.format(i+1)
util.visual.add_inner_title(ax, "Score: {:.4}".format(scores[i]), 3, size={"size":45, "color":"w"})
save_plot(fn, path)
regs = regions.produce_regions(masks[:,:,:num])
ax = prepare_jpg_plot()
ax.imshow(regs,cmap=mpl.colors.ListedColormap ( np.random.rand ( 256,3)), interpolation="nearest")
save_plot("regions.png", path)
ax = prepare_jpg_plot()
reg = img.regions
ax.imshow(reg,cmap=mpl.colors.ListedColormap ( np.random.rand ( 256,3)) ,interpolation='nearest')
ax.set_axis_off()
save_plot("regions_all.png", path)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, show_bg=True, alpha=1.)
save_plot("gt.jpg", path)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, show_bg=False, alpha=0.)
save_plot("img.jpg", path)
w2 = np.loadtxt("../data/voc10train_t50_c1e3.lsvm")
alpha_prescale = w2[0]
binary_prescale = w2[1]
topics_num = w2[2]
alpha = w2[3]
print alpha, alpha_prescale, binary_prescale
w2 = w2[4:].reshape((-1, ds.voc2010_trainval.classnum))
plt.figure(figsize=(8,3))
plt.imshow(w2.T, interpolation="nearest")
plt.xlabel("Topics")
plt.ylabel("Classes")
plt.colorbar()
plt.savefig(path+"../t50_param.pdf")
# Potts model
plt.figure()
d = {-15.0: 0.17103042426067733, -30.0: 0.062159744574600821, -20.0: 0.17085102071912303, -10.0: 0.18369981224948917, -0.5: 0.20696463519914904, -0.75: 0.20392326688153847, -0.3: 0.20925346346946677, -0.1: 0.21599148471137419, -5: 0.1937169597255228, -1: 0.20335897436734418}
a = d.items()
a.sort()
#a.reverse()
x,y = tuple(zip(*a))
plt.plot(x,y)
plt.xlabel(r"$\alpha$")
plt.ylabel("VOC Score")
plt.savefig(path+"../potts.pdf")
path = '../../../dagm12/images/visuals/'
imgs = [ds.voc2010_val[i] for i in [590, 851, 688, 845, 140, 627, 591, 61, 645]]
for img in imgs:
make_predictions(img)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, show_bg=False, alpha=0.9)
save_plot("impr_{}_gt.jpg".format(img.name), path)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, annotation=img.prediction, show_bg=False, alpha=0.9)
save_plot("impr_{}_pottics.jpg".format(img.name), path)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, annotation=img.unary_prediction, show_bg=False, alpha=0.9)
save_plot("impr_{}_unary.jpg".format(img.name), path)
print img.name, ": Unary Hamming Score", img.hacc_unary, " pottics Hamming Score", img.hacc
imgs = [ds.voc2010_val[i] for i in [586, 354, 262, 80, 678, 54, 755, 721]]
for img in imgs:
make_predictions(img)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, show_bg=False, alpha=0.9)
save_plot("worse_{}_gt.jpg".format(img.name), path)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, annotation=img.prediction, show_bg=False, alpha=0.9)
save_plot("worse_{}_pottics.jpg".format(img.name), path)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, annotation=img.unary_prediction, show_bg=False, alpha=0.9)
save_plot("worse_{}_unary.jpg".format(img.name), path)
print img.name, ": Unary Hamming Score", img.hacc_unary, " pottics Hamming Score", img.hacc
imgs = [ds.voc2010_val[i] for i in [125, 525, 729]]
for img in imgs:
make_predictions(img)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, show_bg=False, alpha=0.9)
save_plot("topic_{}_gt.jpg".format(img.name), path)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, annotation=img.prediction, show_bg=False, alpha=0.9)
save_plot("topic_{}_pottics.jpg".format(img.name), path)
ax = prepare_jpg_plot()
util.visual.show_annotated_image(img, ax, annotation=img.unary_prediction, show_bg=False, alpha=0.9)
save_plot("topic_{}_unary.jpg".format(img.name), path)
print img.name, ": Unary Hamming Score", img.hacc_unary, " pottics Hamming Score", img.hacc