|
|
|
@@ -16,17 +16,15 @@ |
|
|
|
|
|
|
|
#include "layer/innerproduct.h" |
|
|
|
|
|
|
|
static int test_innerproduct(int w, int h, int c, int outch, int bias) |
|
|
|
static int test_innerproduct(const ncnn::Mat& a, int outch, int bias) |
|
|
|
{ |
|
|
|
ncnn::Mat a = RandomMat(w, h, c); |
|
|
|
|
|
|
|
ncnn::ParamDict pd; |
|
|
|
pd.set(0, outch);// num_output |
|
|
|
pd.set(1, bias);// bias_term |
|
|
|
pd.set(2, outch*w*h*c); |
|
|
|
pd.set(2, outch*a.w*a.h*a.c); |
|
|
|
|
|
|
|
std::vector<ncnn::Mat> weights(bias ? 2 : 1); |
|
|
|
weights[0] = RandomMat(outch*w*h*c); |
|
|
|
weights[0] = RandomMat(outch*a.w*a.h*a.c); |
|
|
|
if (bias) |
|
|
|
weights[1] = RandomMat(outch); |
|
|
|
|
|
|
|
@@ -43,7 +41,7 @@ static int test_innerproduct(int w, int h, int c, int outch, int bias) |
|
|
|
int ret = test_layer<ncnn::InnerProduct>("InnerProduct", pd, weights, opt, a); |
|
|
|
if (ret != 0) |
|
|
|
{ |
|
|
|
fprintf(stderr, "test_innerproduct failed w=%d h=%d c=%d outch=%d bias=%d\n", w, h, c, outch, bias); |
|
|
|
fprintf(stderr, "test_innerproduct failed a.dims=%d a=(%d %d %d) outch=%d bias=%d\n", a.dims, a.w, a.h, a.c, outch, bias); |
|
|
|
} |
|
|
|
|
|
|
|
return ret; |
|
|
|
@@ -52,29 +50,55 @@ static int test_innerproduct(int w, int h, int c, int outch, int bias) |
|
|
|
static int test_innerproduct_0() |
|
|
|
{ |
|
|
|
return 0 |
|
|
|
|| test_innerproduct(7, 3, 1, 1, 1) |
|
|
|
|| test_innerproduct(7, 3, 2, 2, 1) |
|
|
|
|| test_innerproduct(7, 3, 3, 3, 1) |
|
|
|
|| test_innerproduct(7, 3, 4, 4, 1) |
|
|
|
|| test_innerproduct(7, 3, 7, 7, 1) |
|
|
|
|| test_innerproduct(7, 3, 8, 8, 1) |
|
|
|
|| test_innerproduct(7, 3, 15, 15, 1) |
|
|
|
|| test_innerproduct(7, 3, 16, 16, 1) |
|
|
|
|| test_innerproduct(RandomMat(1, 3, 1), 1, 1) |
|
|
|
|| test_innerproduct(RandomMat(3, 2, 2), 2, 1) |
|
|
|
|| test_innerproduct(RandomMat(9, 3, 8), 7, 1) |
|
|
|
|| test_innerproduct(RandomMat(2, 2, 8), 8, 1) |
|
|
|
|| test_innerproduct(RandomMat(4, 3, 15), 8, 1) |
|
|
|
|| test_innerproduct(RandomMat(6, 2, 16), 16, 1) |
|
|
|
|| test_innerproduct(RandomMat(6, 2, 16), 7, 1) |
|
|
|
|| test_innerproduct(RandomMat(6, 2, 5), 16, 1) |
|
|
|
; |
|
|
|
} |
|
|
|
|
|
|
|
static int test_innerproduct_1() |
|
|
|
{ |
|
|
|
return 0 |
|
|
|
|| test_innerproduct(RandomMat(1, 1), 1, 1) |
|
|
|
|| test_innerproduct(RandomMat(3, 2), 2, 1) |
|
|
|
|| test_innerproduct(RandomMat(9, 8), 7, 1) |
|
|
|
|| test_innerproduct(RandomMat(2, 8), 8, 1) |
|
|
|
|| test_innerproduct(RandomMat(4, 15), 8, 1) |
|
|
|
|| test_innerproduct(RandomMat(6, 16), 16, 1) |
|
|
|
|| test_innerproduct(RandomMat(6, 16), 7, 1) |
|
|
|
|| test_innerproduct(RandomMat(6, 5), 16, 1) |
|
|
|
; |
|
|
|
} |
|
|
|
|
|
|
|
static int test_innerproduct_int8(int w, int h, int c, int outch, int bias) |
|
|
|
static int test_innerproduct_2() |
|
|
|
{ |
|
|
|
ncnn::Mat a = RandomMat(w, h, c); |
|
|
|
return 0 |
|
|
|
|| test_innerproduct(RandomMat(1), 1, 1) |
|
|
|
|| test_innerproduct(RandomMat(2), 2, 1) |
|
|
|
|| test_innerproduct(RandomMat(8), 7, 1) |
|
|
|
|| test_innerproduct(RandomMat(8), 8, 1) |
|
|
|
|| test_innerproduct(RandomMat(15), 8, 1) |
|
|
|
|| test_innerproduct(RandomMat(16), 16, 1) |
|
|
|
|| test_innerproduct(RandomMat(16), 7, 1) |
|
|
|
|| test_innerproduct(RandomMat(5), 16, 1) |
|
|
|
; |
|
|
|
} |
|
|
|
|
|
|
|
static int test_innerproduct_int8(const ncnn::Mat& a, int outch, int bias) |
|
|
|
{ |
|
|
|
ncnn::ParamDict pd; |
|
|
|
pd.set(0, outch);// num_output |
|
|
|
pd.set(1, bias);// bias_term |
|
|
|
pd.set(2, outch*w*h*c); |
|
|
|
pd.set(2, outch*a.w*a.h*a.c); |
|
|
|
pd.set(8, 1);// int8_scale_term |
|
|
|
|
|
|
|
std::vector<ncnn::Mat> weights(bias ? 4 : 3); |
|
|
|
weights[0] = RandomMat(outch*w*h*c); |
|
|
|
weights[0] = RandomMat(outch*a.w*a.h*a.c); |
|
|
|
if (bias) |
|
|
|
{ |
|
|
|
weights[1] = RandomMat(outch); |
|
|
|
@@ -100,26 +124,26 @@ static int test_innerproduct_int8(int w, int h, int c, int outch, int bias) |
|
|
|
int ret = test_layer<ncnn::InnerProduct>("InnerProduct", pd, weights, opt, a); |
|
|
|
if (ret != 0) |
|
|
|
{ |
|
|
|
fprintf(stderr, "test_innerproduct_int8 failed w=%d h=%d c=%d outch=%d bias=%d\n", w, h, c, outch, bias); |
|
|
|
fprintf(stderr, "test_innerproduct_int8 failed a.dims=%d a=(%d %d %d) outch=%d bias=%d\n", a.dims, a.w, a.h, a.c, outch, bias); |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
static int test_innerproduct_1() |
|
|
|
static int test_innerproduct_3() |
|
|
|
{ |
|
|
|
return 0 |
|
|
|
|| test_innerproduct_int8(7, 3, 1, 1, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 2, 2, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 3, 3, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 3, 12, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 4, 4, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 7, 7, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 8, 3, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 8, 8, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 15, 15, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 16, 4, 1) |
|
|
|
|| test_innerproduct_int8(7, 3, 16, 16, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(1, 3, 1), 1, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(3, 2, 2), 2, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(5, 3, 3), 3, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(7, 2, 3), 12, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(9, 3, 4), 4, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(2, 2, 7), 7, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(4, 3, 8), 3, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(6, 2, 8), 8, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(8, 3, 15), 15, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(7, 2, 16), 4, 1) |
|
|
|
|| test_innerproduct_int8(RandomMat(6, 3, 16), 16, 1) |
|
|
|
; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -127,5 +151,10 @@ int main() |
|
|
|
{ |
|
|
|
SRAND(7767517); |
|
|
|
|
|
|
|
return test_innerproduct_0() || test_innerproduct_1(); |
|
|
|
return 0 |
|
|
|
|| test_innerproduct_0() |
|
|
|
|| test_innerproduct_1() |
|
|
|
|| test_innerproduct_2() |
|
|
|
|| test_innerproduct_3() |
|
|
|
; |
|
|
|
} |