There's an error with the last post, so I post it again. In urgent need for help.
I'm testing the caffemodel of FCN32s on pascal voc 2011 data, and the accuracy I got is not the reported mIU 64.0 as the author reported, much higher,
I must have done something wrong, here's my code for testing, can any who has successfully tested it help me with it ?
I got mIU about 72. I don't know why, there must be something wrong in my code.
Below is the code for testing:
net = caffe.Net("deploy.prototxt", "fcn-32s-pascal.caffemodel", caffe.TEST)
files = []
with open("val.txt","r") as f:
for line in f.readlines():
line = line.strip("\n")
files.append(line)
f.close()
colors = []
with open("color.txt", "r") as cf:
for line in cf.readlines():
line = line.strip("\n")
tmp = line.split()
colors.append((int(tmp[3]), int(tmp[2]), int(tmp[1])) )
cf.close()
bound = (192,224,224)
sum = 0.
ct=0 # counter
for l in files:
ct += 1
print ct, l
img = cv2.imread("data/images/%s.jpg"%(str(l)))
in_ = np.array(img, dtype=np.float32)
in_ -= np.array((104.00698793,116.66876762,122.67891434))
in_ = in_.transpose((2,0,1))
net.blobs['data'].reshape(1, *in_.shape)
net.blobs['data'].data[...] = in_
net.forward()
out = net.blobs['upscore'].data[0].argmax(axis=0)
mask = cv2.imread("data/mask/%s.png"%(l))
label = np.zeros(mask[:,:,0].shape)
obj = []
value = 0.
num = 0
for i in range(len(colors)):
eq = np.equal(mask, colors[i])
eq = np.prod(eq, 2).astype(int)
if (eq > 0).any():
num += 1
label += ( i+1 ) * eq
obj.append(i+1)
if num == 0:
raise
eq = np.equal(mask, bound)
eq = np.prod(eq, 2).astype(int)
label[np.nonzero(eq > 0)] = 255
out[np.nonzero(eq > 0)] = 255
# including background
if(label == 0).any():
obj.append(0)
num += 1
for idx in obj:
count1 = np.count_nonzero( (out == idx) & (label == idx))
count2 = np.count_nonzero( (out == idx) | (label==idx))
print count1, count2
value += float(count1)/count2
value = value/num
sum += value
print 1111, sum/1111