海思3519/16 nnie 中upsample层实现方式验证

问题

upsample层作为高低层特征融合的一种手段在图像分割、分类模型中经常会使用,在海思3516/19上nnie 支持upsample层,但文档显示upsample层实现方式为unmaxpooling(HiSVP 开发指南)

 

按照unmaxplooling的实现方式,此时输入数量应为2,其中一层接maxpooling。

 

但此种使用方式缺不大常用,常用方式如retinaface、yolov3等upsample层作为上采样层,只对featuremap进行插值。此时问题就在于插值方式有多重,以opencv提供的方式为例有最近邻插值、双线性插值等;

    /** nearest neighbor interpolation */

    INTER_NEAREST        = 0,

    /** bilinear interpolation */

    INTER_LINEAR         = 1,

    /** bicubic interpolation */

    INTER_CUBIC          = 2,

    /** resampling using pixel area relation. It may be a preferred method for image decimation, as

    it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST

    method. */

    INTER_AREA           = 3,

    /** Lanczos interpolation over 8x8 neighborhood */

    INTER_LANCZOS4       = 4,

    /** Bit exact bilinear interpolation */

    INTER_LINEAR_EXACT = 5,

    /** mask for interpolation codes */

    INTER_MAX            = 7,

    /** flag, fills all of the destination image pixels. If some of them correspond to outliers in the

    source image, they are set to zero */

    WARP_FILL_OUTLIERS   = 8,

弄清upsample实现方式可以解决由此产生的精度损失问题。

实验入下:

首先构建一个只有upsample层的caffe模型,采用nnie_mapper转换为wk模型,log=3记录模型输入输出。模型转换cfg文件如下

 

模型定义如下,

 

 

采用特定的32*32图片作为输入(除部分位置为0外,其余均为255,可以使用opencv或者ps生成,不建议压缩)。

 

输出结果如下:

 

采用opencv分别对图片进行插值操作,代码如下:

 

经过比对在采用最近邻插值是特定位置结果(下图)与mapper_quant中out_output0_3_64_64_quant.linear.hex(SQ20.12格式)输出一致,能够证明upsample实现方式就是最近邻插值。

 

同时上板进行模型推理,此时输入为32*32*3尺度,B通道i%4 = 255;

    for(int i=0;i< 32*32;i++)

    {

        if(i %4 ==0)

        {

            buff[i] = 255;

        }

    }

推理结果如下(上opencv结果;下nnie_mapper结果):

 

可以看到结果只有两个值,可以确定为最近邻实现方式。

结论

海思3516/3519/3559系列nnie upsample层实现方式为最近邻插值。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值