1 #ifndef _RAPID_PERCEPTION_IMAGE_RECOGNITION_H_
2 #define _RAPID_PERCEPTION_IMAGE_RECOGNITION_H_
9 #include "boost/shared_ptr.hpp"
10 #include "caffe/blob.hpp"
11 #include "caffe/common.hpp"
12 #include "caffe/net.hpp"
13 #include "caffe/proto/caffe.pb.h"
14 #include "opencv2/opencv.hpp"
17 namespace perception {
33 ImageRecognizer(boost::shared_ptr<caffe::Net<float> > feature_extraction_net,
34 cv::Mat mean, cv::Size input_geometry,
int num_channels,
35 const std::vector<std::string>& labels);
38 cv::Mat
layer(
const std::string& layer_name, std::string* error);
39 std::vector<std::pair<std::string, float> >
predictions(
int num_predictions,
45 void ForwardPass(std::string* error);
46 std::vector<float> Predict(
const cv::Mat& image, std::string* error);
47 void Preprocess(
const cv::Mat& img, std::vector<cv::Mat>* input_channels,
49 void WrapInputLayer(std::vector<cv::Mat>* input_channels);
51 static bool BuildFromFiles(
const std::string& model_prototxt,
52 const std::string& pretrained_caffemodel,
53 const std::string& mean_binaryproto,
54 const std::string& labels_file,
57 boost::shared_ptr<caffe::Net<float> > net_;
60 cv::Size input_geometry_;
62 std::vector<std::string> labels_;
68 const cv::Size& input_geometry,
int num_channels,
69 std::string* error = NULL);
71 static bool PairCompare(
const std::pair<float, int>& lhs,
72 const std::pair<float, int>& rhs);
75 static std::vector<int>
Argmax(
const std::vector<float>& v,
int N);
79 #endif // _RAPID_PERCEPTION_IMAGE_RECOGNITION_H_
static bool PairCompare(const std::pair< float, int > &lhs, const std::pair< float, int > &rhs)
std::vector< std::pair< std::string, float > > predictions(int num_predictions, std::string *error)
static std::vector< int > Argmax(const std::vector< float > &v, int N)
void set_image(const cv::Mat &image)
cv::Mat ReadMeanFile(const std::string &mean_file, const cv::Size &input_geometry, int num_channels, std::string *error=NULL)
cv::Mat layer(const std::string &layer_name, std::string *error)
static bool AlexNet(std::string model_dir, ImageRecognizer *recognizer, std::string *error)