| 147 | } |
| 148 | |
| 149 | std::vector<float> Classifier::Predict(const cv::Mat& img) |
| 150 | { |
| 151 | Blob<float>* input_layer = net_->input_blobs()[0]; |
| 152 | input_layer->Reshape(1, num_channels_, input_geometry_.height, input_geometry_.width); |
| 153 | /* Forward dimension change to all layers. */ |
| 154 | net_->Reshape(); |
| 155 | |
| 156 | std::vector<cv::Mat> input_channels; |
| 157 | WrapInputLayer(&input_channels); |
| 158 | |
| 159 | Preprocess(img, &input_channels); |
| 160 | |
| 161 | net_->Forward(); |
| 162 | |
| 163 | /* Copy the output layer to a std::vector */ |
| 164 | Blob<float>* output_layer = net_->output_blobs()[0]; |
| 165 | const float* begin = output_layer->cpu_data(); |
| 166 | const float* end = begin + output_layer->channels(); |
| 167 | return std::vector<float>(begin, end); |
| 168 | } |
| 169 | |
| 170 | /* Wrap the input layer of the network in separate cv::Mat objects |
| 171 | * (one per channel). This way we save one memcpy operation and we |