-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathvisualize_densecrf_gradient.py
72 lines (53 loc) · 1.77 KB
/
visualize_densecrf_gradient.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
from sys import exit
import sys
sys.path.insert(0,'/home/m62tang/rloss/deeplab/python')
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import caffe
caffe.set_device(0)
caffe.set_mode_gpu()
solver = caffe.SGDSolver('pascal_scribble/config/deeplab_largeFOV/solverwithdensecrfloss_train.prototxt')
solver.net.copy_from('pascal_scribble/model/deeplab_largeFOV/train_iter_9000.caffemodel')
training_net = solver.net
solver.step(1)
print 'densecrf loss', training_net.blobs['densecrf_loss'].data
print training_net.blobs['fc8_interp_softmax'].data.shape
prob = training_net.blobs['fc8_interp_softmax'].data
scores = training_net.blobs['fc8_interp']
print type(prob)
print prob[0,0,:,:].shape
print prob[0,0,:,:].dtype
# RGB image
imgblob = training_net.blobs['data'].data
imgblob = imgblob[0,:,:,:]
(C, H, W) = imgblob.shape
img = np.zeros((H, W, C), dtype=np.uint8);
img[:,:,2] = imgblob[0,:,:] + 104.008
img[:,:,1] = imgblob[1,:,:] + 116.669
img[:,:,0] = imgblob[2,:,:] + 122.675
scores_diff = scores.diff
print np.amax(scores_diff[0,1,:,:])
print np.amin(scores_diff[0,1,:,:])
prob0 = prob[0,0,:,:]
prob_diff = training_net.blobs['fc8_interp_softmax'].diff
shrink_scores_diff = training_net.blobs['fc8_pascal_scribble'].diff
for i in range(21):
fig=plt.figure()
plt.imshow(prob[0,i,:,:], vmin=0, vmax=1);
plt.colorbar()
plt.axis('off')
plt.savefig('visualization/' + str(i) + 'prob' + '.png')
plt.show(block=False)
plt.close(fig)
for i in range(21):
fig = plt.figure()
plt.imshow(scores_diff[0,i,:,:],cmap="hot");
plt.colorbar()
plt.axis('off')
plt.savefig('visualization/' + str(i) + 'scorediff' + '.png')
plt.show(block=False)
plt.close(fig)
plt.figure()
plt.imshow(img, cmap='gray')
plt.show(block=True)