def test_eq(self):
        translation = [1, 2, 3]
        rotation = quaternion(1, 2, 3, 4)

        box3d1 = LabeledBox3D(
            size=[1, 2, 3],
            translation=translation,
            rotation=rotation,
            category="cat",
            attributes={"gender": "male"},
        )
        box3d2 = LabeledBox3D(
            size=[1, 2, 3],
            translation=translation,
            rotation=rotation,
            category="cat",
            attributes={"gender": "male"},
        )
        box3d3 = LabeledBox3D(
            size=[1, 2, 5],
            translation=translation,
            rotation=rotation,
            category="cat",
            attributes={"gender": "male"},
        )

        assert box3d1 == box3d2
        assert box3d1 != box3d3
    def test_rmul(self):
        size = [1, 2, 3]
        translation = [1, 2, 3]
        rotation = quaternion(0, 1, 0, 0)
        transform = Transform3D(translation, rotation)
        quaternion_1 = quaternion(1, 2, 3, 4)

        labeledbox3d = LabeledBox3D(
            size=size,
            translation=translation,
            rotation=rotation,
            category="cat",
            attributes={"gender": "male"},
            instance="12345",
        )

        assert labeledbox3d.__rmul__(transform) == LabeledBox3D(
            size=size,
            translation=[2, 0, 0],
            rotation=[-1, 0, 0, 0],
            category="cat",
            attributes={"gender": "male"},
            instance="12345",
        )

        assert labeledbox3d.__rmul__(quaternion_1) == LabeledBox3D(
            size=size,
            translation=[1.7999999999999996, 2, 2.6],
            rotation=[-2, 1, 4, -3],
            category="cat",
            attributes={"gender": "male"},
            instance="12345",
        )

        assert labeledbox3d.__rmul__(1) == NotImplemented
예제 #3
0
def _load_labels(boxes: List[Dict[str, Any]]) -> List[LabeledBox3D]:
    labels = []
    for box in boxes:
        dimension = box["dimensions"]
        position = box["position"]

        attributes = box["attributes"]
        attributes["stationary"] = box["stationary"]
        attributes["camera_used"] = box["camera_used"]
        attributes["points_count"] = box["points_count"]

        label = LabeledBox3D(
            size=(
                dimension[
                    "y"],  # The "y" dimension is the width from front to back.
                dimension[
                    "x"],  # The "x" dimension is the width from left to right.
                dimension["z"],
            ),
            translation=(
                position[
                    "x"],  # "x" axis points to the forward facing direction of the object.
                position[
                    "y"],  # "y" axis points to the left direction of the object.
                position["z"],
            ),
            rotation=quaternion.from_rotation_vector((0, 0, box["yaw"])),
            category=box["label"],
            attributes=attributes,
            instance=box["uuid"],
        )
        labels.append(label)

    return labels
    def test_loads(self):
        contents = {
            "box3d": {
                "translation": {
                    "x": 1,
                    "y": 2,
                    "z": 3
                },
                "rotation": {
                    "w": 1,
                    "x": 2,
                    "y": 3,
                    "z": 4
                },
                "size": {
                    "x": 1,
                    "y": 2,
                    "z": 3
                },
            },
            "category": "cat",
            "attributes": {
                "gender": "male"
            },
            "instance": 12345,
        }
        labeledbox3d = LabeledBox3D.loads(contents)

        assert labeledbox3d.category == "cat"
        assert labeledbox3d.attributes == {"gender": "male"}
        assert labeledbox3d.instance == 12345

        assert labeledbox3d.translation == Vector3D(1, 2, 3)
        assert labeledbox3d.rotation == quaternion(1, 2, 3, 4)
        assert labeledbox3d.size == Vector3D(1, 2, 3)
예제 #5
0
def _get_labeled_box(
    instance_annotation: Dict[str, Any],
    annotation_info: Dict[str, Any],
) -> LabeledBox3D:
    instance = instance_annotation["instance_token"]
    category = annotation_info["category"][annotation_info["instance"][instance]["category_token"]][
        "name"
    ]
    attributes = {}
    for attribute_token in instance_annotation["attribute_tokens"]:
        attribute_full_name = annotation_info["attribute"][attribute_token]["name"]
        key, value = attribute_full_name.rsplit(".", 1)
        attributes[_ATTRIBUTE_KEYS[key]] = value
    attributes["visibility"] = annotation_info["visibility"][
        instance_annotation["visibility_token"]
    ]["level"]

    width, length, height = instance_annotation["size"]
    return LabeledBox3D(
        translation=instance_annotation["translation"],
        rotation=instance_annotation["rotation"],
        size=(length, width, height),
        category=category,
        instance=instance,
        attributes=attributes,
    )
