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

Method SetMean

examples/cpp_classification/classification.cpp:120–148  ·  view source on GitHub ↗

Load the mean file in binaryproto format. */

Source from the content-addressed store, hash-verified

118
119/* Load the mean file in binaryproto format. */
120void Classifier::SetMean(const string& mean_file) {
121 BlobProto blob_proto;
122 ReadProtoFromBinaryFileOrDie(mean_file.c_str(), &blob_proto);
123
124 /* Convert from BlobProto to Blob<float> */
125 Blob<float> mean_blob;
126 mean_blob.FromProto(blob_proto);
127 CHECK_EQ(mean_blob.channels(), num_channels_)
128 << "Number of channels of mean file doesn't match input layer.";
129
130 /* The format of the mean file is planar 32-bit float BGR or grayscale. */
131 std::vector<cv::Mat> channels;
132 float* data = mean_blob.mutable_cpu_data();
133 for (int i = 0; i < num_channels_; ++i) {
134 /* Extract an individual channel. */
135 cv::Mat channel(mean_blob.height(), mean_blob.width(), CV_32FC1, data);
136 channels.push_back(channel);
137 data += mean_blob.height() * mean_blob.width();
138 }
139
140 /* Merge the separate channels into a single image. */
141 cv::Mat mean;
142 cv::merge(channels, mean);
143
144 /* Compute the global mean pixel value and create a mean image
145 * filled with this value. */
146 cv::Scalar channel_mean = cv::mean(mean);
147 mean_ = cv::Mat(input_geometry_, mean.type(), channel_mean);
148}
149
150std::vector<float> Classifier::Predict(const cv::Mat& img) {
151 Blob<float>* input_layer = net_->input_blobs()[0];

Callers

nothing calls this directly

Calls 8

MatClass · 0.85
FromProtoMethod · 0.80
channelsMethod · 0.45
mutable_cpu_dataMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected