Ejemplo n.º 1
0
 def __call__(self, data: Dict) -> bool:
     if data is None:
         return True
     im, anno = data["image"], data["anno"]
     if self._hyper_params["target_type"] == "bbox":
         bbox = xyxy2xywh(anno)
     elif self._hyper_params["target_type"] == "mask":
         bbox = cv2.boundingRect(anno)
     else:
         logger.error("unspported target type {} in filter".format(
             self._hyper_params["target_type"]))
         exit()
     filter_flag = filter_unreasonable_training_boxes(
         im, bbox, self._hyper_params)
     return filter_flag
dev = torch.device(parsed_args.device)
pipeline.set_device(dev)

if __name__ == "__main__":

    seq = dataset[parsed_args.sequence_index]

    template_frame = {k: seq[k][parsed_args.template_frame] for k in seq}
    template_frame['image'] = load_image(template_frame['image'])

    search_frame = {k: seq[k][parsed_args.search_frame] for k in seq}
    search_frame['image'] = load_image(search_frame['image'])

    im = template_frame['image']
    bbox = template_frame['anno']
    rect = xyxy2xywh(bbox)
    pipeline.init(im, rect)

    bbox = tuple(map(int, bbox))
    cv2.rectangle(im,
                  bbox[:2],
                  bbox[2:],
                  color["target"],
                  thickness=bbox_thickness)
    cv2.rectangle(im, (0, 0), (im.shape[1] - 1, im.shape[0] - 1),
                  color["border"],
                  thickness=10)

    im = cv2.resize(im, (0, 0), fx=resize_factor, fy=resize_factor)
    im = cv2.putText(im, "template frame", (20, 20), cv2.FONT_HERSHEY_COMPLEX,
                     font_size, color["target"], font_width)
logger.info("Load experiment configuration at: %s" % exp_cfg_path)

# resolve config
root_cfg = root_cfg.test
task, task_cfg = specify_task(root_cfg)
task_cfg.freeze()
# build model
model = model_builder.build(task, task_cfg.model)
# build pipeline
pipeline = pipeline_builder.build(task, task_cfg.pipeline, model)

dev = torch.device(parsed_args.device)
pipeline.set_device(dev)

if __name__ == "__main__":
    rect = xyxy2xywh(bbox)
    pipeline.init(im, rect)

    im_size = np.array((im.shape[1], im.shape[0]), dtype=np.float)
    crop_pos = np.array([parsed_args.shift_x, parsed_args.shift_y])
    im_shift = get_subwindow(im, im_size * crop_pos, im_size, im_size)

    rect_pred = pipeline.update(im_shift)
    bbox_pred = xywh2xyxy(rect_pred)
    bbox_pred = tuple(map(int, bbox_pred))

    im_ = im_shift
    cv2.rectangle(im_, bbox[:2], bbox[2:], color["target"])
    cv2.rectangle(im_, bbox_pred[:2], bbox_pred[2:], color["pred"])
    cv2.rectangle(im_, (0, 0), (im.shape[1] - 1, im.shape[0] - 1),
                  color["border"],