未验证 提交 5fc41a27 编写于 作者: C cnn 提交者: GitHub

[dev] fix deploy of ttfnet fcos (#3568)

* fix bs=2 of FCOS

* fix bs=2 of ttfnet

* fix cascade deploy

* speedup by paddle.expand
上级 cb568212
...@@ -191,8 +191,10 @@ def draw_segm(im, ...@@ -191,8 +191,10 @@ def draw_segm(im,
color_mask[c] = color_mask[c] * (1 - w_ratio) + w_ratio * 255 color_mask[c] = color_mask[c] * (1 - w_ratio) + w_ratio * 255
idx = np.nonzero(mask) idx = np.nonzero(mask)
color_mask = np.array(color_mask) color_mask = np.array(color_mask)
im[idx[0], idx[1], :] *= 1.0 - alpha idx0 = np.minimum(idx[0], im.shape[0] - 1)
im[idx[0], idx[1], :] += alpha * color_mask idx1 = np.minimum(idx[1], im.shape[1] - 1)
im[idx0, idx1, :] *= 1.0 - alpha
im[idx0, idx1, :] += alpha * color_mask
sum_x = np.sum(mask, axis=0) sum_x = np.sum(mask, axis=0)
x = np.where(sum_x > 0.5)[0] x = np.where(sum_x > 0.5)[0]
sum_y = np.sum(mask, axis=1) sum_y = np.sum(mask, axis=1)
......
...@@ -266,7 +266,9 @@ class CascadeHead(BBoxHead): ...@@ -266,7 +266,9 @@ class CascadeHead(BBoxHead):
proposals) > 1 else proposals[0] proposals) > 1 else proposals[0]
pred_bbox = delta2bbox(deltas, pred_proposals, weights) pred_bbox = delta2bbox(deltas, pred_proposals, weights)
pred_bbox = paddle.reshape(pred_bbox, [-1, deltas.shape[-1]]) pred_bbox = paddle.reshape(pred_bbox, [-1, deltas.shape[-1]])
num_prop = [p.shape[0] for p in proposals] num_prop = []
for p in proposals:
num_prop.append(p.shape[0])
return pred_bbox.split(num_prop) return pred_bbox.split(num_prop)
def get_prediction(self, head_out_list): def get_prediction(self, head_out_list):
......
...@@ -386,7 +386,11 @@ class RCNNBox(object): ...@@ -386,7 +386,11 @@ class RCNNBox(object):
scale_list = [] scale_list = []
origin_shape_list = [] origin_shape_list = []
batch_size = paddle.slice(paddle.shape(im_shape), [0], [0], [1]) batch_size = 1
if isinstance(roi, list):
batch_size = len(roi)
else:
batch_size = paddle.slice(paddle.shape(im_shape), [0], [0], [1])
# bbox_pred.shape: [N, C*4] # bbox_pred.shape: [N, C*4]
for idx in range(batch_size): for idx in range(batch_size):
roi_per_im = roi[idx] roi_per_im = roi[idx]
...@@ -755,6 +759,8 @@ class FCOSBox(object): ...@@ -755,6 +759,8 @@ class FCOSBox(object):
# recover the location to original image # recover the location to original image
im_scale = paddle.concat([scale_factor, scale_factor], axis=1) im_scale = paddle.concat([scale_factor, scale_factor], axis=1)
im_scale = paddle.expand(im_scale, [box_reg_decoding.shape[0], 4])
im_scale = paddle.reshape(im_scale, [box_reg_decoding.shape[0], -1, 4])
box_reg_decoding = box_reg_decoding / im_scale box_reg_decoding = box_reg_decoding / im_scale
box_cls_ch_last = box_cls_ch_last * box_ctn_ch_last box_cls_ch_last = box_cls_ch_last * box_ctn_ch_last
return box_cls_ch_last, box_reg_decoding return box_cls_ch_last, box_reg_decoding
...@@ -822,7 +828,7 @@ class TTFBox(object): ...@@ -822,7 +828,7 @@ class TTFBox(object):
return topk_score, topk_inds, topk_clses, topk_ys, topk_xs return topk_score, topk_inds, topk_clses, topk_ys, topk_xs
def __call__(self, hm, wh, im_shape, scale_factor): def _decode(self, hm, wh, im_shape, scale_factor):
heatmap = F.sigmoid(hm) heatmap = F.sigmoid(hm)
heat = self._simple_nms(heatmap) heat = self._simple_nms(heatmap)
scores, inds, clses, ys, xs = self._topk(heat) scores, inds, clses, ys, xs = self._topk(heat)
...@@ -861,6 +867,19 @@ class TTFBox(object): ...@@ -861,6 +867,19 @@ class TTFBox(object):
results = paddle.gather(results, valid_ind) results = paddle.gather(results, valid_ind)
return results, paddle.shape(results)[0:1] return results, paddle.shape(results)[0:1]
def __call__(self, hm, wh, im_shape, scale_factor):
results = []
results_num = []
for i in range(scale_factor.shape[0]):
result, num = self._decode(hm[i:i + 1, ], wh[i:i + 1, ],
im_shape[i:i + 1, ],
scale_factor[i:i + 1, ])
results.append(result)
results_num.append(num)
results = paddle.concat(results, axis=0)
results_num = paddle.concat(results_num, axis=0)
return results, results_num
@register @register
@serializable @serializable
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册