Caffe
data_transformer.hpp
1 #ifndef CAFFE_DATA_TRANSFORMER_HPP
2 #define CAFFE_DATA_TRANSFORMER_HPP
3 
4 #include <vector>
5 
6 #include "caffe/blob.hpp"
7 #include "caffe/common.hpp"
8 #include "caffe/proto/caffe.pb.h"
9 
10 namespace caffe {
11 
16 template <typename Dtype>
18  public:
19  explicit DataTransformer(const TransformationParameter& param, Phase phase);
20  virtual ~DataTransformer() {}
21 
26  void InitRand();
27 
38  void Transform(const Datum& datum, Blob<Dtype>* transformed_blob);
39 
50  void Transform(const vector<Datum> & datum_vector,
51  Blob<Dtype>* transformed_blob);
52 
53 #ifdef USE_OPENCV
54 
64  void Transform(const vector<cv::Mat> & mat_vector,
65  Blob<Dtype>* transformed_blob);
66 
77  void Transform(const cv::Mat& cv_img, Blob<Dtype>* transformed_blob);
78 #endif // USE_OPENCV
79 
91  void Transform(Blob<Dtype>* input_blob, Blob<Dtype>* transformed_blob);
92 
100  vector<int> InferBlobShape(const Datum& datum);
109  vector<int> InferBlobShape(const vector<Datum> & datum_vector);
118 #ifdef USE_OPENCV
119  vector<int> InferBlobShape(const vector<cv::Mat> & mat_vector);
127  vector<int> InferBlobShape(const cv::Mat& cv_img);
128 #endif // USE_OPENCV
129 
130  protected:
139  virtual int Rand(int n);
140 
141  void Transform(const Datum& datum, Dtype* transformed_data);
142  // Tranformation parameters
143  TransformationParameter param_;
144 
145 
146  shared_ptr<Caffe::RNG> rng_;
147  Phase phase_;
148  Blob<Dtype> data_mean_;
149  vector<Dtype> mean_values_;
150 };
151 
152 } // namespace caffe
153 
154 #endif // CAFFE_DATA_TRANSFORMER_HPP_
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
vector< int > InferBlobShape(const Datum &datum)
Infers the shape of transformed_blob will have when the transformation is applied to the data...
Definition: data_transformer.cpp:442
Applies common transformations to the input data, such as scaling, mirroring, substracting the image ...
Definition: data_transformer.hpp:17
void InitRand()
Initialize the Random number generations if needed by the transformation.
Definition: data_transformer.cpp:523
virtual int Rand(int n)
Infers the shape of transformed_blob will have when the transformation is applied to the data...
Definition: data_transformer.cpp:535
void Transform(const Datum &datum, Blob< Dtype > *transformed_blob)
Applies the transformation defined in the data layer&#39;s transform_param block to the data...
Definition: data_transformer.cpp:131
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24