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

Method TestForwardSquare

src/caffe/test/test_pooling_layer.cpp:641–711  ·  view source on GitHub ↗

Test for 2x 2 square pooling layer

Source from the content-addressed store, hash-verified

639 vector<Blob<Dtype>*> blob_top_vec_;
640 // Test for 2x 2 square pooling layer
641 void TestForwardSquare() {
642 LayerParameter layer_param;
643 PoolingParameter* pooling_param = layer_param.mutable_pooling_param();
644 pooling_param->set_kernel_size(2);
645 pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);
646 const int num = 2;
647 const int channels = 2;
648 blob_bottom_->Reshape(num, channels, 3, 5);
649 // Input: 2x 2 channels of:
650 // [1 2 5 2 3]
651 // [9 4 1 4 8]
652 // [1 2 5 2 3]
653 for (int i = 0; i < 15 * num * channels; i += 15) {
654 blob_bottom_->mutable_cpu_data()[i + 0] = 1;
655 blob_bottom_->mutable_cpu_data()[i + 1] = 2;
656 blob_bottom_->mutable_cpu_data()[i + 2] = 5;
657 blob_bottom_->mutable_cpu_data()[i + 3] = 2;
658 blob_bottom_->mutable_cpu_data()[i + 4] = 3;
659 blob_bottom_->mutable_cpu_data()[i + 5] = 9;
660 blob_bottom_->mutable_cpu_data()[i + 6] = 4;
661 blob_bottom_->mutable_cpu_data()[i + 7] = 1;
662 blob_bottom_->mutable_cpu_data()[i + 8] = 4;
663 blob_bottom_->mutable_cpu_data()[i + 9] = 8;
664 blob_bottom_->mutable_cpu_data()[i + 10] = 1;
665 blob_bottom_->mutable_cpu_data()[i + 11] = 2;
666 blob_bottom_->mutable_cpu_data()[i + 12] = 5;
667 blob_bottom_->mutable_cpu_data()[i + 13] = 2;
668 blob_bottom_->mutable_cpu_data()[i + 14] = 3;
669 }
670 CuDNNPoolingLayer<Dtype> layer(layer_param);
671 layer.SetUp(blob_bottom_vec_, blob_top_vec_);
672 EXPECT_EQ(blob_top_->num(), num);
673 EXPECT_EQ(blob_top_->channels(), channels);
674 EXPECT_EQ(blob_top_->height(), 2);
675 EXPECT_EQ(blob_top_->width(), 4);
676 if (blob_top_vec_.size() > 1) {
677 EXPECT_EQ(blob_top_mask_->num(), num);
678 EXPECT_EQ(blob_top_mask_->channels(), channels);
679 EXPECT_EQ(blob_top_mask_->height(), 2);
680 EXPECT_EQ(blob_top_mask_->width(), 4);
681 }
682 layer.Forward(blob_bottom_vec_, blob_top_vec_);
683 // Expected output: 2x 2 channels of:
684 // [9 5 5 8]
685 // [9 5 5 8]
686 for (int i = 0; i < 8 * num * channels; i += 8) {
687 EXPECT_EQ(blob_top_->cpu_data()[i + 0], 9);
688 EXPECT_EQ(blob_top_->cpu_data()[i + 1], 5);
689 EXPECT_EQ(blob_top_->cpu_data()[i + 2], 5);
690 EXPECT_EQ(blob_top_->cpu_data()[i + 3], 8);
691 EXPECT_EQ(blob_top_->cpu_data()[i + 4], 9);
692 EXPECT_EQ(blob_top_->cpu_data()[i + 5], 5);
693 EXPECT_EQ(blob_top_->cpu_data()[i + 6], 5);
694 EXPECT_EQ(blob_top_->cpu_data()[i + 7], 8);
695 }
696 if (blob_top_vec_.size() > 1) {
697 // Expected mask output: 2x 2 channels of:
698 // [5 2 2 9]

Callers

nothing calls this directly

Calls 10

numMethod · 0.80
ForwardMethod · 0.80
ReshapeMethod · 0.45
mutable_cpu_dataMethod · 0.45
SetUpMethod · 0.45
channelsMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
sizeMethod · 0.45
cpu_dataMethod · 0.45

Tested by

no test coverage detected