Cysu / dgd_person_reid

Domain Guided Dropout for Person Re-identification
http://arxiv.org/abs/1604.07528
231 stars 94 forks source link

The difference of jstl_dgd_inference.caffemodel and jstl_dgd.caffemodel? #32

Closed kecaiwu closed 7 years ago

kecaiwu commented 7 years ago

I compute the euclidean distance between two images, and the jstl_dgd_inference.caffemodel get the distance is 64.3684, then i change the caffemodel to jstl_dgd.caffemodel that getting the distance is 1.26359441957e-05, we extract the fc7 layer feature, what's problem in this process, thx.

Cysu commented 7 years ago

Do you use different prototxts for different caffemodels? Specifically, jstl_dgd_deploy.prototxt <=> jstl_dgd.caffemodel and jstl_dgd_deploy_inference.prototxt <=> jstl_dgd_inference.caffemodel.

kecaiwu commented 7 years ago

I have check the prototxt and caffemodel, and these is no problem, this is the script that extract fc7 feature, can you help me run this script in your environment, thx.

!/usr/bin/env python

import numpy as np import caffe from scipy.spatial import distance import time import cv2

deploy_prototxt = '/home/cc/software/dgd_person_reid/output/jstl_dgd_deploy.prototxt' model_file = '/home/cc/software/dgd_person_reid/output/jstl_dgd.caffemodel' input1 = '/home/cc/software/dgd_person_reid/output/liou1.jpg' input2 = '/home/cc/software/dgd_person_reid/output/liou2.jpg'

def tic(): globals()['tt'] = time.clock()

def toc(): print '\nElapsed time: %.8f seconds\n' % (time.clock()-globals()['tt'])

caffe.set_mode_gpu() caffe.set_device(0)

net = caffe.Net(deploy_prototxt, model_file, caffe.TEST)

transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) transformer.set_transpose('data', (2,0,1)) transformer.set_mean('data', np.array([102, 102, 101]))

transformer.set_raw_scale('data', 255) # rescale from [0, 1] to [0, 255] transformer.set_channel_swap('data', (2,1,0)) # swap channels from RGB to BGR net.blobs['data'].reshape(1, 3, 144, 56)

myfeature = []

imglist = [input1, input2] for f in imglist: img = caffe.io.load_image(f) net.blobs['data'].data[...] = transformer.preprocess('data', img) tic() output = net.forward() toc()

feat = net.blobs['fc7'].data[0]
# convert array to list in 'feat'
feat = feat.tolist()
print feat
print '----------------------------'
myfeature.append(feat)

print distance.euclidean(myfeature[0], myfeature[1])

Cysu commented 7 years ago

@kecaiwu For jstl_dgd_deploy.prototxt, you may need to extract the blob 'fc7_bn', rather than 'fc7'.

kecaiwu commented 7 years ago

I rechoose the caffe version from the 'external/caffe' by your provided:

jstl_dgd.caffemodel + fc7_bn = 77.8961552259 (Euclidean distance) jstl_dgd.caffemodel + fc7 = 0.827980185359 (Euclidean distance) jstl_dgd_inference.caffemodel + fc7 = 77.8961590025 (Euclidean distance)

these distance results is normal?

Cysu commented 7 years ago

Yes. I think these numbers are reasonable.

kecaiwu commented 7 years ago

Thanks for your help! @Cysu