I expect mean subtraction to be same between .prototxt and python's transfomer.set_mean. but No.

111 views
Skip to first unread message

Peerajak Witoonchart

unread,
Jan 10, 2017, 5:42:00 AM1/10/17
to Caffe Users
Hi all

I am expecting the transform_param{} to calculate the same thing as transformer.set_mean. When these values do not agree over the very same image, I think something must be wrong.

Suppose
I initailize a caffe solver with the following test section. I found that the solver.test_nets[0] will preprocess the image different from python caffe transformer.set_mean.
If I remove both the transform_param{} in prototxt and Transfomer.set_mean in python code out of the code, my net.data layer will be the same value. However, when there is transform_param{}, and Transformer, the net.data differs.



layer
{
  name
: "cifar"
  type
: "Data"
  top
: "data"
  top
: "label"
  include
{
    phase
: TEST
 
}
  transform_param
{
    mean_file
: "examples/Softmax/mean.binaryproto"
 
}
  data_param
{
    source
: "examples/Softmax/cifar10_testdata_pycreated"
    batch_size
: 100
    backend
: LMDB
 
}
}




import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import Image
import scipy.io
# load input and configure preprocessing
test_batch_mat_path
='examples/Softmax/cifar-10-batches-mat/test_batch_mat'
i_test_batch_Obj
= scipy.io.loadmat(test_batch_mat_path + '/test_batch.mat' )
X
= i_test_batch_Obj.get('data').reshape((10000,3,32,32)).astype('float')
im
= X[0,:,:,:].squeeze().transpose((1,2,0))
print im.shape
im
= im[:, :, (2, 1, 0)]


print np.load('examples/Softmax/mean.npy').mean(1).mean(1)

transformer
= caffe.io.Transformer({'data': net_softmax.blobs['data'].data.shape})
transformer
.set_mean('data', np.load('examples/Softmax/mean.npy').mean(1).mean(1))
#transformer.set_mean('data', np.load('python/caffe/imagenet/ilsvrc_2012_mean.npy').mean(1).mean(1))
#transformer.set_mean('data', mean_arr[0]) # ImageNet mean
transformer
.set_transpose('data', (2,0,1))
transformer
.set_channel_swap('data',(2,1,0))#(2,1,0))
transformer
.set_raw_scale('data',1.0)
# make classification map by forward and print prediction indices at each location
transformed_image
= transformer.preprocess('data', im)
net_softmax
.blobs['data'].data[...] = transformed_image
net_softmax
.forward()


Reply all
Reply to author
Forward
0 new messages