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

Open
thnkinbtfly wants to merge 6 commits from thnkinbtfly/master into master
thnkinbtfly commented 2020-12-14 08:00:33 +01:00 (Migrated from github.com)

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          
  1. download enet-coco weights from official darknet repo

  2. 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

  3. 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
## 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](https://github.com/AlexeyAB/darknet/blob/a488131a1158665ec421ef258f55292127da1487/src/avgpool_layer.c) in darknet Tested with enet_coco (I removed dropout layers from the [original enet_coco.cfg](https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/enet-coco.cfg)) ![image](https://user-images.githubusercontent.com/70014488/102048206-0fcf8300-3e22-11eb-8572-4307fef52f75.png) ## Reproduce test with enet_coco 1. git clone the [tkDNN forked darknet](https://git.hipert.unimore.it/fgatti/darknet). 1. 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 ``` 2. download enet-coco weights from [official darknet repo](https://github.com/AlexeyAB/darknet#pre-trained-models) 3. follow the [steps](https://github.com/ceccocats/tkDNN#1export-weights-from-darknet) to generate weights and input/outputs. Example : `./darknet export ../tkDNN/tests/darknet/cfg/enet-coco-wo-dropout.cfg enetb0-coco_final.weights layers` 4. 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 ```
This repo is archived. You cannot comment on pull requests.
No Reviewers
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mmr/tkDNN#172