Progress should be reported for each feature blob
authorKai Li <kaili_kloud@163.com>
Tue, 17 Jun 2014 08:27:24 +0000 (16:27 +0800)
committerKai Li <kaili_kloud@163.com>
Tue, 24 Jun 2014 14:12:44 +0000 (22:12 +0800)
tools/extract_features.cpp

index 99eb0db..aa665a0 100644 (file)
@@ -141,7 +141,7 @@ int feature_extraction_pipeline(int argc, char** argv) {
   char key_str[kMaxKeyStrLength];
   int num_bytes_of_binary_code = sizeof(Dtype);
   vector<Blob<float>*> input_vec;
-  int image_index = 0;
+  vector<int> image_indices(num_features, 0);
   for (int batch_index = 0; batch_index < num_mini_batches; ++batch_index) {
     feature_extraction_net->Forward(input_vec);
     for (int i = 0; i < num_features; ++i) {
@@ -163,13 +163,13 @@ int feature_extraction_pipeline(int argc, char** argv) {
         }
         string value;
         datum.SerializeToString(&value);
-        snprintf(key_str, kMaxKeyStrLength, "%d", image_index);
+        snprintf(key_str, kMaxKeyStrLength, "%d", image_indices[i]);
         feature_batches[i]->Put(string(key_str), value);
-        ++image_index;
-        if (image_index % 1000 == 0) {
+        ++image_indices[i];
+        if (image_indices[i] % 1000 == 0) {
           feature_dbs[i]->Write(leveldb::WriteOptions(), feature_batches[i]);
-          LOG(ERROR)<< "Extracted features of " << image_index <<
-              " query images.";
+          LOG(ERROR)<< "Extracted features of " << image_indices[i] <<
+              " query images for feature blob " << blob_names[i];
           delete feature_batches[i];
           feature_batches[i] = new leveldb::WriteBatch();
         }
@@ -177,12 +177,12 @@ int feature_extraction_pipeline(int argc, char** argv) {
     }  // for (int i = 0; i < num_features; ++i)
   }  // for (int batch_index = 0; batch_index < num_mini_batches; ++batch_index)
   // write the last batch
-  if (image_index % 1000 != 0) {
-    for (int i = 0; i < num_features; ++i) {
+  for (int i = 0; i < num_features; ++i) {
+    if (image_indices[i] % 1000 != 0) {
       feature_dbs[i]->Write(leveldb::WriteOptions(), feature_batches[i]);
     }
-    LOG(ERROR)<< "Extracted features of " << image_index <<
-        " query images.";
+    LOG(ERROR)<< "Extracted features of " << image_indices[i] <<
+        " query images for feature blob " << blob_names[i];
   }
 
   for (int i = 0; i < num_features; ++i) {