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

Function feature_extraction_pipeline

tools/extract_features.cpp:31–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30template<typename Dtype>
31int feature_extraction_pipeline(int argc, char** argv) {
32 ::google::InitGoogleLogging(argv[0]);
33 const int num_required_args = 7;
34 if (argc < num_required_args) {
35 LOG(ERROR)<<
36 "This program takes in a trained network and an input data layer, and then"
37 " extract features of the input data produced by the net.\n"
38 "Usage: extract_features pretrained_net_param"
39 " feature_extraction_proto_file extract_feature_blob_name1[,name2,...]"
40 " save_feature_dataset_name1[,name2,...] num_mini_batches db_type"
41 " [CPU/GPU] [DEVICE_ID=0]\n"
42 "Note: you can extract multiple features in one pass by specifying"
43 " multiple feature blob names and dataset names separated by ','."
44 " The names cannot contain white space characters and the number of blobs"
45 " and datasets must be equal.";
46 return 1;
47 }
48 int arg_pos = num_required_args;
49
50 arg_pos = num_required_args;
51 if (argc > arg_pos && strcmp(argv[arg_pos], "GPU") == 0) {
52 LOG(ERROR)<< "Using GPU";
53 int device_id = 0;
54 if (argc > arg_pos + 1) {
55 device_id = atoi(argv[arg_pos + 1]);
56 CHECK_GE(device_id, 0);
57 }
58 LOG(ERROR) << "Using Device_id=" << device_id;
59 Caffe::SetDevice(device_id);
60 Caffe::set_mode(Caffe::GPU);
61 } else {
62 LOG(ERROR) << "Using CPU";
63 Caffe::set_mode(Caffe::CPU);
64 }
65
66 arg_pos = 0; // the name of the executable
67 std::string pretrained_binary_proto(argv[++arg_pos]);
68
69 // Expected prototxt contains at least one data layer such as
70 // the layer data_layer_name and one feature blob such as the
71 // fc7 top blob to extract features.
72 /*
73 layers {
74 name: "data_layer_name"
75 type: DATA
76 data_param {
77 source: "/path/to/your/images/to/extract/feature/images_leveldb"
78 mean_file: "/path/to/your/image_mean.binaryproto"
79 batch_size: 128
80 crop_size: 227
81 mirror: false
82 }
83 top: "data_blob_name"
84 top: "label_blob_name"
85 }
86 layers {
87 name: "drop7"
88 type: DROPOUT

Callers

nothing calls this directly

Calls 15

GetDBFunction · 0.85
format_intFunction · 0.85
CopyTrainedLayersFromMethod · 0.80
has_blobMethod · 0.80
ForwardMethod · 0.80
blob_by_nameMethod · 0.80
numMethod · 0.80
countMethod · 0.80
offsetMethod · 0.80
sizeMethod · 0.45
OpenMethod · 0.45
NewTransactionMethod · 0.45

Tested by

no test coverage detected