Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python wrapper and extract_feature.cpp gives different fc7 layer values for the same image ? #1758

Closed
erogol opened this issue Jan 20, 2015 · 2 comments

Comments

@erogol
Copy link
Contributor

erogol commented Jan 20, 2015

I created a single image path file_list2.txt and I give it to caffe_reference model as

layers {
name: "data"
type: IMAGE_DATA
top: "data"
top: "label"
image_data_param {
source: "file_list2.txt"
batch_size: 1
new_height: 256
new_width: 256
}
transform_param {
crop_size: 224
mean_file: "mean_file.binaryproto"
mirror: false
}
}

layers {
name: "conv1"
type: CONVOLUTION
bottom: "data"
top: "conv1"
blobs_lr: 1
....

the I call extract_features.cpp as

./build/tools/extract_features.bin models/CaffeRef_iter_100000.caffemodel models/caffe_reference/train_val_feat_ext.prototxt fc7 /path/to/features 1

so it takes 1 image for 1 instance batch

Then for the same image I run following python code

net = caffe.Classifier(MODEL_FILE, "models/CaffeRef_iter_100000.caffemodel ",
mean=np.load(mean_file.npy'),
channel_swap=(2,1,0),
image_dims = [256,256],
raw_scale=255)

img_path = 'same/file/path'
img = caffe.io.load_image(img_path)
plt.imshow(img)
x = net.predict([img], oversample=False)

MODEL_FILE is same with last one except it has different data input;

input: "data"
input_dim: 10
input_dim: 3
input_dim: 224
input_dim: 224
layers {
name: "conv1"
type: CONVOLUTION
bottom: "data"
top: "conv1"
convolution_param {
num_output: 96
.....

So normally I ecpect to have the same feature vector for this image from these two different approach. However they are different. I compare both feature vector on Python like below to see that whether only the non-zero values are different or activated units are different too.

X[X>0] = 1
x[x>0] = 1
print len(np.nonzero(X-x)[0])
output: 845

I guess this needs a bit of attention from the community. Please direct me to enhance the observation.

@shelhamer
Copy link
Member

@erogol
Copy link
Contributor Author

erogol commented Jan 20, 2015

I believe this is not users problem since Python wrapper gives different output compared to caffe backhand. I guess something in the pycaffe preprocessing breaks the given image.

@erogol erogol mentioned this issue Jan 22, 2015
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants