MTF
netUtils.h
1 #ifndef MTF_NET_UTILS_H
2 #define MTF_NET_UTILS_H
3 
4 #include <caffe/layers/memory_data_layer.hpp>
5 #include "mtf/Macros/common.h"
6 #include <caffe/caffe.hpp>
7 #include <vector>
8 #include <opencv2/core/core.hpp>
9 #include <opencv2/highgui/highgui.hpp>
10 #include <opencv2/imgproc/imgproc.hpp>
11 #include <iostream>
12 #include <iostream>
13 #include "boost/scoped_ptr.hpp"
14 #include "caffe/util/db.hpp"
15 #include "caffe/util/io.hpp"
16 #include "mtf/SM/RegNetParams.h"
17 
18 using boost::scoped_ptr;
19 using namespace caffe;
20 
21 _MTF_BEGIN_NAMESPACE
22 
23 namespace utils{
24  class MTFNet{
25  public:
27  MTFNet(RegNetParams _rgparams);
28 
29  boost::shared_ptr<caffe::Net<float> > net_; // Network object
30  boost::shared_ptr<caffe::Solver<float > > solver_;
31  cv::Size input_geometry_; // W*H Input Geometry to the network
32  int num_channels_; //Number of Channels
33  cv::Scalar channel_mean_;
34 
35  RegNetParams rgparams;
36 
37  private:
39  void getGPUs(vector<int>* gpus);
40 
41  public:
43  void preprocessBatch(std::vector<cv::Mat>& batch);
44 
46  void extractBatch(int bs, int bi, std::vector<cv::Mat> t_data, std::vector<cv::Mat> t_labels, std::vector<cv::Mat> &t_data_b, std::vector<cv::Mat> &t_labels_b);
47  };
48 
52  MTFNet *createNetwork(RegNetParams rgparams, char *conv_model = nullptr, char *last_conv_layer = nullptr,
53  int n_layers = 2, int *n_neurons = nullptr, char *activ_fn = nullptr);
54 
56  float *forwardPass(MTFNet *network, cv::Mat patch);
57 
59  void train(MTFNet *network, std::vector<cv::Mat> training_data, std::vector<cv::Mat> training_labels);
60 
62  void testingInputBlobs(boost::shared_ptr<caffe::Net<float> > net_);
63 }
64 
65 _MTF_END_NAMESPACE
66 #endif
MTFNet * createNetwork(RegNetParams rgparams, char *conv_model=nullptr, char *last_conv_layer=nullptr, int n_layers=2, int *n_neurons=nullptr, char *activ_fn=nullptr)
Creates Network with first conv layers from conv_model till name of last_conv_layer.
void testingInputBlobs(boost::shared_ptr< caffe::Net< float > > net_)
Tests the Input Blobs and shows images and Label.
void train(MTFNet *network, std::vector< cv::Mat > training_data, std::vector< cv::Mat > training_labels)
Train the network with training_data and labels as input.
float * forwardPass(MTFNet *network, cv::Mat patch)
Forward Pass the patch into the network after being resized to image_size.
basic functions for preprocessing the raw input image using filtering, resizing and histogram equaliz...
Definition: histUtils.h:20
Definition: netUtils.h:24