| @@ -17,18 +17,17 @@ | |||
| #include "layer.h" | |||
| #include "layer/roipooling.h" | |||
| static int RandomInt(float a = -2.f, float b = 2.f) | |||
| { | |||
| return RandomFloat( a, b ) / 1; | |||
| } | |||
| static int test_roipooling(int w, int h, int c, int pooled_width, int pooled_height, float spatial_scale) | |||
| { | |||
| std::vector<ncnn::Mat> a; | |||
| int num_rois = RandomInt(2, 1000); | |||
| for(int i=0; i<num_rois; i++){ | |||
| a.push_back(RandomMat(w + RandomInt(0, 15), h + RandomInt(0, 13), c)); | |||
| } | |||
| a.push_back(RandomMat(w, h, c)); | |||
| ncnn::Mat b(4); | |||
| b[0] = RandomFloat(0.001 , w-2.001); //roi_x1 | |||
| b[2] = RandomFloat(b[0]+1.001, w-1.001); //roi_x2 | |||
| b[1] = RandomFloat(0.001 , h-2.001); //roi_y1 | |||
| b[3] = RandomFloat(b[2]+1.001, h-1.001); //roi_y2 | |||
| a.push_back(b); | |||
| ncnn::ParamDict pd; | |||
| pd.set(0, pooled_width); // pooled_width | |||
| @@ -49,7 +48,7 @@ static int test_roipooling(int w, int h, int c, int pooled_width, int pooled_hei | |||
| int ret = test_layer<ncnn::ROIPooling>("ROIPooling", pd, weights, opt, a); | |||
| if (ret != 0) | |||
| { | |||
| fprintf(stderr, "test_roipooling failed base_w=%d base_h=%d base_c=%d num_rois=%d pooled_width=%d pooled_height=%d spatial_scale=%4f.3\n", w, h, c, num_rois, pooled_width, pooled_height, spatial_scale); | |||
| fprintf(stderr, "test_roipooling failed base_w=%d base_h=%d base_c=%d pooled_width=%d pooled_height=%d spatial_scale=%4f.3\n", w, h, c, pooled_width, pooled_height, spatial_scale); | |||
| } | |||
| return ret; | |||
| @@ -57,62 +56,16 @@ static int test_roipooling(int w, int h, int c, int pooled_width, int pooled_hei | |||
| static int test_roipooling_0() | |||
| { | |||
| for (int i=0; i<11; i++) | |||
| { | |||
| int ret = 0 | |||
| || test_roipooling(2, 2, 81, 4, 4, 0.0156) | |||
| || test_roipooling(4, 4, 27, 7, 7, 0.0312) | |||
| || test_roipooling(9, 9, 9, 14, 14, 0.0625) | |||
| || test_roipooling(15, 21, 81, 8, 6, 0.0123) | |||
| || test_roipooling(17, 23, 27, 27, 17, 0.0370) | |||
| || test_roipooling(19, 25, 9, 80, 53, 0.1111) | |||
| ; | |||
| if (ret != 0) | |||
| return -1; | |||
| } | |||
| return 0; | |||
| } | |||
| static int test_roipooling_1() | |||
| { | |||
| for (int i=0; i<11; i++) | |||
| { | |||
| int ret = 0 | |||
| || test_roipooling(2, 2, 27, 4, 4, 0.0156) | |||
| || test_roipooling(4, 4, 9, 7, 7, 0.0312) | |||
| || test_roipooling(9, 9, 3, 14, 14, 0.0625) | |||
| || test_roipooling(4, 21, 27, 12, 9, 0.0123) | |||
| || test_roipooling(17, 23, 9, 38, 29, 0.0370) | |||
| || test_roipooling(105, 65, 3, 113, 85, 0.1111) | |||
| ; | |||
| if (ret != 0) | |||
| return -1; | |||
| } | |||
| return 0; | |||
| } | |||
| static int test_roipooling_2() | |||
| { | |||
| for (int i=0; i<11; i++) | |||
| { | |||
| int ret = 0 | |||
| || test_roipooling(4, 7, 1, 4, 5, 0.0156) | |||
| || test_roipooling(6, 11, 2, 6, 7, 0.0312) | |||
| || test_roipooling(9, 17, 3, 14, 17, 0.0625) | |||
| || test_roipooling(13, 19, 4, 15, 18, 0.1250) | |||
| || test_roipooling(15, 21, 7, 18, 21, 0.0123) | |||
| || test_roipooling(17, 23, 8, 21, 25, 0.0370) | |||
| || test_roipooling(19, 25, 15, 21, 26, 0.1111) | |||
| || test_roipooling(23, 31, 16, 25, 34, 0.3333) | |||
| ; | |||
| int ret = 0 | |||
| || test_roipooling(112, 112, 16 , 56, 56, 0.50000) | |||
| || test_roipooling(56 , 56 , 32 , 28, 28, 0.25000) | |||
| || test_roipooling(28 , 28 , 64 , 14, 14, 0.12500) | |||
| || test_roipooling(14 , 14 , 128, 27, 17, 0.06250) | |||
| || test_roipooling(7 , 7 , 256, 3, 3, 0.03125) | |||
| ; | |||
| if (ret != 0) | |||
| return -1; | |||
| } | |||
| if (ret != 0) | |||
| return -1; | |||
| return 0; | |||
| } | |||
| @@ -123,7 +76,5 @@ int main() | |||
| return 0 | |||
| || test_roipooling_0() | |||
| || test_roipooling_1() | |||
| || test_roipooling_2() | |||
| ; | |||
| } | |||