-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaffe_batch_classifier.h
More file actions
43 lines (32 loc) · 1.13 KB
/
Copy pathcaffe_batch_classifier.h
File metadata and controls
43 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef CAFFE_BATCH_CLASSIFIER_H
#define CAFFE_BATCH_CLASSIFIER_H
using namespace caffe; // NOLINT(build/namespaces)
//using std::string;
/* Pair (label, confidence) representing a prediction. */
typedef std::pair<string, float> Prediction;
class BatchClassifier {
public:
BatchClassifier(
const string& model_file,
const string& trained_file,
const string& mean_file,
const string& label_file,
const bool use_GPU,
const int batch_size);
std::vector<vector<Prediction>> Classify(const std::vector<cv::Mat> imgs, const size_t top_n);
private:
void SetMean(const string& mean_file);
std::vector<float> Predict(const std::vector<cv::Mat> imgs);
void WrapInputLayer(std::vector<std::vector<cv::Mat>> *input_batch);
void Preprocess(const vector<cv::Mat> imgs,
std::vector<std::vector<cv::Mat>> *input_batch);
private:
std::shared_ptr<caffe::Net<float>> net_;
cv::Size input_geometry_;
int num_channels_;
cv::Mat mean_;
std::vector<std::string> labels_;
int num_classes_;
int batch_size_;
};
#endif //CAFFE_BATCH_CLASSIFIER_H