@@ -44,15 +44,15 @@ namespace caffe2 {
44
44
cv::Mat resizeImage (cv::Mat& img) {
45
45
cv::Mat resized_img;
46
46
int scaled_width, scaled_height;
47
- if (c10:: FLAGS_warp) {
48
- scaled_width = c10:: FLAGS_scale;
49
- scaled_height = c10:: FLAGS_scale;
47
+ if (FLAGS_warp) {
48
+ scaled_width = FLAGS_scale;
49
+ scaled_height = FLAGS_scale;
50
50
} else if (img.rows > img.cols ) {
51
- scaled_width = c10:: FLAGS_scale;
52
- scaled_height = static_cast <float >(img.rows ) * c10:: FLAGS_scale / img.cols ;
51
+ scaled_width = FLAGS_scale;
52
+ scaled_height = static_cast <float >(img.rows ) * FLAGS_scale / img.cols ;
53
53
} else {
54
- scaled_height = c10:: FLAGS_scale;
55
- scaled_width = static_cast <float >(img.cols ) * c10:: FLAGS_scale / img.rows ;
54
+ scaled_height = FLAGS_scale;
55
+ scaled_width = static_cast <float >(img.cols ) * FLAGS_scale / img.rows ;
56
56
}
57
57
cv::resize (
58
58
img,
@@ -87,9 +87,9 @@ std::vector<float> convertToVector(cv::Mat& img) {
87
87
std::vector<float > mean (3 , 0 );
88
88
std::vector<float > std (3 , 1 );
89
89
bool bgrtorgb = false ;
90
- assert (img.cols == c10:: FLAGS_scale);
91
- assert (img.rows == c10:: FLAGS_scale);
92
- vector<string> steps = caffe2::split (' ,' , c10:: FLAGS_preprocess);
90
+ assert (img.cols == FLAGS_scale);
91
+ assert (img.rows == FLAGS_scale);
92
+ vector<string> steps = caffe2::split (' ,' , FLAGS_preprocess);
93
93
for (int i = 0 ; i < steps.size (); i++) {
94
94
auto step = steps[i];
95
95
if (step == " subtract128" ) {
@@ -112,8 +112,8 @@ std::vector<float> convertToVector(cv::Mat& img) {
112
112
}
113
113
}
114
114
115
- int C = c10:: FLAGS_color ? 3 : 1 ;
116
- int total_size = C * c10:: FLAGS_scale * c10:: FLAGS_scale;
115
+ int C = FLAGS_color ? 3 : 1 ;
116
+ int total_size = C * FLAGS_scale * FLAGS_scale;
117
117
std::vector<float > values (total_size);
118
118
if (C == 1 ) {
119
119
cv::MatIterator_<uchar> it, end;
@@ -130,9 +130,9 @@ std::vector<float> convertToVector(cv::Mat& img) {
130
130
for (it = img.begin <cv::Vec3b>(), end = img.end <cv::Vec3b>(); it != end;
131
131
++it, i++) {
132
132
values[i] = (((*it)[b] / normalize[0 ] - mean[0 ]) / std[0 ]);
133
- int offset = c10:: FLAGS_scale * c10:: FLAGS_scale + i;
133
+ int offset = FLAGS_scale * FLAGS_scale + i;
134
134
values[offset] = (((*it)[g] / normalize[1 ] - mean[1 ]) / std[1 ]);
135
- offset = c10:: FLAGS_scale * c10:: FLAGS_scale + offset;
135
+ offset = FLAGS_scale * FLAGS_scale + offset;
136
136
values[offset] = (((*it)[r] / normalize[2 ] - mean[2 ]) / std[2 ]);
137
137
}
138
138
}
@@ -145,8 +145,7 @@ std::vector<float> convertOneImage(std::string& filename) {
145
145
std::cout << " Converting " << filename << std::endl;
146
146
// Load image
147
147
cv::Mat img = cv::imread (
148
- filename,
149
- c10::FLAGS_color ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE);
148
+ filename, FLAGS_color ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE);
150
149
151
150
cv::Mat crop = cropToSquare (img);
152
151
@@ -155,17 +154,17 @@ std::vector<float> convertOneImage(std::string& filename) {
155
154
// Assert we don't have to deal with alignment
156
155
DCHECK (resized_img.isContinuous ());
157
156
assert (resized_img.rows == resized_img.cols );
158
- assert (resized_img.rows == c10:: FLAGS_scale);
157
+ assert (resized_img.rows == FLAGS_scale);
159
158
std::vector<float > one_image_values = convertToVector (resized_img);
160
159
return one_image_values;
161
160
}
162
161
163
162
void convertImages () {
164
163
vector<string> file_names;
165
- if (c10:: FLAGS_input_images != " " ) {
166
- file_names = caffe2::split (' ,' , c10:: FLAGS_input_images);
167
- } else if (c10:: FLAGS_input_image_file != " " ) {
168
- std::ifstream infile (c10:: FLAGS_input_image_file);
164
+ if (FLAGS_input_images != " " ) {
165
+ file_names = caffe2::split (' ,' , FLAGS_input_images);
166
+ } else if (FLAGS_input_image_file != " " ) {
167
+ std::ifstream infile (FLAGS_input_image_file);
169
168
std::string line;
170
169
while (std::getline (infile, line)) {
171
170
vector<string> file_name = caffe2::split (' ,' , line);
@@ -181,7 +180,7 @@ void convertImages() {
181
180
assert (false );
182
181
}
183
182
std::vector<std::vector<float >> values;
184
- int C = c10:: FLAGS_color ? 3 : 1 ;
183
+ int C = FLAGS_color ? 3 : 1 ;
185
184
for (int i = 0 ; i < file_names.size (); i++) {
186
185
std::vector<float > one_image_values = convertOneImage (file_names[i]);
187
186
values.push_back (one_image_values);
@@ -193,19 +192,19 @@ void convertImages() {
193
192
data->set_data_type (TensorProto::FLOAT);
194
193
data->add_dims (values.size ());
195
194
data->add_dims (C);
196
- data->add_dims (c10:: FLAGS_scale);
197
- data->add_dims (c10:: FLAGS_scale);
195
+ data->add_dims (FLAGS_scale);
196
+ data->add_dims (FLAGS_scale);
198
197
199
198
for (int i = 0 ; i < values.size (); i++) {
200
- assert (values[i].size () == C * c10:: FLAGS_scale * c10:: FLAGS_scale);
199
+ assert (values[i].size () == C * FLAGS_scale * FLAGS_scale);
201
200
for (int j = 0 ; j < values[i].size (); j++) {
202
201
data->add_float_data (values[i][j]);
203
202
}
204
203
}
205
- if (c10:: FLAGS_text_output) {
206
- caffe2::WriteProtoToTextFile (protos, c10:: FLAGS_output_tensor);
204
+ if (FLAGS_text_output) {
205
+ caffe2::WriteProtoToTextFile (protos, FLAGS_output_tensor);
207
206
} else {
208
- caffe2::WriteProtoToBinaryFile (protos, c10:: FLAGS_output_tensor);
207
+ caffe2::WriteProtoToBinaryFile (protos, FLAGS_output_tensor);
209
208
}
210
209
}
211
210
0 commit comments