glog, protobuf, gflag, snappy, leveldb, gtest
All are open libraries by Google
(Wow, they like Google very much)
There are still benchmark library and so on
Google LOGging library
Initialize
#include <glog/logging.h>
int main(int argc, char* argv[]) {
google::InitGoogleLogging(argv[0]);
// INFO, WARNING, ERROR, FETAL
LOG(INFO) << "Your code is running";
LOG_IF(WARNING, speedup < 1.0)
<< "Your median filter is "
<< speedup << "x slower";
LOG_FIRST_N(INFO, 20) << google::COUNTER;
LOG_IF_EVERY_N(INFO, (size > 1024), 10) << google::COUNTER;
DLOG(INFO) << "Won't appear using NDEBUG";
CHECK(random() <= RAND_MAX) << "Your library has bug";
CHECK_NE(1, 2) << "Your compiler has bug";
CHECK_NOTNULL(some_ptr); // Return the pointer itself, so do not use <<
FLAGS_v = 1;
VLOG(0) << "This will not be printed";
VLOG(100) << "This will be printed";
You may usually set FLAGS_* variables
Data serializer
Here, we use the term "serialization" to mean the reversible deconstruction of an arbitrary set of C++ data structures to a sequence of bytes.From boost serialization library
(Caffe use it to store network)
struct Member {
void from_file(FILE *fp) {
fread(...
Language 1
class Member:
def from_file(self, fp):
fp.read...
Language 2
package tutorial;
message Person {
required string name = 1;
required int32 id = 2;
optional bool isMale = 3;
repeated string email = 4;
}
Compile to different target language
Reading/Writing file
using namespace tutorial; // Correspond to "package tutorial;"
fstream in("in", ios::in | ios::binary);
ostream out("out", ios::out | ios::binary);
Person person;
person.ParseFromIstream(&in);
person.SerializeToOstream(&out);
Generated code will has (but is not limited to) these APIs
person.id();
person.clear_id();
person.set_id();
person.has_id();
person.email(); // return a vector like object
person.email(123); // repeated only
person.email_size(); // repeated only
person.add_email(); // repeated only
A simple example
TEST(PrimeTest, Positive) {
EXPECT_TRUE(IsPrime(2));
EXPECT_TRUE(IsPrime(199));
EXPECT_FALSE(IsPrime(2000));
}
TEST(PrimeTest, Invalid) {
EXPECT_FALSE(IsPrime(0));
EXPECT_FALSE(IsPrime(-9999));
}
int main() {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
self-explanatory, I think
getopt
boost
OK I like to draw by myself.
1 is included in 2 so I will only talk about 2
Define in protobuf text format
name: "LogReg"
layers {
name: "mnist"
type: DATA
top: "data"
top: "label"
data_param {
source: "input_leveldb"
batch_size: 64
}
}
...
Description text file
Kongou.jpg 1
Yamato.jpg 1
Bismarck.jpg 1
Akagi.jpg 2
Shoukaku.jpg 2
Yukikaze.jpg 3
Hibiki.jpg 3
Fubuki.jpg 3
...
And put these images into a directory
← If we want to classify: (1)battleship, (2)aircraft carrier or (3)destroyer
convert_imageset \
<dir> <txt> <output> \
[1] [-backend leveldb] [w h]
caffe train -solver your_solver.prototxt
net:
to specify your net fileinclude: { phase: TEST/TRAIN }
Caffe run 1 test phase after several train phases as long as you define in your solver
See Alexnet for example