Output of Caffe Feature Extraction example

1,669 views
Skip to first unread message

Roy

unread,
Apr 14, 2015, 7:27:30 AM4/14/15
to caffe...@googlegroups.com

Hi All

I am new to caffe. I successfully installed and ran the caffe feature extraction demo. The application ouputs two .mdb files data.mdb and lock.mdb.

The tutorial does not say beyond how to use those two files or how to access the data inside them. They are not microsoft access files. Anybody would like to explain how to access the data in those files. Is there any code available that helps explain.

Appreciate your help and thank you!
regards
Roy

Nikiforos Pittaras

unread,
Apr 14, 2015, 8:32:44 AM4/14/15
to caffe...@googlegroups.com
You can modify the .cpp file to store the features in the format you wish, that's what I have done.

J. Yegerlehner

unread,
Apr 14, 2015, 12:55:41 PM4/14/15
to caffe...@googlegroups.com
Those are lmdb database files. That is one of two formats that layers of type Data read.
http://caffe.berkeleyvision.org/tutorial/data.html
http://caffe.berkeleyvision.org/tutorial/layers.html#data-layers

Alessandro Ortis

unread,
May 25, 2015, 7:50:26 AM5/25/15
to caffe...@googlegroups.com
can you explain better please? for example I wish to print the 4096-d features of fc8 in the prompt or write them in a txt file.

npit

unread,
May 25, 2015, 8:36:38 AM5/25/15
to caffe...@googlegroups.com
in tools/extract_features.cpp


The loop at line 157, loops over the values of the feature of a single image.
feature_blob_data[d] is the d-th value of the feature vector
The loop at line 143 loops over the feature layers.
The loops at lines  141 and 149  loop over the # of minibatches and each image in the batch, respectively.

So you can store the feature vector of each image using the indices of the above loops :)

anurika

unread,
Jun 4, 2015, 6:07:55 AM6/4/15
to caffe...@googlegroups.com
Hi!!
I also want to do the same thing. DId you find the solution to this?

Kenya

unread,
Jul 1, 2015, 4:56:14 AM7/1/15
to caffe...@googlegroups.com
Hi npit,

What format did you save your file as?
Also, could you kindly post your extract_features.cpp file to this thread?

Thanks in advance,

npit

unread,
Jul 1, 2015, 6:38:04 AM7/1/15
to caffe...@googlegroups.com
 save the file in whatever format I want, since I store the data in a pointer.
Here's the relevant code you asked for. Note that this works only for a batchSize that divides the number of images exactly.




// initialize the feature containers' pointers and the dimension container

                data = new float*[num_layers];
featDimension = new int[num_layers];
numLayers = num_layers;
// variable to control one-time allocation within the loop
bool * allocated = new bool[num_layers];
// init to false
for (int layer_index = 0; layer_index < num_layers; ++layer_index) allocated[layer_index] = false;



                // EXTRACT

// for each batch of images
for (int batch_index = 0; batch_index < num_mini_batches; ++batch_index) 
{
// evaluate the net
feature_extraction_net->Forward(input_vec);

// for each feature layer
for (int layer_index = 0; layer_index < num_layers; ++layer_index) 
{
// get that layer blob and its dimension
const boost::shared_ptr<Blob<Dtype> > feature_blob = feature_extraction_net
->blob_by_name(blob_names[layer_index]);
int batch_size = feature_blob->num();
int dim_features = feature_blob->count() / batch_size;

// init the feat container for that layer if needed, set dimension
if (!allocated[layer_index])
{
data[layer_index] = new float[dim_features * num_mini_batches * batch_size];
featDimension[layer_index] = dim_features;
allocated[layer_index] = true;
}

const Dtype* feature_blob_data;
// for each image in the batch
for (int image_index_inBatch = 0; image_index_inBatch < batch_size; ++image_index_inBatch) {

// get the image's feature vector
feature_blob_data = feature_blob->cpu_data() +
feature_blob->offset(image_index_inBatch);
// copy the values to the data container
for (int d = 0; d < dim_features; ++d) {
data[layer_index][(batch_index * batch_size + image_index_inBatch) * dim_features + d] = feature_blob_data[d];
}

++image_indices[layer_index];

if (image_indices[layer_index] % 1000 == 0) {
//txns.at(layer_index)->Commit();
//txns.at(layer_index).reset(feature_dbs.at(layer_index)->NewTransaction());
LOG(ERROR) << "Extracted features of " << image_indices[layer_index] <<
" query images for feature blob " << blob_names[layer_index];
}
}  // for (int image_index_inBatch = 0; image_index_inBatch < batch_size; ++image_index_inBatch)
}  // for (int layer_index = 0; layer_index < num_layers; ++layer_index)
}  // for (int batch_index = 0; batch_index < num_mini_batches; ++batch_index)
// write the last batch

for (int layer_index = 0; layer_index < num_layers; ++layer_index) {
LOG(ERROR) << "Extracted features of " << image_indices[layer_index] <<
" query images for feature blob " << blob_names[layer_index];
}

Uni A

unread,
Aug 11, 2015, 10:42:01 AM8/11/15
to Caffe Users
Hi Kenya, 

Did you figure out how to handle this issue? 

Thanks

Komal Sinha

unread,
Sep 11, 2015, 7:42:09 AM9/11/15
to Caffe Users
Hi !

Please send the full modified code for extract_feature.cpp. as making the mentioned changes throws error .
Thanks! 

Hongping Cai

unread,
Sep 22, 2015, 12:05:34 PM9/22/15
to Caffe Users
I also got stuck in the same problem. 

npit

unread,
Sep 23, 2015, 2:37:19 AM9/23/15
to Caffe Users
What's the error?

Ali Matin

unread,
Oct 14, 2015, 8:00:17 AM10/14/15
to Caffe Users
errors like undefined variables! i spend a long time fixing errors but I'm wasting time, i cant understand whole code so i cant fix all errors. would you send the whole .cpp file wich works? thank you

On Wednesday, September 23, 2015 at 10:07:19 AM UTC+3:30, npit wrote:
What's the error?

Xing Di

unread,
Nov 17, 2015, 11:21:04 AM11/17/15
to Caffe Users
I also stuck in this problem
Reply all
Reply to author
Forward
0 new messages