MCPcopy Create free account
hub / github.com/BVLC/caffe / TestReadCrop

Method TestReadCrop

src/caffe/test/test_data_layer.cpp:199–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197 }
198
199 void TestReadCrop(Phase phase) {
200 const Dtype scale = 3;
201 LayerParameter param;
202 param.set_phase(phase);
203 Caffe::set_random_seed(1701);
204
205 DataParameter* data_param = param.mutable_data_param();
206 data_param->set_batch_size(5);
207 data_param->set_source(filename_->c_str());
208 data_param->set_backend(backend_);
209
210 TransformationParameter* transform_param =
211 param.mutable_transform_param();
212 transform_param->set_scale(scale);
213 transform_param->set_crop_size(1);
214
215 DataLayer<Dtype> layer(param);
216 layer.SetUp(blob_bottom_vec_, blob_top_vec_);
217 EXPECT_EQ(blob_top_data_->num(), 5);
218 EXPECT_EQ(blob_top_data_->channels(), 2);
219 EXPECT_EQ(blob_top_data_->height(), 1);
220 EXPECT_EQ(blob_top_data_->width(), 1);
221 EXPECT_EQ(blob_top_label_->num(), 5);
222 EXPECT_EQ(blob_top_label_->channels(), 1);
223 EXPECT_EQ(blob_top_label_->height(), 1);
224 EXPECT_EQ(blob_top_label_->width(), 1);
225
226 for (int iter = 0; iter < 2; ++iter) {
227 layer.Forward(blob_bottom_vec_, blob_top_vec_);
228 for (int i = 0; i < 5; ++i) {
229 EXPECT_EQ(i, blob_top_label_->cpu_data()[i]);
230 }
231 int num_with_center_value = 0;
232 for (int i = 0; i < 5; ++i) {
233 for (int j = 0; j < 2; ++j) {
234 const Dtype center_value = scale * (j ? 17 : 5);
235 num_with_center_value +=
236 (center_value == blob_top_data_->cpu_data()[i * 2 + j]);
237 // At TEST time, check that we always get center value.
238 if (phase == caffe::TEST) {
239 EXPECT_EQ(center_value, this->blob_top_data_->cpu_data()[i * 2 + j])
240 << "debug: iter " << iter << " i " << i << " j " << j;
241 }
242 }
243 }
244 // At TRAIN time, check that we did not get the center crop all 10 times.
245 // (This check fails with probability 1-1/12^10 in a correct
246 // implementation, so we call set_random_seed.)
247 if (phase == caffe::TRAIN) {
248 EXPECT_LT(num_with_center_value, 10);
249 }
250 }
251 }
252
253 void TestReadCropTrainSequenceSeeded() {
254 LayerParameter param;

Callers 1

TYPED_TESTFunction · 0.80

Calls 10

set_random_seedFunction · 0.85
set_batch_sizeMethod · 0.80
set_scaleMethod · 0.80
numMethod · 0.80
ForwardMethod · 0.80
SetUpMethod · 0.45
channelsMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
cpu_dataMethod · 0.45

Tested by

no test coverage detected