diff options
author | Tea <tea.desouza@gmail.com> | 2015-11-17 17:05:56 +0800 |
---|---|---|
committer | Tea <tea.desouza@gmail.com> | 2015-11-26 09:54:12 +0800 |
commit | b72b0318e2802785c17be1fe8ed1b6899961df19 (patch) | |
tree | efa7a1a24c420de673a7ebee343b3b1f68079907 /tools | |
parent | 8e8d97d6206cac99eae3c16baaa2275a14e64ca7 (diff) | |
download | caffeonacl-b72b0318e2802785c17be1fe8ed1b6899961df19.tar.gz caffeonacl-b72b0318e2802785c17be1fe8ed1b6899961df19.tar.bz2 caffeonacl-b72b0318e2802785c17be1fe8ed1b6899961df19.zip |
replace snprintf with a C++98 equivalent
Diffstat (limited to 'tools')
-rw-r--r-- | tools/convert_imageset.cpp | 8 | ||||
-rw-r--r-- | tools/extract_features.cpp | 11 |
2 files changed, 7 insertions, 12 deletions
diff --git a/tools/convert_imageset.cpp b/tools/convert_imageset.cpp index e51a2631..9c52bfa0 100644 --- a/tools/convert_imageset.cpp +++ b/tools/convert_imageset.cpp @@ -20,6 +20,7 @@ #include "caffe/proto/caffe.pb.h" #include "caffe/util/db.hpp" +#include "caffe/util/format.hpp" #include "caffe/util/io.hpp" #include "caffe/util/rng.hpp" @@ -99,8 +100,6 @@ int main(int argc, char** argv) { std::string root_folder(argv[1]); Datum datum; int count = 0; - const int kMaxKeyLength = 256; - char key_cstr[kMaxKeyLength]; int data_size = 0; bool data_size_initialized = false; @@ -131,13 +130,12 @@ int main(int argc, char** argv) { } } // sequential - int length = snprintf(key_cstr, kMaxKeyLength, "%08d_%s", line_id, - lines[line_id].first.c_str()); + string key_str = caffe::format_int(line_id, 8) + "_" + lines[line_id].first; // Put in db string out; CHECK(datum.SerializeToString(&out)); - txn->Put(string(key_cstr, length), out); + txn->Put(key_str, out); if (++count % 1000 == 0) { // Commit db diff --git a/tools/extract_features.cpp b/tools/extract_features.cpp index 084c9bf8..b94dbb98 100644 --- a/tools/extract_features.cpp +++ b/tools/extract_features.cpp @@ -1,4 +1,3 @@ -#include <stdio.h> // for snprintf #include <string> #include <vector> @@ -10,6 +9,7 @@ #include "caffe/net.hpp" #include "caffe/proto/caffe.pb.h" #include "caffe/util/db.hpp" +#include "caffe/util/format.hpp" #include "caffe/util/io.hpp" #include "caffe/vision_layers.hpp" @@ -135,8 +135,6 @@ int feature_extraction_pipeline(int argc, char** argv) { LOG(ERROR)<< "Extacting Features"; Datum datum; - const int kMaxKeyStrLength = 100; - char key_str[kMaxKeyStrLength]; std::vector<Blob<float>*> input_vec; std::vector<int> image_indices(num_features, 0); for (int batch_index = 0; batch_index < num_mini_batches; ++batch_index) { @@ -158,11 +156,11 @@ int feature_extraction_pipeline(int argc, char** argv) { for (int d = 0; d < dim_features; ++d) { datum.add_float_data(feature_blob_data[d]); } - int length = snprintf(key_str, kMaxKeyStrLength, "%010d", - image_indices[i]); + string key_str = caffe::format_int(image_indices[i], 10); + string out; CHECK(datum.SerializeToString(&out)); - txns.at(i)->Put(std::string(key_str, length), out); + txns.at(i)->Put(key_str, out); ++image_indices[i]; if (image_indices[i] % 1000 == 0) { txns.at(i)->Commit(); @@ -186,4 +184,3 @@ int feature_extraction_pipeline(int argc, char** argv) { LOG(ERROR)<< "Successfully extracted the features!"; return 0; } - |