예제 #6
0
def DeepRoute(path: str) -> Dataset:
    """`DeepRoute <https://gas.graviti.cn/dataset/graviti-open-dataset\
    /DeepRoute>`_ dataset.

    The file structure should be like::

        <path>
            pointcloud/
                00001.bin
                00002.bin
                ...
                10000.bin
            groundtruth/
                00001.txt
                00002.txt
                ...
                10000.txt

    Arguments:
        path: The root directory of the dataset.

    Returns:
        Loaded :class:`~tensorbay.dataset.dataset.Dataset` instance.

    """
    root_path = os.path.abspath(os.path.expanduser(path))

    dataset = Dataset(DATASET_NAME)
    dataset.load_catalog(os.path.join(os.path.dirname(__file__), "catalog.json"))
    segment = dataset.create_segment()

    point_cloud_paths = glob(os.path.join(root_path, "pointcloud", "*.bin"))

    for point_cloud_path in point_cloud_paths:
        point_cloud_id = os.path.splitext(os.path.basename(point_cloud_path))[0]
        label_path = os.path.join(root_path, "groundtruth", f"{point_cloud_id}.txt")

        data = Data(point_cloud_path)
        data.label.box3d = []

        with open(label_path, encoding="utf-8") as fp:
            annotations = json.load(fp)["objects"]

        for annotation in annotations:
            bounding_box = annotation["bounding_box"]
            position = annotation["position"]

            label = LabeledBox3D(
                size=(bounding_box["length"], bounding_box["width"], bounding_box["height"]),
                translation=(position["x"], position["y"], position["z"]),
                rotation=from_rotation_vector((0, 0, annotation["heading"])),
                category=annotation["type"],
            )
            data.label.box3d.append(label)

        segment.append(data)

    return dataset
    def test_init(self):
        translation = Vector3D(1, 2, 3)
        rotation = quaternion(1, 2, 3, 4)
        size = Vector3D(1, 2, 3)

        labeledbox3d = LabeledBox3D(
            size=size,
            translation=translation,
            rotation=rotation,
            category="cat",
            attributes={"gender": "male"},
            instance="12345",
        )

        assert labeledbox3d.translation == translation
        assert labeledbox3d.rotation == rotation
        assert labeledbox3d.size == size
        assert labeledbox3d.category == "cat"
        assert labeledbox3d.attributes == {"gender": "male"}
        assert labeledbox3d.instance == "12345"
    def test_dumps(self):
        translation = [1, 2, 3]
        rotation = quaternion(1, 2, 3, 4)
        size = [1, 2, 3]

        labeledbox3d = LabeledBox3D(
            size=size,
            translation=translation,
            rotation=rotation,
            category="cat",
            attributes={"gender": "male"},
            instance="12345",
        )

        assert labeledbox3d.dumps() == {
            "box3d": {
                "translation": {
                    "x": 1,
                    "y": 2,
                    "z": 3
                },
                "rotation": {
                    "w": 1,
                    "x": 2,
                    "y": 3,
                    "z": 4
                },
                "size": {
                    "x": 1,
                    "y": 2,
                    "z": 3
                },
            },
            "category": "cat",
            "attributes": {
                "gender": "male"
            },
            "instance": "12345",
        }
예제 #9
0
def NeolixOD(path: str) -> Dataset:
    """`Neolix OD <https://gas.graviti.cn/dataset\
    /graviti-open-dataset/NeolixOD>`_ dataset.

    The file structure should be like::

        <path>
            bins/
                <id>.bin
            labels/
                <id>.txt
            ...

    Arguments:
        path: The root directory of the dataset.

    Returns:
        Loaded :class:`~tensorbay.dataset.dataset.Dataset` instance.

    """
    root_path = os.path.abspath(os.path.expanduser(path))

    dataset = Dataset(DATASET_NAME)
    dataset.load_catalog(
        os.path.join(os.path.dirname(__file__), "catalog.json"))
    segment = dataset.create_segment()

    point_cloud_paths = glob(os.path.join(root_path, "bins", "*.bin"))

    for point_cloud_path in point_cloud_paths:
        data = Data(point_cloud_path)
        data.label.box3d = []

        point_cloud_id = os.path.basename(point_cloud_path)[:6]
        label_path = os.path.join(root_path, "labels", f"{point_cloud_id}.txt")

        with open(label_path, encoding="utf-8") as fp:
            for label_value_raw in fp:
                label_value = label_value_raw.rstrip().split()
                label = LabeledBox3D(
                    size=[
                        float(label_value[10]),
                        float(label_value[9]),
                        float(label_value[8])
                    ],
                    translation=[
                        float(label_value[11]),
                        float(label_value[12]),
                        float(label_value[13]) + 0.5 * float(label_value[8]),
                    ],
                    rotation=from_rotation_vector(
                        (0, 0, float(label_value[14]))),
                    category=label_value[0],
                    attributes={
                        "Occlusion": int(label_value[1]),
                        "Truncation": bool(int(label_value[2])),
                        "Alpha": float(label_value[3]),
                    },
                )
                data.label.box3d.append(label)

        segment.append(data)
    return dataset