Example #1
0
def test_decode_centernet():
    print("output: heatmaps", Y[0]["hm"].shape)
    print("output: wh_scale", Y[0]["wh"].shape)
    print("output: xy_offset", Y[0]["reg"].shape)

    heatmaps, scale, offset = Y[0]["hm"], Y[0]["wh"], Y[0]["reg"]
    detections = decode_centernet(heat=heatmaps, wh=scale, reg=offset, cat_spec_wh=False, K=10, flag_split=False)
    print(detections.shape)
    def process(self, images, return_time=False):
        output = self.model(images)[-1]
        heatmaps = output["hm"].sigmoid()
        wh = output["wh"]
        reg = output["reg"] if self.opt.reg_offset else None

        if self.opt.flip_test:
            heatmaps = (heatmaps[0:1] + flip_tensor(heatmaps[1:2])) / 2
            wh = (wh[0:1] + flip_tensor(wh[1:2])) / 2
            reg = reg[0:1] if reg is not None else None

        nd.waitall()
        forward_time = time.time()
        dets = decode_centernet(heatmaps, wh, reg, K=self.opt.K)
        if return_time:
            return output, dets, forward_time
        else:
            return output, dets
Example #3
0
def validate(model, val_loader, ctx, eval_metric):
    """Test on validation dataset."""
    eval_metric.reset()
    for batch in val_loader:
        data = gluon.utils.split_and_load(batch[0], ctx_list=ctx, batch_axis=0, even_split=False)
        label = gluon.utils.split_and_load(batch[1], ctx_list=ctx, batch_axis=0, even_split=False)
        det_bboxes = []
        det_ids = []
        det_scores = []
        gt_bboxes = []
        gt_ids = []
        gt_difficults = []
        for x, y in zip(data, label):
            #print("x.shape", x.shape)
            #print("x element value: ", x[0, 0, 128, 128])

            # get prediction results
            pred = model(x)
            heatmaps, scale, offset = pred[-1]["hm"], pred[-1]["wh"], pred[-1]["reg"]  # 2nd stack hourglass result

            #DEBUGING decode_centernet:
            bboxes, scores, ids = decode_centernet(heat=heatmaps, wh=scale, reg=offset, flag_split=True)

            num_gt_bboxes = y.shape[1]
            bboxes = bboxes[:, 0:num_gt_bboxes, :]
            scores = scores[:, 0:num_gt_bboxes, :]
            ids = ids[:, 0:num_gt_bboxes, :]
            print("Top-k, bbox: {}, scores: {}, id {}, gt_bbox: {}, gt_id: {}".format(bboxes[0, :, :], scores[0, :, :], ids[0, :, :], y[0, :, 0:4], y[0, :, 4]))

            det_ids.append(ids)
            det_scores.append(scores)
            # clip to image size
            det_bboxes.append(bboxes.clip(0, batch[0].shape[2]))
            # split ground truths
            gt_bboxes.append(y.slice_axis(axis=-1, begin=0, end=4))
            gt_ids.append(y.slice_axis(axis=-1, begin=4, end=5))
            gt_difficults.append(y.slice_axis(axis=-1, begin=5, end=6) if y.shape[-1] > 5 else None)

        # update metric
        eval_metric.update(det_bboxes, det_ids, det_scores, gt_bboxes, gt_ids, gt_difficults)
    return eval_metric.get()