forked from nigroup/nideep
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpascal_context.py
More file actions
93 lines (71 loc) · 2.38 KB
/
pascal_context.py
File metadata and controls
93 lines (71 loc) · 2.38 KB
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
'''
Created on Jul 21, 2015
@author: kashefy
'''
import os
import numpy as np
import fileSystemUtils as fs
import cv2 as cv2
import cv2.cv as cv
from PIL import Image
import matplotlib.pyplot as plt
from read_img import read_img_cv2, read_img_PIL
CAFFE_ROOT = '/home/kashefy/src/caffe/'
if CAFFE_ROOT is not None:
import sys
sys.path.insert(0, os.path.join(CAFFE_ROOT, 'python'))
import caffe
def main(args):
caffe.set_mode_cpu()
# load image, switch to BGR, subtract mean, and make dims C x H x W for Caffe
path_img = '/home/kashefy/data/VOCdevkit/VOC2012/JPEGImagesX/2008_000015.jpg'
bgr_mean = np.array((104.00698793,116.66876762,122.67891434))
im = Image.open(path_img)
in_ = np.array(im, dtype=np.float32)
in_ = in_[:,:,::-1]
print in_.shape
print in_
in_ -= bgr_mean
print in_
in_ = in_.transpose((2,0,1))
in_ = read_img_PIL(path_img, mean=bgr_mean)
print 'in_'
print in_[0, 0, 0:6]
print in_[1, 0, 0:6]
print in_[2, 0, 0:6]
in2 = read_img_cv2(path_img, mean=bgr_mean)
print in2.shape
#in2[0, :, :] -= 104.00698793
#in2[1, :, :] -= 116.66876762
#in2[2, :, :] -= 122.67891434
print in2[0, 0, 0:6]
print in2[1, 0, 0:6]
print in2[2, 0, 0:6]
print np.all(in_ == in2)
print in_[in_ != in2]
print in2[in_ != in2]
return 0
# load net
path_model = '/home/kashefy/data/models/fcn_segm/fcn-32s-Pascal-context/deploy.prototxt'
path_weights = '/home/kashefy/data/models/fcn_segm/fcn-32s-Pascal-context/fcn-32s-pascalcontext.caffemodel'
net = caffe.Net(path_model, path_weights, caffe.TEST)
# shape for input (data blob is N x C x H x W), set data
net.blobs['data'].reshape(1, *in_.shape)
net.blobs['data'].data[...] = in_
# run net and take argmax for prediction
# net.forward()
# out = net.blobs['score'].data[0].argmax(axis=0)
#
#
# print 'data after fwd'
# print net.blobs['data'].data[net.blobs['data'].data.shape[0]/2-3:net.blobs['data'].data.shape[0]/2+3,
# net.blobs['data'].data.shape[1]/2-3:net.blobs['data'].data.shape[1]/2+3]
#
# print 'out'
# print out[out.shape[0]/2-3:out.shape[0]/2+3,
# out.shape[1]/2-3:out.shape[1]/2+3]
# plt.imshow(out)
# plt.show()
if __name__ == '__main__':
main(None)
pass