Tic商业评论

关注微信公众号【站长自定义模块】,定时推送前沿、专业、深度的商业资讯。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

微信登录

微信扫码,快速开始

  • QQ空间
  • 回复
  • 收藏

rknn模型转换,采用512x128图像

lijingle 深度学习 2021-10-25 19:24 1719人围观

rknn在模型进行转换时,一般官方给的是320x320的图片,或者是416x416的图片,都是正方形图片,在我们进行训练自己的数据集时,不一定都是刚好的正方形,也可能是矩形,这里我们采用的是矩形,这里我们转换的模型是YOLOv3,采用的输入图片配置如下:
#配置

rknn.config(reorder_channel='0 1 2', mean_values=[[0, 0, 0]], std_values=[[255, 255, 255]])
模型转化后,需要修改测试代码,需要修改的代码如下:
GRID0 = 13GRID1 = 26

GRID2 = 52
修改为
GRID0_w = 16

GRID0_h = 4

GRID1_w = 32

GRID1_h = 8

GRID2_w = 16

GRID2_h = 64
在输入处改为:
input0_data = input0_data.reshape(SPAN, LISTSIZE, GRID0_h, GRID0_w)

input1_data = input1_data.reshape(SPAN, LISTSIZE, GRID1_h GRID1_w)

input2_data = input2_data.reshape(SPAN, LISTSIZE, GRID2_w, GRID2_h)
在处理输出处时需要将代码修改为如下:
def process(input, mask, anchors):



    anchors = [anchors[i] for i in mask]

    grid_h, grid_w = map(int, input.shape[0:2])

    

    box_confidence = sigmoid(input[..., 4])

    box_confidence = np.expand_dims(box_confidence, axis=-1)

    

    box_class_probs = sigmoid(input[..., 5:])

    box_xy = sigmoid(input[..., :2])

    box_wh = np.exp(input[..., 2:4])

    box_wh = box_wh * anchors

    col = np.tile(np.arange(0, grid_w), grid_h).reshape(-1, grid_w)

    row = np.tile(np.arange(0, grid_h).reshape(-1, 1), grid_w)

    col = col.reshape(grid_h, grid_w, 1, 1).repeat(3, axis=-2)

    row = row.reshape(grid_h, grid_w, 1, 1).repeat(3, axis=-2)</font>

    grid = np.concatenate((col, row), axis=-1)
这样就可以进行转换矩形图片了

路过

雷人

握手

鲜花

鸡蛋
原作者: lijingle
我有话说......
电话咨询: 135xxxxxxx
关注微信