1 #ifndef CAFFE_DATA_TRANSFORMER_HPP
2 #define CAFFE_DATA_TRANSFORMER_HPP
6 #include "caffe/blob.hpp"
7 #include "caffe/common.hpp"
8 #include "caffe/proto/caffe.pb.h"
13 * @brief Applies common transformations to the input data, such as
14 * scaling, mirroring, substracting the image mean...
16 template <typename Dtype>
17 class DataTransformer {
19 explicit DataTransformer(const TransformationParameter& param, Phase phase);
20 virtual ~DataTransformer() {}
23 * @brief Initialize the Random number generations if needed by the
29 * @brief Applies the transformation defined in the data layer's
30 * transform_param block to the data.
33 * Datum containing the data to be transformed.
34 * @param transformed_blob
35 * This is destination blob. It can be part of top blob's data if
36 * set_cpu_data() is used. See data_layer.cpp for an example.
38 void Transform(const Datum& datum, Blob<Dtype>* transformed_blob);
41 * @brief Applies the transformation defined in the data layer's
42 * transform_param block to a vector of Datum.
45 * A vector of Datum containing the data to be transformed.
46 * @param transformed_blob
47 * This is destination blob. It can be part of top blob's data if
48 * set_cpu_data() is used. See memory_layer.cpp for an example.
50 void Transform(const vector<Datum> & datum_vector,
51 Blob<Dtype>* transformed_blob);
55 * @brief Applies the transformation defined in the data layer's
56 * transform_param block to a vector of Mat.
59 * A vector of Mat containing the data to be transformed.
60 * @param transformed_blob
61 * This is destination blob. It can be part of top blob's data if
62 * set_cpu_data() is used. See memory_layer.cpp for an example.
64 void Transform(const vector<cv::Mat> & mat_vector,
65 Blob<Dtype>* transformed_blob);
68 * @brief Applies the transformation defined in the data layer's
69 * transform_param block to a cv::Mat
72 * cv::Mat containing the data to be transformed.
73 * @param transformed_blob
74 * This is destination blob. It can be part of top blob's data if
75 * set_cpu_data() is used. See image_data_layer.cpp for an example.
77 void Transform(const cv::Mat& cv_img, Blob<Dtype>* transformed_blob);
81 * @brief Applies the same transformation defined in the data layer's
82 * transform_param block to all the num images in a input_blob.
85 * A Blob containing the data to be transformed. It applies the same
86 * transformation to all the num images in the blob.
87 * @param transformed_blob
88 * This is destination blob, it will contain as many images as the
89 * input blob. It can be part of top blob's data.
91 void Transform(Blob<Dtype>* input_blob, Blob<Dtype>* transformed_blob);
94 * @brief Infers the shape of transformed_blob will have when
95 * the transformation is applied to the data.
98 * Datum containing the data to be transformed.
100 vector<int> InferBlobShape(const Datum& datum);
102 * @brief Infers the shape of transformed_blob will have when
103 * the transformation is applied to the data.
104 * It uses the first element to infer the shape of the blob.
106 * @param datum_vector
107 * A vector of Datum containing the data to be transformed.
109 vector<int> InferBlobShape(const vector<Datum> & datum_vector);
111 * @brief Infers the shape of transformed_blob will have when
112 * the transformation is applied to the data.
113 * It uses the first element to infer the shape of the blob.
116 * A vector of Mat containing the data to be transformed.
119 vector<int> InferBlobShape(const vector<cv::Mat> & mat_vector);
121 * @brief Infers the shape of transformed_blob will have when
122 * the transformation is applied to the data.
125 * cv::Mat containing the data to be transformed.
127 vector<int> InferBlobShape(const cv::Mat& cv_img);
132 * @brief Generates a random integer from Uniform({0, 1, ..., n-1}).
135 * The upperbound (exclusive) value of the random number.
137 * A uniformly random integer value from ({0, 1, ..., n-1}).
139 virtual int Rand(int n);
141 void Transform(const Datum& datum, Dtype* transformed_data);
142 // Tranformation parameters
143 TransformationParameter param_;
146 shared_ptr<Caffe::RNG> rng_;
148 Blob<Dtype> data_mean_;
149 vector<Dtype> mean_values_;
154 #endif // CAFFE_DATA_TRANSFORMER_HPP_