1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 深度学习自学(七):腾讯移动端开源框架ncnn学习总结

深度学习自学(七):腾讯移动端开源框架ncnn学习总结

时间:2022-03-19 17:06:36

相关推荐

深度学习自学(七):腾讯移动端开源框架ncnn学习总结

一、支持的网络

Support most commonly used CNN network

支持大部分常用的 CNN 网络

Classical CNN Network: VGG AlexNet GoogleNet Inception …

Practical CNN Network: ResNet DenseNet SENet FPN …

Light-weight CNN Network: SqueezeNet MobileNetV1/V2 ShuffleNetV1/V2 MNasNet …

Detection Network: MTCNN facedetection …

Detection Network: VGG-SSD MobileNet-SSD SqueezeNet-SSD MobileNetV2-SSDLite …

Detection Network: Faster-RCNN R-FCN …

Detection Network: YOLOV2 YOLOV3 MobileNet-YOLOV3 …

Segmentation Network: FCN PSPNet …

二、加速技巧

1)使用低精度

半精度浮点数类型, 浮点数转化8bit量化

// convert float to half precision floating pointstatic unsigned short float2half(float value){// 1 : 8 : 23union{unsigned int u;float f;} tmp;tmp.f = value;// 1 : 8 : 23unsigned short sign = (tmp.u & 0x80000000) >> 31;unsigned short exponent = (tmp.u & 0x7F800000) >> 23;unsigned int significand = tmp.u & 0x7FFFFF;//fprintf(stderr, "%d %d %d\n", sign, exponent, significand);// 1 : 5 : 10unsigned short fp16;if (exponent == 0){// zero or denormal, always underflowfp16 = (sign << 15) | (0x00 << 10) | 0x00;}else if (exponent == 0xFF){// infinity or NaNfp16 = (sign << 15) | (0x1F << 10) | (significand ? 0x200 : 0x00);}else{// normalizedshort newexp = exponent + (- 127 + 15);if (newexp >= 31){// overflow, return infinityfp16 = (sign << 15) | (0x1F << 10) | 0x00;}else if (newexp <= 0){// underflowif (newexp >= -10){// denormal half-precisionunsigned short sig = (significand | 0x800000) >> (14 - newexp);fp16 = (sign << 15) | (0x00 << 10) | sig;}else{// underflowfp16 = (sign << 15) | (0x00 << 10) | 0x00;}}else{fp16 = (sign << 15) | (newexp << 10) | (significand >> 13);}}return fp16;}

2)openmp多核多线程加速

#pragma omp parallel for num_threads(opt.num_threads)for (int q=0; q<channels; q++){float* ptr = bottom_top_blob.channel(q);for (int i=0; i<size; i++){if (ptr[i] < 0)ptr[i] = -ptr[i];}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。