Difference between Datum class and Blob class in caffe library

194 views
Skip to first unread message

Nyan Naing

unread,
Feb 27, 2017, 11:31:51 PM2/27/17
to Caffe Users

Caffe has two data class Datum class and Blob.

(1)Could somebody explain what is the difference and advantages upon each other?

The reason why I query is

I am structuring two nets using caffe libraries. One net will go through the input image and extract features.

Then the second net will take the feature as input and do forward for the detection.

What I am confusing is whether I should keep the feature extracted using the first net in Blob format or Datum to input into the second net. Because feature_extraction example in the caffe library changed Blob data to Datum to save the data. Please look at the following code.


Datum datum;
std
::vector<int> image_indices(num_features, 0);
for (int batch_index = 0; batch_index < num_mini_batches; ++batch_index)
{
     feature_extraction_net
->Forward();
     
for (int i = 0; i < num_features; ++i) {
         
const boost::shared_ptr<Blob<Dtype> > feature_blob = feature_extraction_net->blob_by_name(blob_names[i]);
         
int batch_size = feature_blob->num();
         
int dim_features = feature_blob->count() / batch_size;
         
const Dtype* feature_blob_data;
         
for (int n = 0; n < batch_size; ++n) {
                 datum
.set_height(feature_blob->height());
                 datum
.set_width(feature_blob->width());
                 datum
.set_channels(feature_blob->channels());
                 datum
.clear_data();
                 datum
.clear_float_data();
                 feature_blob_data
= feature_blob->cpu_data() + feature_blob->offset(n);
                 
for (int d = 0; d < dim_features; ++d) { datum.add_float_data(feature_blob_data[d]); }
                 
string key_str = caffe::format_int(image_indices[i], 10);
                 
string out; CHECK(datum.SerializeToString(&out));
                 txns
.at(i)->Put(key_str, out); ++image_indices[i];
               
if (image_indices[i] % 1000 == 0) {
                       txns
.at(i)->Commit();
                       txns
.at(i).reset(feature_dbs.at(i)->NewTransaction());
                       LOG
(ERROR)<< "Extracted features of " << image_indices[i] << " query images for feature blob " << blob_names[i];
                 
}
       
} // for (int n = 0; n < batch_size; ++n) } // for (int i = 0; i < num_features; ++i) } // for (int batch_index = 0; batch_index < num_mini_batches; ++batch_index)
}

Inside the code, num_mini_batches is 10, batch_size is 50 and dim_features is 4096. dim_features is clear it is output, so it is depth of the output volume.

(2)What do batch_size 50 and num_mini_batches 10 mean for? Why we need to run through 10 times to have fc7 features in the image?

Could somebody explain me for these two queries?


Reply all
Reply to author
Forward
0 new messages