ceccocats / tkDNN

Deep neural network library and toolkit to do high performace inference on NVIDIA jetson platforms
GNU General Public License v2.0
718 stars 209 forks source link

add scale_channels, swish, logistic(sigmoid), avgpool ; add enet_coco(EfficientNetB0-Yolov3).cfg #172

Open thnkinbtfly opened 3 years ago

thnkinbtfly commented 3 years ago

Added Features

Add followings:

  1. [scale_channels] layer with scale_wh=0
  2. swish and logistic activation functions
  3. [avgpool] layer, which is global average pool in darknet

Tested with enet_coco (I removed dropout layers from the original enet_coco.cfg)

image

Reproduce test with enet_coco

  1. git clone the tkDNN forked darknet.

  2. git apply following patch file to the forked darknet. Note that if you don't change the BN epsilon (#167), the final output will fail to be similar.

    diff --git a/src/blas.c b/src/blas.c
    index 7bfc752..8d3ddd8 100644
    --- a/src/blas.c
    +++ b/src/blas.c
    @@ -289,7 +289,7 @@ void normalize_cpu(float *x, float *mean, float *variance, int batch, int filter
         for(f = 0; f < filters; ++f){
             for(i = 0; i < spatial; ++i){
                 int index = b*filters*spatial + f*spatial + i;
    -                x[index] = (x[index] - mean[f])/(sqrt(variance[f] + .000001f));
    +                x[index] = (x[index] - mean[f])/(sqrt(variance[f] + .00001f));
             }
         }
     }
    diff --git a/src/darknet.c b/src/darknet.c
    index f7d6a81..21b0f83 100644
    --- a/src/darknet.c
    +++ b/src/darknet.c
    @@ -506,6 +506,9 @@ void run_export(char *cfgfile, char *weightfile, char *out)
         } else if(l.type == SHORTCUT) {
             printf("export SHORTCUT\n");
             // no weights
    +        } else if(l.type == SCALE_CHANNELS) {
    +            printf("export SCALE_CHANNELS\n");
    +            // no weights
         } else if(l.type == ROUTE) {
             printf("export ROUTE\n");
             // no weights
    @@ -515,6 +518,9 @@ void run_export(char *cfgfile, char *weightfile, char *out)
         } else if(l.type == MAXPOOL) {
             printf("export MAXPOOL\n");
             // no weights 
    +        } else if(l.type == AVGPOOL) {
    +            printf("export AVGPOOL\n");
    +            // no weights
         } else if(l.type == REORG || l.type == REORG_OLD) {
             printf("export REORG\n");
             // no weights          
  3. download enet-coco weights from official darknet repo

  4. follow the steps to generate weights and input/outputs. Example : ./darknet export ../tkDNN/tests/darknet/cfg/enet-coco-wo-dropout.cfg enetb0-coco_final.weights layers

  5. build tkDNN and

    cd build
    mkdir enet_coco_wo_dropout
    cp -r ../../darknet/layers enet_coco_wo_dropout/ && cp -r ../../darknet/debug enet_coco_wo_dropout
    ./test_enet_coco_wo_dropout