Beispiel #1
0
    def _get_sym_infos(self, dataset_name):
        """label based keys."""
        if dataset_name in self.sym_infos:
            return self.sym_infos[dataset_name]

        dset_meta = MetadataCatalog.get(dataset_name)
        ref_key = dset_meta.ref_key
        data_ref = ref.__dict__[ref_key]
        objs = dset_meta.objs
        cfg = self.cfg

        cur_sym_infos = {}
        loaded_models_info = data_ref.get_models_info()
        for i, obj_name in enumerate(objs):
            obj_id = data_ref.obj2id[obj_name]
            model_info = loaded_models_info[str(obj_id)]
            if "symmetries_discrete" in model_info or "symmetries_continuous" in model_info:
                sym_transforms = misc.get_symmetry_transformations(
                    model_info, max_sym_disc_step=0.01)
                sym_info = np.array([sym["R"] for sym in sym_transforms],
                                    dtype=np.float32)
            else:
                sym_info = None
            cur_sym_infos[i] = sym_info

        self.sym_infos[dataset_name] = cur_sym_infos
        return self.sym_infos[dataset_name]
Beispiel #2
0
def get_ycbv_metadata(obj_names, ref_key):
    """task specific metadata."""
    data_ref = ref.__dict__[ref_key]

    cur_sym_infos = {}  # label based key
    loaded_models_info = data_ref.get_models_info()

    for i, obj_name in enumerate(obj_names):
        obj_id = data_ref.obj2id[obj_name]
        model_info = loaded_models_info[str(obj_id)]
        if "symmetries_discrete" in model_info or "symmetries_continuous" in model_info:
            sym_transforms = misc.get_symmetry_transformations(model_info, max_sym_disc_step=0.01)
            sym_info = np.array([sym["R"] for sym in sym_transforms], dtype=np.float32)
        else:
            sym_info = None
        cur_sym_infos[i] = sym_info

    meta = {"thing_classes": obj_names, "sym_infos": cur_sym_infos}
    return meta
Beispiel #3
0
    # axis_est = np.array([1, 2, 0])
    # axis_gt = np.array([0,2,1])
    # est_rot = axangle2mat(axis_est, -pi/3)
    # gt_rot = axangle2mat(axis_gt, pi)
    # sym_info = axangle2mat([0, 0, 1], pi)
    # print('sym_info', sym_info)

    cls_idx = 3
    obj_id = cls_idx - 1
    trans = np.array([-0.0021458883, 0.0804758, 0.78142926])
    axis_est = np.array([1, 2, 0])
    axis_gt = np.array([0, 2, 1])
    est_rot = axangle2mat(axis_est, -pi / 3)
    gt_rot = axangle2mat(axis_gt, pi)

    transforms_sym = get_symmetry_transformations(models_info[cls_idx], max_sym_disc_step=0.01)
    # sym_info = axangle2mat([0, 0, 1], pi)
    sym_info = np.array([sym["R"] for sym in transforms_sym])
    print("sym_info", sym_info.shape)

    est_pose = np.random.rand(3, 4)
    est_pose[:, :3] = est_rot
    gt_pose = np.random.rand(3, 4)
    gt_pose[:, :3] = gt_rot
    rd_ori = re(est_rot, gt_rot)

    t = time.perf_counter()
    for i in range(3000):
        closest_rot = get_closest_rot(est_rot, gt_rot, sym_info)
    print(("calculate closest rot {}s".format((time.perf_counter() - t) / 3000)))
    closest_pose = np.copy(gt_pose)
Beispiel #4
0
    ]:
        misc.log("Loading object models...")
        for obj_id in dp_model["obj_ids"]:
            models[obj_id] = inout.load_ply(dp_model["model_tpath"].format(obj_id=obj_id))

    # Load models info.
    models_info = None
    if p["error_type"] in ["ad", "add", "adi", "vsd", "mssd", "mspd", "cus", "reteS", "reS", "teS", "projS"]:
        models_info = inout.load_json(dp_model["models_info_path"], keys_to_int=True)

    # Get sets of symmetry transformations for the object models.
    models_sym = None
    if p["error_type"] in ["mssd", "mspd", "reteS", "reS", "teS", "projS"]:
        models_sym = {}
        for obj_id in dp_model["obj_ids"]:
            models_sym[obj_id] = misc.get_symmetry_transformations(models_info[obj_id], p["max_sym_disc_step"])

    # Initialize a renderer.
    ren = None
    if p["error_type"] in ["vsd", "cus"]:
        misc.log("Initializing renderer...")
        width, height = dp_split["im_size"]
        if p["renderer_type"] in ["python", "cpp"]:
            ren = renderer.create_renderer(width, height, p["renderer_type"], mode="depth")
            for obj_id in dp_model["obj_ids"]:
                ren.add_object(obj_id, dp_model["model_tpath"].format(obj_id=obj_id))
        elif p["renderer_type"] == "egl":
            from lib.egl_renderer.egl_renderer import EGLRenderer

            model_paths = [dp_model["model_tpath"].format(obj_id=obj_id) for obj_id in dp_model["obj_ids"]]
            texture_paths = [