Skip to content

Commit

Permalink
new int8 implement,better accuracy (Tencent#749)
Browse files Browse the repository at this point in the history
* add the armv7a conv3x3s1 implement without overflow,remove old codes

* fix the bug of conv3x3s2 packed int8

* new int8 implement,weight quant by perchanel,better accuracy~

* fix the bug of conv3x3s1 packed int8 neon

* add the naive c fp32 and int8 winograd F(2,3)

* add the neon intrinsic int8 winograd F(2,3)

* optimize the armv7a int8 winograd F(2,3) with neon assembly

* optimize the armv7a int8 winograd F(2,3) input transform with assembly.

* add the requantize layer and int8 relu implement.

* add graph optimize conv1x1s2 -> conv1x1s1,begin optimize int8 aarch64.

* fix int8 bugs

* add the c naive im2col with sgemm

* add aarch64 int8 winograd f23, conv3x3s2 naive implement

* add the int8 sgemm conv7x7s2 on x86/armv7a platform

* optimize the int8 sgemm by neon intrinsic and packed kernel

* optimize the int8 sgemm with packed data

* optimize the int8 sgemm with armv7a neon assembly

* add the int8 sgemm on arm64-v8a platform

* perpare to merge latest codes from master

* add the int8 param files

* In the Class Net,add the fuse_network method
  • Loading branch information
BUG1989 authored and nihui committed Mar 5, 2019
1 parent 4ac56d3 commit df3d224
Show file tree
Hide file tree
Showing 49 changed files with 9,347 additions and 6,796 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ option(NCNN_PIXEL "convert and resize from/to image pixel" ON)
option(NCNN_PIXEL_ROTATE "rotate image pixel orientation" OFF)
option(NCNN_CMAKE_VERBOSE "print verbose cmake messages" OFF)
option(NCNN_VULKAN "vulkan compute support" OFF)
option(NCNN_REQUANT "auto merge int8 quant and dequant" OFF)
option(NCNN_IM2COL_SGEMM "im2col sgemm support" OFF)

if(NCNN_OPENMP)
find_package(OpenMP)
Expand Down
74 changes: 73 additions & 1 deletion benchmark/benchncnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,19 @@ void benchmark(const char* comment, void (*init)(ncnn::Net&), void (*run)(const

time_avg /= g_loop_count;

fprintf(stderr, "%16s min = %7.2f max = %7.2f avg = %7.2f\n", comment, time_min, time_max, time_avg);
fprintf(stderr, "%-20s min = %7.2f max = %7.2f avg = %7.2f\n", comment, time_min, time_max, time_avg);
}

void squeezenet_init(ncnn::Net& net)
{
net.load_param("squeezenet.param");
}

void squeezenet_int8_init(ncnn::Net& net)
{
net.load_param("squeezenet_int8.param");
}

void squeezenet_run(const ncnn::Net& net)
{
ncnn::Extractor ex = net.create_extractor();
Expand All @@ -226,6 +231,11 @@ void mobilenet_init(ncnn::Net& net)
net.load_param("mobilenet.param");
}

void mobilenet_int8_init(ncnn::Net& net)
{
net.load_param("mobilenet_int8.param");
}

void mobilenet_run(const ncnn::Net& net)
{
ncnn::Extractor ex = net.create_extractor();
Expand Down Expand Up @@ -306,6 +316,11 @@ void googlenet_init(ncnn::Net& net)
net.load_param("googlenet.param");
}

void googlenet_int8_init(ncnn::Net& net)
{
net.load_param("googlenet_int8.param");
}

void googlenet_run(const ncnn::Net& net)
{
ncnn::Extractor ex = net.create_extractor();
Expand All @@ -322,6 +337,11 @@ void resnet18_init(ncnn::Net& net)
net.load_param("resnet18.param");
}

void resnet18_int8_init(ncnn::Net& net)
{
net.load_param("resnet18_int8.param");
}

void resnet18_run(const ncnn::Net& net)
{
ncnn::Extractor ex = net.create_extractor();
Expand Down Expand Up @@ -354,6 +374,11 @@ void vgg16_init(ncnn::Net& net)
net.load_param("vgg16.param");
}

void vgg16_int8_init(ncnn::Net& net)
{
net.load_param("vgg16_int8.param");
}

void vgg16_run(const ncnn::Net& net)
{
ncnn::Extractor ex = net.create_extractor();
Expand All @@ -365,11 +390,37 @@ void vgg16_run(const ncnn::Net& net)
ex.extract("prob", out);
}

void resnet50_init(ncnn::Net& net)
{
net.load_param("resnet50.param");
}

void resnet50_int8_init(ncnn::Net& net)
{
net.load_param("resnet50_int8.param");
}

void resnet50_run(const ncnn::Net& net)
{
ncnn::Extractor ex = net.create_extractor();

ncnn::Mat in(224, 224, 3);
ex.input("data", in);

ncnn::Mat out;
ex.extract("prob", out);
}

void squeezenet_ssd_init(ncnn::Net& net)
{
net.load_param("squeezenet_ssd.param");
}

void squeezenet_ssd_int8_init(ncnn::Net& net)
{
net.load_param("squeezenet_ssd_int8.param");
}

void squeezenet_ssd_run(const ncnn::Net& net)
{
ncnn::Extractor ex = net.create_extractor();
Expand All @@ -386,6 +437,11 @@ void mobilenet_ssd_init(ncnn::Net& net)
net.load_param("mobilenet_ssd.param");
}

void mobilenet_ssd_int8_init(ncnn::Net& net)
{
net.load_param("mobilenet_ssd_int8.param");
}

void mobilenet_ssd_run(const ncnn::Net& net)
{
ncnn::Extractor ex = net.create_extractor();
Expand Down Expand Up @@ -497,8 +553,12 @@ int main(int argc, char** argv)
// run
benchmark("squeezenet", squeezenet_init, squeezenet_run);

benchmark("squeezenet-int8", squeezenet_int8_init, squeezenet_run);

benchmark("mobilenet", mobilenet_init, mobilenet_run);

benchmark("mobilenet-int8", mobilenet_int8_init, mobilenet_run);

benchmark("mobilenet_v2", mobilenet_v2_init, mobilenet_v2_run);

benchmark("shufflenet", shufflenet_init, shufflenet_run);
Expand All @@ -509,16 +569,28 @@ int main(int argc, char** argv)

benchmark("googlenet", googlenet_init, googlenet_run);

benchmark("googlenet-int8", googlenet_int8_init, googlenet_run);

benchmark("resnet18", resnet18_init, resnet18_run);

benchmark("resnet18-int8", resnet18_int8_init, resnet18_run);

benchmark("alexnet", alexnet_init, alexnet_run);

benchmark("vgg16", vgg16_init, vgg16_run);

benchmark("resnet50", resnet50_init, resnet50_run);

benchmark("resnet50-int8", resnet50_int8_init, resnet50_run);

benchmark("squeezenet-ssd", squeezenet_ssd_init, squeezenet_ssd_run);

benchmark("squeezenet-ssd-int8", squeezenet_ssd_int8_init, squeezenet_ssd_run);

benchmark("mobilenet-ssd", mobilenet_ssd_init, mobilenet_ssd_run);

benchmark("mobilenet-ssd-int8", mobilenet_ssd_int8_init, mobilenet_ssd_run);

benchmark("mobilenet-yolo", mobilenet_yolo_init, mobilenet_yolo_run);

benchmark("mobilenet-yolov3", mobilenet_yolov3_init, mobilenet_yolov3_run);
Expand Down
Loading

0 comments on commit df3d224

Please sign in to comment.