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)
这样就可以进行转换矩形图片了
|