MCPcopy Create free account
hub / github.com/BVLC/caffe / main

Function main

tools/compute_image_mean.cpp:24–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 "The backend {leveldb, lmdb} containing the images");
23
24int main(int argc, char** argv) {
25#ifdef USE_OPENCV
26 ::google::InitGoogleLogging(argv[0]);
27 // Print output to stderr (while still logging)
28 FLAGS_alsologtostderr = 1;
29
30#ifndef GFLAGS_GFLAGS_H_
31 namespace gflags = google;
32#endif
33
34 gflags::SetUsageMessage("Compute the mean_image of a set of images given by"
35 " a leveldb/lmdb\n"
36 "Usage:\n"
37 " compute_image_mean [FLAGS] INPUT_DB [OUTPUT_FILE]\n");
38
39 gflags::ParseCommandLineFlags(&argc, &argv, true);
40
41 if (argc < 2 || argc > 3) {
42 gflags::ShowUsageWithFlagsRestrict(argv[0], "tools/compute_image_mean");
43 return 1;
44 }
45
46 scoped_ptr<db::DB> db(db::GetDB(FLAGS_backend));
47 db->Open(argv[1], db::READ);
48 scoped_ptr<db::Cursor> cursor(db->NewCursor());
49
50 BlobProto sum_blob;
51 int count = 0;
52 // load first datum
53 Datum datum;
54 datum.ParseFromString(cursor->value());
55
56 if (DecodeDatumNative(&datum)) {
57 LOG(INFO) << "Decoding Datum";
58 }
59
60 sum_blob.set_num(1);
61 sum_blob.set_channels(datum.channels());
62 sum_blob.set_height(datum.height());
63 sum_blob.set_width(datum.width());
64 const int data_size = datum.channels() * datum.height() * datum.width();
65 int size_in_datum = std::max<int>(datum.data().size(),
66 datum.float_data_size());
67 for (int i = 0; i < size_in_datum; ++i) {
68 sum_blob.add_data(0.);
69 }
70 LOG(INFO) << "Starting iteration";
71 while (cursor->valid()) {
72 Datum datum;
73 datum.ParseFromString(cursor->value());
74 DecodeDatumNative(&datum);
75
76 const std::string& data = datum.data();
77 size_in_datum = std::max<int>(datum.data().size(),
78 datum.float_data_size());
79 CHECK_EQ(size_in_datum, data_size) << "Incorrect data field size " <<
80 size_in_datum;
81 if (data.size() != 0) {

Callers

nothing calls this directly

Calls 13

GetDBFunction · 0.85
DecodeDatumNativeFunction · 0.85
dataMethod · 0.80
WriteProtoToBinaryFileFunction · 0.50
OpenMethod · 0.45
NewCursorMethod · 0.45
valueMethod · 0.45
channelsMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
sizeMethod · 0.45
validMethod · 0.45

Tested by

no test coverage detected