| 44 | "Optional: What type should we encode the image as ('png','jpg',...)."); |
| 45 | |
| 46 | int main(int argc, char** argv) { |
| 47 | #ifdef USE_OPENCV |
| 48 | ::google::InitGoogleLogging(argv[0]); |
| 49 | // Print output to stderr (while still logging) |
| 50 | FLAGS_alsologtostderr = 1; |
| 51 | |
| 52 | #ifndef GFLAGS_GFLAGS_H_ |
| 53 | namespace gflags = google; |
| 54 | #endif |
| 55 | |
| 56 | gflags::SetUsageMessage("Convert a set of images to the leveldb/lmdb\n" |
| 57 | "format used as input for Caffe.\n" |
| 58 | "Usage:\n" |
| 59 | " convert_imageset [FLAGS] ROOTFOLDER/ LISTFILE DB_NAME\n" |
| 60 | "The ImageNet dataset for the training demo is at\n" |
| 61 | " http://www.image-net.org/download-images\n"); |
| 62 | gflags::ParseCommandLineFlags(&argc, &argv, true); |
| 63 | |
| 64 | if (argc < 4) { |
| 65 | gflags::ShowUsageWithFlagsRestrict(argv[0], "tools/convert_imageset"); |
| 66 | return 1; |
| 67 | } |
| 68 | |
| 69 | const bool is_color = !FLAGS_gray; |
| 70 | const bool check_size = FLAGS_check_size; |
| 71 | const bool encoded = FLAGS_encoded; |
| 72 | const string encode_type = FLAGS_encode_type; |
| 73 | |
| 74 | std::ifstream infile(argv[2]); |
| 75 | std::vector<std::pair<std::string, int> > lines; |
| 76 | std::string line; |
| 77 | size_t pos; |
| 78 | int label; |
| 79 | while (std::getline(infile, line)) { |
| 80 | pos = line.find_last_of(' '); |
| 81 | label = atoi(line.substr(pos + 1).c_str()); |
| 82 | lines.push_back(std::make_pair(line.substr(0, pos), label)); |
| 83 | } |
| 84 | if (FLAGS_shuffle) { |
| 85 | // randomly shuffle data |
| 86 | LOG(INFO) << "Shuffling data"; |
| 87 | shuffle(lines.begin(), lines.end()); |
| 88 | } |
| 89 | LOG(INFO) << "A total of " << lines.size() << " images."; |
| 90 | |
| 91 | if (encode_type.size() && !encoded) |
| 92 | LOG(INFO) << "encode_type specified, assuming encoded=true."; |
| 93 | |
| 94 | int resize_height = std::max<int>(0, FLAGS_resize_height); |
| 95 | int resize_width = std::max<int>(0, FLAGS_resize_width); |
| 96 | |
| 97 | // Create new DB |
| 98 | scoped_ptr<db::DB> db(db::GetDB(FLAGS_backend)); |
| 99 | db->Open(argv[3], db::NEW); |
| 100 | scoped_ptr<db::Transaction> txn(db->NewTransaction()); |
| 101 | |
| 102 | // Storing to db |
| 103 | std::string root_folder(argv[1]); |
nothing calls this directly
no test coverage detected