diff --git a/bin/nnc/cifar-10.c b/bin/nnc/cifar-10.c index 1d52ceaf8..2b2acb106 100644 --- a/bin/nnc/cifar-10.c +++ b/bin/nnc/cifar-10.c @@ -24,16 +24,16 @@ static ccv_cnnp_model_t* _building_block_new(const int filters, const int stride ccv_cnnp_model_io_t output = ccv_cnnp_model_apply(identity, MODEL_IO_LIST(input)); if (projection_shortcut) { - ccv_cnnp_model_t* const conv0 = ccv_cnnp_convolution(1, filters, DIM_ALLOC(1, 1), 1, HINT((strides, strides), (0, 0)), 0, 1, 0); + ccv_cnnp_model_t* const conv0 = ccv_cnnp_convolution(1, filters, DIM_ALLOC(1, 1), DIM_ALLOC(), 1, HINT((strides, strides), (0, 0)), 0, 1, 0); shortcut = ccv_cnnp_model_apply(conv0, MODEL_IO_LIST(output)); } ccv_cnnp_model_t* const conv1 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((strides, strides), (border, border)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((strides, strides), (border, border)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); output = ccv_cnnp_model_apply(conv1, MODEL_IO_LIST(output)); - ccv_cnnp_model_t* const conv2 = ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0); + ccv_cnnp_model_t* const conv2 = ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0); output = ccv_cnnp_model_apply(conv2, MODEL_IO_LIST(output)); ccv_cnnp_model_t* const add = ccv_cnnp_sum(0); output = ccv_cnnp_model_apply(add, MODEL_IO_LIST(output, shortcut)); @@ -57,7 +57,7 @@ static ccv_cnnp_model_t* _block_layer_new(const int filters, const int strides, ccv_cnnp_model_t* _cifar_10_resnet56(void) { const ccv_cnnp_model_io_t input = ccv_cnnp_input(); - ccv_cnnp_model_t* init_conv = ccv_cnnp_convolution(1, 16, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0); + ccv_cnnp_model_t* init_conv = ccv_cnnp_convolution(1, 16, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0); ccv_cnnp_model_io_t output = ccv_cnnp_model_apply(init_conv, MODEL_IO_LIST(input)); output = ccv_cnnp_model_apply(_block_layer_new(16, 1, 1, 9), MODEL_IO_LIST(output)); output = ccv_cnnp_model_apply(_block_layer_new(32, 2, 1, 9), MODEL_IO_LIST(output)); @@ -78,7 +78,7 @@ static ccv_cnnp_model_t* _dawn_layer_new(const int filters, const int strides, c { ccv_cnnp_model_io_t input = ccv_cnnp_input(); ccv_cnnp_model_t* conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); @@ -89,13 +89,13 @@ static ccv_cnnp_model_t* _dawn_layer_new(const int filters, const int strides, c { ccv_cnnp_model_io_t shortcut = output; ccv_cnnp_model_t* res1 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); output = ccv_cnnp_model_apply(res1, MODEL_IO_LIST(output)); ccv_cnnp_model_t* res2 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); @@ -109,7 +109,7 @@ static ccv_cnnp_model_t* _dawn_layer_new(const int filters, const int strides, c ccv_cnnp_model_t* _cifar_10_dawn(void) { ccv_cnnp_model_t* prep = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); @@ -129,15 +129,15 @@ ccv_cnnp_model_t* _cifar_10_dawn(void) ccv_cnnp_model_t* _cifar_10_alexnet(void) { return ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (0, 0)), 0), - ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_average_pool(DIM_ALLOC(3, 3), HINT((2, 2), (0, 0)), 0), - ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_average_pool(DIM_ALLOC(3, 3), HINT((2, 2), (0, 0)), 0), diff --git a/bin/nnc/coco.c b/bin/nnc/coco.c index db02cbf13..dbe27462a 100644 --- a/bin/nnc/coco.c +++ b/bin/nnc/coco.c @@ -27,23 +27,23 @@ static ccv_cnnp_model_t* _resnet_block_new(const int filters, const int expansio ccv_cnnp_model_t* const avgdown = ccv_cnnp_average_pool(DIM_ALLOC(strides, strides), HINT((strides, strides), (0, 0)), 0); shortcut = ccv_cnnp_model_apply(avgdown, MODEL_IO_LIST(input)); } - ccv_cnnp_model_t* const conv0 = ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), 1, HINT((1, 1), (0, 0)), 0, 1, 0); + ccv_cnnp_model_t* const conv0 = ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), DIM_ALLOC(), 1, HINT((1, 1), (0, 0)), 0, 1, 0); shortcut = ccv_cnnp_model_apply(conv0, MODEL_IO_LIST(shortcut)); } ccv_cnnp_model_t* const conv1 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); ccv_cnnp_model_io_t output = ccv_cnnp_model_apply(conv1, MODEL_IO_LIST(input)); ccv_cnnp_model_t* const conv2 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((strides, strides), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((strides, strides), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); output = ccv_cnnp_model_apply(conv2, MODEL_IO_LIST(output)); ccv_cnnp_model_t* const conv3 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0) ), 1, 0); output = ccv_cnnp_model_apply(conv3, MODEL_IO_LIST(output)); @@ -72,13 +72,13 @@ ccv_array_t* _imagenet_resnet50_v1d(void) { const ccv_cnnp_model_io_t input = ccv_cnnp_input(); ccv_cnnp_model_t* init_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((2, 2), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((2, 2), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (1, 1)), 0) @@ -110,14 +110,14 @@ ccv_array_t* _imagenet_resnet50_v1d(void) static void _fpn(const int d, const ccv_cnnp_model_io_t* const c, const int c_size, ccv_cnnp_model_io_t* const p) { int i; - ccv_cnnp_model_io_t output = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(c[c_size - 1])); + ccv_cnnp_model_io_t output = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(c[c_size - 1])); p[c_size - 1] = output; for (i = c_size - 2; i >= 0; i--) { - const ccv_cnnp_model_io_t lateral = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(c[i])); + const ccv_cnnp_model_io_t lateral = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(c[i])); const ccv_cnnp_model_io_t up = ccv_cnnp_model_apply(ccv_cnnp_upsample(CCV_NNC_UPSAMPLE_BILINEAR, 2, 2, 0), MODEL_IO_LIST(output)); const ccv_cnnp_model_io_t sum = ccv_cnnp_model_apply(ccv_cnnp_sum(0), MODEL_IO_LIST(lateral, up)); - output = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), MODEL_IO_LIST(sum)); + output = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), MODEL_IO_LIST(sum)); p[i] = output; } } @@ -126,13 +126,13 @@ ccv_array_t* _imagenet_resnet50_v1d_fpn(void) { const ccv_cnnp_model_io_t input = ccv_cnnp_input(); ccv_cnnp_model_t* init_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((2, 2), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((2, 2), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (1, 1)), 0) @@ -171,7 +171,7 @@ ccv_cnnp_model_t* _coco_resnet50_v1d_rpn(void) ccv_cnnp_model_io_t proposals[5]; int i; // 3 aspect ratios (1:2, 1:1, 2:1). Each has 4 + 1 (x, y, w, h, objectness), total 15. - ccv_cnnp_model_t* const rpn_proposals = ccv_cnnp_convolution(1, 15, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, "rpn"); + ccv_cnnp_model_t* const rpn_proposals = ccv_cnnp_convolution(1, 15, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, "rpn"); for (i = 0; i < 5; i++) { p[i] = ccv_cnnp_input(); diff --git a/bin/nnc/imagenet.c b/bin/nnc/imagenet.c index a06e7fd01..a0d44dcad 100644 --- a/bin/nnc/imagenet.c +++ b/bin/nnc/imagenet.c @@ -26,23 +26,23 @@ static ccv_cnnp_model_t* _resnet_block_new(const int filters, const int expansio ccv_cnnp_model_t* const avgdown = ccv_cnnp_average_pool(DIM_ALLOC(strides, strides), HINT((strides, strides), (0, 0)), 0); shortcut = ccv_cnnp_model_apply(avgdown, MODEL_IO_LIST(input)); } - ccv_cnnp_model_t* const conv0 = ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), 1, HINT((1, 1), (0, 0)), 0, 1, 0); + ccv_cnnp_model_t* const conv0 = ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), DIM_ALLOC(), 1, HINT((1, 1), (0, 0)), 0, 1, 0); shortcut = ccv_cnnp_model_apply(conv0, MODEL_IO_LIST(shortcut)); } ccv_cnnp_model_t* const conv1 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); ccv_cnnp_model_io_t output = ccv_cnnp_model_apply(conv1, MODEL_IO_LIST(input)); ccv_cnnp_model_t* const conv2 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((strides, strides), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((strides, strides), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); output = ccv_cnnp_model_apply(conv2, MODEL_IO_LIST(output)); ccv_cnnp_model_t* const conv3 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0) ), 1, 0); output = ccv_cnnp_model_apply(conv3, MODEL_IO_LIST(output)); @@ -71,13 +71,13 @@ ccv_cnnp_model_t* _imagenet_resnet50_v1d(void) { const ccv_cnnp_model_io_t input = ccv_cnnp_input(); ccv_cnnp_model_t* init_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((2, 2), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((2, 2), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (1, 1)), 0) @@ -98,13 +98,13 @@ ccv_cnnp_model_t* _imagenet_resnet101_v1d(void) { const ccv_cnnp_model_io_t input = ccv_cnnp_input(); ccv_cnnp_model_t* init_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((2, 2), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((2, 2), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (1, 1)), 0) @@ -124,29 +124,29 @@ ccv_cnnp_model_t* _imagenet_resnet101_v1d(void) ccv_cnnp_model_t* _imagenet_vgg13(void) { ccv_cnnp_model_t* vgg13 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (1, 1)), 0), - ccv_cnnp_convolution(1, 128, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 128, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 128, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 128, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (1, 1)), 0), - ccv_cnnp_convolution(1, 256, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 256, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 256, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 256, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (1, 1)), 0), - ccv_cnnp_convolution(1, 512, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 512, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 512, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 512, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (1, 1)), 0), - ccv_cnnp_convolution(1, 512, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 512, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 512, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 512, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_average_pool(DIM_ALLOC(0, 0), ccv_nnc_no_hint, 0), ccv_cnnp_flatten(0), @@ -165,7 +165,7 @@ static ccv_cnnp_model_t* _mconv_block_new(const int kernel_size, const int strid { expand_filters = input_filters * expand_ratio; ccv_cnnp_model_t* const expand_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, expand_filters, DIM_ALLOC(1, 1), 1, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, expand_filters, DIM_ALLOC(1, 1), DIM_ALLOC(), 1, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_swish(0) ), 1, 0); @@ -173,7 +173,7 @@ static ccv_cnnp_model_t* _mconv_block_new(const int kernel_size, const int strid } const int paddings = (kernel_size - 1) / 2; ccv_cnnp_model_t* const depthwise_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(expand_filters, expand_filters, DIM_ALLOC(kernel_size, kernel_size), 1, HINT((strides, strides), (paddings, paddings)), 0, 1, 0), + ccv_cnnp_convolution(expand_filters, expand_filters, DIM_ALLOC(kernel_size, kernel_size), DIM_ALLOC(), 1, HINT((strides, strides), (paddings, paddings)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_swish(0) ), 1, 0); @@ -181,15 +181,15 @@ static ccv_cnnp_model_t* _mconv_block_new(const int kernel_size, const int strid const int se_filters = ccv_max(1, (int)(input_filters * se_ratio + 0.5)); ccv_cnnp_model_t* const se_conv = ccv_cnnp_sequential_new(MODEL_LIST( ccv_cnnp_average_pool(DIM_ALLOC(0, 0), ccv_nnc_no_hint, 0), - ccv_cnnp_convolution(1, se_filters, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, se_filters, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_swish(0), - ccv_cnnp_convolution(1, expand_filters, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, expand_filters, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_sigmoid(0) ), 1, 0); const ccv_cnnp_model_io_t se = ccv_cnnp_model_apply(se_conv, MODEL_IO_LIST(x)); x = ccv_cnnp_model_apply(ccv_cnnp_mul(1, 0), MODEL_IO_LIST(x, se)); ccv_cnnp_model_t* const proj_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, output_filters, DIM_ALLOC(1, 1), 1, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, output_filters, DIM_ALLOC(1, 1), DIM_ALLOC(), 1, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0) ), 1, 0); x = ccv_cnnp_model_apply(proj_conv, MODEL_IO_LIST(x)); @@ -221,7 +221,7 @@ ccv_cnnp_model_t* _efficientnet_b0(void) const ccv_cnnp_model_io_t input = ccv_cnnp_input(); const float dropout = 0.1; ccv_cnnp_model_t* const init_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((2, 2), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((2, 2), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_swish(0) ), 1, 0); @@ -234,7 +234,7 @@ ccv_cnnp_model_t* _efficientnet_b0(void) output = ccv_cnnp_model_apply(_mconv_block_layer_new(4, 5, 2, 6, 112, 192, 0.25, dropout), MODEL_IO_LIST(output)); output = ccv_cnnp_model_apply(_mconv_block_layer_new(1, 3, 1, 6, 192, 320, 0.25, dropout), MODEL_IO_LIST(output)); ccv_cnnp_model_t* const head_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 1280, DIM_ALLOC(1, 1), 1, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, 1280, DIM_ALLOC(1, 1), DIM_ALLOC(), 1, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_swish(0) ), 1, 0); diff --git a/lib/nnc/ccv_cnnp_model_addons.c b/lib/nnc/ccv_cnnp_model_addons.c index 61c0f9368..8b3d4a9fd 100644 --- a/lib/nnc/ccv_cnnp_model_addons.c +++ b/lib/nnc/ccv_cnnp_model_addons.c @@ -897,6 +897,7 @@ typedef struct { int groups; int filters; int kdim[CCV_NNC_MAX_DIM_ALLOC]; + int dilation[CCV_NNC_MAX_DIM_ALLOC]; int no_bias; int format; ccv_nnc_hint_t hint; @@ -931,7 +932,11 @@ static void _ccv_cnnp_convolution_build(ccv_cnnp_model_t* const super, ccv_nnc_s ccv_nnc_cmd_t cmd = CMD_CONVOLUTION_FORWARD(self->groups, self->filters); for (i = 0; i < CCV_NNC_MAX_DIM; i++) cmd.info.size.dim[i] = self->kdim[i]; + memcpy(cmd.info.convolution.dilation, self->dilation, sizeof(self->dilation)); ccv_nnc_tensor_param_t output_params; + // Dilate weight size based on the dilation factor. + for (i = 0; i < CCV_NNC_MAX_DIM; i++) + weights_params.dim[i + hw] = (self->kdim[i] - 1) * ccv_max(self->dilation[i], 1) + 1; ccv_nnc_hint_tensor_auto(cmd, (ccv_nnc_tensor_param_t []){ params, weights_params, @@ -980,7 +985,7 @@ static const ccv_cnnp_model_vtab_t ccv_cnnp_convolution_isa = { .copy = _ccv_cnnp_convolution_copy, }; -ccv_cnnp_model_t* ccv_cnnp_convolution(const int groups, const int filters, const int kdim[CCV_NNC_MAX_DIM_ALLOC], const int no_bias, ccv_nnc_hint_t hint, const int format, const int is_trainable, const char* const name) +ccv_cnnp_model_t* ccv_cnnp_convolution(const int groups, const int filters, const int kdim[CCV_NNC_MAX_DIM_ALLOC], const int dilation[CCV_NNC_MAX_DIM_ALLOC], const int no_bias, ccv_nnc_hint_t hint, const int format, const int is_trainable, const char* const name) { ccv_cnnp_model_convolution_t* const model_convolution = (ccv_cnnp_model_convolution_t*)cccalloc(1, sizeof(ccv_cnnp_model_convolution_t)); model_convolution->super.isa = &ccv_cnnp_convolution_isa; @@ -996,6 +1001,7 @@ ccv_cnnp_model_t* ccv_cnnp_convolution(const int groups, const int filters, cons model_convolution->groups = groups; model_convolution->filters = filters; memcpy(model_convolution->kdim, kdim, sizeof(model_convolution->kdim)); + memcpy(model_convolution->dilation, dilation, sizeof(model_convolution->dilation)); model_convolution->no_bias = no_bias; model_convolution->hint = hint; model_convolution->format = format; @@ -1005,7 +1011,7 @@ ccv_cnnp_model_t* ccv_cnnp_convolution(const int groups, const int filters, cons static ccv_cnnp_model_t* _ccv_cnnp_convolution_copy(const ccv_cnnp_model_t* const super, void* const context) { ccv_cnnp_model_convolution_t* const self = (ccv_cnnp_model_convolution_t*)super; - return ccv_cnnp_convolution(self->groups, self->filters, self->kdim, self->no_bias, self->hint, self->format, self->super.is_trainable, self->super.name); + return ccv_cnnp_convolution(self->groups, self->filters, self->kdim, self->dilation, self->no_bias, self->hint, self->format, self->super.is_trainable, self->super.name); } // MARK - Dense Layer diff --git a/lib/nnc/ccv_nnc.h b/lib/nnc/ccv_nnc.h index 72b6b9c73..69a931795 100644 --- a/lib/nnc/ccv_nnc.h +++ b/lib/nnc/ccv_nnc.h @@ -4111,6 +4111,7 @@ CCV_WARN_UNUSED(ccv_cnnp_model_t*) ccv_cnnp_concat(const int axis, const char* c * @param groups The number of kernel groups in the model. * @param filters The total number of filters in the model (filters = groups * per group filters). * @param kdim The dimensions of the kernel. + * @param dilation The dilation factor on each dimension. * @param no_bias Whether has bias term or not. * @param hint The hint for alignment. * @param format The format for weights. If 0, it will have the same format as the input. @@ -4118,7 +4119,7 @@ CCV_WARN_UNUSED(ccv_cnnp_model_t*) ccv_cnnp_concat(const int axis, const char* c * @param name The unique name of the model. * @return A convolution model. */ -CCV_WARN_UNUSED(ccv_cnnp_model_t*) ccv_cnnp_convolution(const int groups, const int filters, const int kdim[CCV_NNC_MAX_DIM_ALLOC], const int no_bias, ccv_nnc_hint_t hint, const int format, const int is_trainable, const char* const name); +CCV_WARN_UNUSED(ccv_cnnp_model_t*) ccv_cnnp_convolution(const int groups, const int filters, const int kdim[CCV_NNC_MAX_DIM_ALLOC], const int dilation[CCV_NNC_MAX_DIM_ALLOC], const int no_bias, ccv_nnc_hint_t hint, const int format, const int is_trainable, const char* const name); /** * A dense layer model. * @param count The output dimension. diff --git a/test/int/nnc/cifar.tests.c b/test/int/nnc/cifar.tests.c index 9705c3358..a0935fe22 100644 --- a/test/int/nnc/cifar.tests.c +++ b/test/int/nnc/cifar.tests.c @@ -16,7 +16,7 @@ static ccv_cnnp_model_t* _dawn_layer_new(const int filters, const int strides, c { ccv_cnnp_model_io_t input = ccv_cnnp_input(); ccv_cnnp_model_t* conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); @@ -27,13 +27,13 @@ static ccv_cnnp_model_t* _dawn_layer_new(const int filters, const int strides, c { ccv_cnnp_model_io_t shortcut = output; ccv_cnnp_model_t* res1 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); output = ccv_cnnp_model_apply(res1, MODEL_IO_LIST(output)); ccv_cnnp_model_t* res2 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); @@ -47,7 +47,7 @@ static ccv_cnnp_model_t* _dawn_layer_new(const int filters, const int strides, c static ccv_cnnp_model_t* _cifar_10_dawn(const int softmax) { ccv_cnnp_model_t* prep = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); diff --git a/test/unit/nnc/cnnp.core.tests.c b/test/unit/nnc/cnnp.core.tests.c index da96356aa..21765a60d 100644 --- a/test/unit/nnc/cnnp.core.tests.c +++ b/test/unit/nnc/cnnp.core.tests.c @@ -14,13 +14,13 @@ TEST_SETUP() static ccv_cnnp_model_t* simple_cifar_10(void) { return ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (0, 0)), 0), - ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_average_pool(DIM_ALLOC(3, 3), HINT((2, 2), (0, 0)), 0), - ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_average_pool(DIM_ALLOC(3, 3), HINT((2, 2), (0, 0)), 0), ccv_cnnp_flatten(0), @@ -109,22 +109,22 @@ TEST_CASE("inception layer for model") { const ccv_cnnp_model_io_t x = ccv_cnnp_input(); _ccv_cnnp_model_notified = 0; - ccv_cnnp_model_t* const conv_1 = ccv_cnnp_convolution(1, 64, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0); + ccv_cnnp_model_t* const conv_1 = ccv_cnnp_convolution(1, 64, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0); ccv_cnnp_model_notify_hook(conv_1, _ccv_cnnp_model_hook, 0); ccv_cnnp_model_io_t tower_1 = ccv_cnnp_model_apply(conv_1, MODEL_IO_LIST(x)); ccv_cnnp_model_t* const relu_1 = ccv_cnnp_relu(0); ccv_cnnp_model_notify_hook(relu_1, _ccv_cnnp_model_hook, 0); tower_1 = ccv_cnnp_model_apply(relu_1, MODEL_IO_LIST(tower_1)); - tower_1 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), MODEL_IO_LIST(tower_1)); + tower_1 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), MODEL_IO_LIST(tower_1)); tower_1 = ccv_cnnp_model_apply(ccv_cnnp_relu(0), MODEL_IO_LIST(tower_1)); - ccv_cnnp_model_io_t tower_2 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(x)); + ccv_cnnp_model_io_t tower_2 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(x)); tower_2 = ccv_cnnp_model_apply(ccv_cnnp_relu(0), MODEL_IO_LIST(tower_2)); - tower_2 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), MODEL_IO_LIST(tower_2)); + tower_2 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), MODEL_IO_LIST(tower_2)); tower_2 = ccv_cnnp_model_apply(ccv_cnnp_relu(0), MODEL_IO_LIST(tower_2)); ccv_cnnp_model_io_t tower_3 = ccv_cnnp_model_apply(ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((1, 1), (1, 1)), 0), MODEL_IO_LIST(x)); - tower_3 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(tower_3)); + tower_3 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(tower_3)); tower_3 = ccv_cnnp_model_apply(ccv_cnnp_relu(0), MODEL_IO_LIST(tower_3)); ccv_cnnp_model_t* const add_1 = ccv_cnnp_sum(0); ccv_cnnp_model_notify_hook(add_1, _ccv_cnnp_model_hook, 0); @@ -145,16 +145,16 @@ static ccv_cnnp_model_t* _ccv_multiple_outputs_functional_model(const ccv_nnc_te { ccv_cnnp_model_io_t input0 = ccv_cnnp_input(); ccv_cnnp_model_io_t input1 = ccv_cnnp_input(); - ccv_cnnp_model_io_t output0 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(input0)); + ccv_cnnp_model_io_t output0 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(input0)); output0 = ccv_cnnp_model_apply(ccv_cnnp_relu(0), MODEL_IO_LIST(output0)); - ccv_cnnp_model_io_t output1 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, 0), MODEL_IO_LIST(input1)); + ccv_cnnp_model_io_t output1 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, 0), MODEL_IO_LIST(input1)); output1 = ccv_cnnp_model_apply(ccv_cnnp_relu(0), MODEL_IO_LIST(output1)); ccv_cnnp_model_t* model0 = ccv_cnnp_model_new(MODEL_IO_LIST(input0, input1), MODEL_IO_LIST(output0, output1), 1, 0); input0 = ccv_cnnp_input(); input1 = ccv_cnnp_input(); output0 = ccv_cnnp_model_apply(model0, MODEL_IO_LIST(input0, input1)); ccv_cnnp_model_io_t input2 = ccv_cnnp_input(); - output1 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), MODEL_IO_LIST(input2)); + output1 = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), MODEL_IO_LIST(input2)); output1 = ccv_cnnp_model_apply(ccv_cnnp_relu(0), MODEL_IO_LIST(output1)); ccv_cnnp_model_t* interim = ccv_cnnp_model_new(MODEL_IO_LIST(input0, input1, input2), MODEL_IO_LIST(output0, output1), 1, 0); input0 = ccv_cnnp_input(); @@ -349,13 +349,13 @@ TEST_CASE("train model with share weights and L2 loss") static ccv_cnnp_model_t* simple_cifar_10_no_softmax(void) { return ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (0, 0)), 0), - ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_average_pool(DIM_ALLOC(3, 3), HINT((2, 2), (0, 0)), 0), - ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), 0, HINT((1, 1), (2, 2)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(5, 5), DIM_ALLOC(), 0, HINT((1, 1), (2, 2)), 0, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_average_pool(DIM_ALLOC(3, 3), HINT((2, 2), (0, 0)), 0), ccv_cnnp_flatten(0), @@ -1369,23 +1369,23 @@ static ccv_cnnp_model_t* _resnet_block_new(const int filters, const int expansio { ccv_cnnp_model_t* const avgdown = ccv_cnnp_average_pool(DIM_ALLOC(strides, strides), HINT((strides, strides), (0, 0)), 0); shortcut = ccv_cnnp_model_apply(avgdown, MODEL_IO_LIST(input)); - ccv_cnnp_model_t* const conv0 = ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), 1, HINT((1, 1), (0, 0)), 0, 1, 0); + ccv_cnnp_model_t* const conv0 = ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), DIM_ALLOC(), 1, HINT((1, 1), (0, 0)), 0, 1, 0); shortcut = ccv_cnnp_model_apply(conv0, MODEL_IO_LIST(shortcut)); } ccv_cnnp_model_t* const conv1 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); ccv_cnnp_model_io_t output = ccv_cnnp_model_apply(conv1, MODEL_IO_LIST(input)); ccv_cnnp_model_t* const conv2 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), 0, HINT((strides, strides), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, filters, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((strides, strides), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0) ), 1, 0); output = ccv_cnnp_model_apply(conv2, MODEL_IO_LIST(output)); ccv_cnnp_model_t* const conv3 = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), + ccv_cnnp_convolution(1, filters * expansion, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0) ), 1, 0); output = ccv_cnnp_model_apply(conv3, MODEL_IO_LIST(output)); @@ -1413,14 +1413,14 @@ static ccv_cnnp_model_t* _resnet_block_layer_new(const int filters, const int ex static void _fpn(const int d, const ccv_cnnp_model_io_t* const c, const int c_size, ccv_cnnp_model_io_t* const p) { int i; - ccv_cnnp_model_io_t output = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(c[c_size - 1])); + ccv_cnnp_model_io_t output = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(c[c_size - 1])); p[c_size - 1] = output; for (i = c_size - 2; i >= 0; i--) { - const ccv_cnnp_model_io_t lateral = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(c[i])); + const ccv_cnnp_model_io_t lateral = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, 0), MODEL_IO_LIST(c[i])); const ccv_cnnp_model_io_t up = ccv_cnnp_model_apply(ccv_cnnp_upsample(CCV_NNC_UPSAMPLE_BILINEAR, 2, 2, 0), MODEL_IO_LIST(output)); const ccv_cnnp_model_io_t sum = ccv_cnnp_model_apply(ccv_cnnp_sum(0), MODEL_IO_LIST(lateral, up)); - output = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), MODEL_IO_LIST(sum)); + output = ccv_cnnp_model_apply(ccv_cnnp_convolution(1, d, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), MODEL_IO_LIST(sum)); p[i] = output; } } @@ -1429,13 +1429,13 @@ ccv_cnnp_model_t* _imagenet_resnet50_v1d_fpn(void) { const ccv_cnnp_model_io_t input = ccv_cnnp_input(); ccv_cnnp_model_t* init_conv = ccv_cnnp_sequential_new(MODEL_LIST( - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((2, 2), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((2, 2), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), - ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), 1, HINT((1, 1), (1, 1)), 0, 1, 0), + ccv_cnnp_convolution(1, 64, DIM_ALLOC(3, 3), DIM_ALLOC(), 1, HINT((1, 1), (1, 1)), 0, 1, 0), ccv_cnnp_batch_norm(0.9, 1e-4, 1, 0), ccv_cnnp_relu(0), ccv_cnnp_max_pool(DIM_ALLOC(3, 3), HINT((2, 2), (1, 1)), 0) @@ -1454,7 +1454,7 @@ ccv_cnnp_model_t* _imagenet_resnet50_v1d_fpn(void) _fpn(256, c, 4, p); p[4] = ccv_cnnp_model_apply(ccv_cnnp_average_pool(DIM_ALLOC(2, 2), HINT((2, 2), (0, 0)), 0), MODEL_IO_LIST(p[3])); // 3 aspect ratios (1:2, 1:1, 2:1). Each has 4 + 2 (x, y, w, h, object, non-object), total 18. - ccv_cnnp_model_t* const rpn_proposals = ccv_cnnp_convolution(1, 18, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, "rpn"); + ccv_cnnp_model_t* const rpn_proposals = ccv_cnnp_convolution(1, 18, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, "rpn"); ccv_cnnp_model_io_t proposals[5]; int i; for (i = 0; i < 5; i++) @@ -1657,9 +1657,9 @@ TEST_CASE("LoRA fine-tuning GEMM set is_trainable to false") TEST_CASE("LoRA fine-tuning convolution set is_trainable to false") { const ccv_cnnp_model_io_t input = ccv_cnnp_input(); - ccv_cnnp_model_t* const conv = ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, -1, "conv"); - ccv_cnnp_model_t* const down = ccv_cnnp_convolution(1, 4, DIM_ALLOC(3, 3), 0, HINT((1, 1), (1, 1)), 0, 1, "down"); - ccv_cnnp_model_t* const up = ccv_cnnp_convolution(1, 32, DIM_ALLOC(1, 1), 0, HINT((1, 1), (0, 0)), 0, 1, "up"); + ccv_cnnp_model_t* const conv = ccv_cnnp_convolution(1, 32, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, -1, "conv"); + ccv_cnnp_model_t* const down = ccv_cnnp_convolution(1, 4, DIM_ALLOC(3, 3), DIM_ALLOC(), 0, HINT((1, 1), (1, 1)), 0, 1, "down"); + ccv_cnnp_model_t* const up = ccv_cnnp_convolution(1, 32, DIM_ALLOC(1, 1), DIM_ALLOC(), 0, HINT((1, 1), (0, 0)), 0, 1, "up"); ccv_cnnp_model_io_t out = ccv_cnnp_model_apply(conv, MODEL_IO_LIST(input)); ccv_cnnp_model_io_t out_down = ccv_cnnp_model_apply(down, MODEL_IO_LIST(input)); ccv_cnnp_model_io_t out_up = ccv_cnnp_model_apply(up, MODEL_IO_LIST(out_down));