Beispiel #1
0
def test_detection_dataset_init_basic(
    tiny_od_data_path,
    od_data_path_labels,
    tiny_od_mask_data_path,
    tiny_od_keypoint_data_path,
):
    """ Tests that initialization of the Detection Dataset works. """
    data = DetectionDataset(tiny_od_data_path)
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 19
    assert len(data.train_ds) == 20

    # test random seed
    data = DetectionDataset(tiny_od_data_path, seed=9)
    data2 = DetectionDataset(tiny_od_data_path, seed=9)
    assert data.train_dl.dataset.indices == data2.train_dl.dataset.indices
    assert data.test_dl.dataset.indices == data2.test_dl.dataset.indices

    # test mask data
    data = DetectionDataset(
        tiny_od_mask_data_path, mask_dir="segmentation-masks"
    )
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 15
    assert len(data.train_ds) == 16

    # test keypoint data
    data = DetectionDataset(
        tiny_od_keypoint_data_path,
        keypoint_meta={
            "labels": [
                "lid_left_top",
                "lid_right_top",
                "lid_left_bottom",
                "lid_right_bottom",
                "left_bottom",
                "right_bottom",
            ],
            "skeleton": [
                [0, 1],
                [0, 2],
                [1, 3],
                [2, 3],
                [2, 4],
                [3, 5],
                [4, 5],
            ],
            "hflip_inds": [1, 0, 3, 2, 5, 4],
        },
    )
    validate_milkbottle_keypoint_tiny_dataset(data)
    assert len(data.test_ds) == 15
    assert len(data.train_ds) == 16
Beispiel #2
0
def test_detection_dataset_init_train_pct(
    tiny_od_data_path,
    od_data_path_labels,
    tiny_od_mask_data_path,
    tiny_od_keypoint_data_path,
):
    """ Tests that initialization with train_pct."""
    data = DetectionDataset(tiny_od_data_path, train_pct=0.75)
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 9
    assert len(data.train_ds) == 30

    # test mask data
    data = DetectionDataset(
        tiny_od_mask_data_path, train_pct=0.75, mask_dir="segmentation-masks"
    )
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 7
    assert len(data.train_ds) == 24

    # test keypoint data
    data = DetectionDataset(
        tiny_od_keypoint_data_path,
        train_pct=0.75,
        keypoint_meta={
            "labels": [
                "lid_left_top",
                "lid_right_top",
                "lid_left_bottom",
                "lid_right_bottom",
                "left_bottom",
                "right_bottom",
            ],
            "skeleton": [
                [0, 1],
                [0, 2],
                [1, 3],
                [2, 3],
                [2, 4],
                [3, 5],
                [4, 5],
            ],
            "hflip_inds": [1, 0, 3, 2, 5, 4],
        },
    )
    validate_milkbottle_keypoint_tiny_dataset(data)
    assert len(data.test_ds) == 7
    assert len(data.train_ds) == 24
Beispiel #3
0
def tiny_od_detection_keypoint_dataset(tiny_od_keypoint_data_path):
    """ returns a basic detection keypoint dataset. """
    return DetectionDataset(
        tiny_od_keypoint_data_path,
        keypoint_meta={
            "labels": [
                "lid_left_top",
                "lid_right_top",
                "lid_left_bottom",
                "lid_right_bottom",
                "left_bottom",
                "right_bottom",
            ],
            "skeleton": [
                [0, 1],
                [0, 2],
                [1, 3],
                [2, 3],
                [2, 4],
                [3, 5],
                [4, 5],
            ],
            "hflip_inds": [1, 0, 3, 2, 5, 4],
        },
    )
def test_detection_dataset_init_train_pct(tiny_od_data_path,
                                          od_data_path_labels):
    """ Tests that initialization with train_pct."""
    data = DetectionDataset(tiny_od_data_path, train_pct=0.75)
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 9
    assert len(data.train_ds) == 30
Beispiel #5
0
def test_detection_dataset_init_train_pct(tiny_od_data_path,
                                          od_data_path_labels,
                                          tiny_od_mask_data_path):
    """ Tests that initialization with train_pct."""
    data = DetectionDataset(tiny_od_data_path, train_pct=0.75)
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 9
    assert len(data.train_ds) == 30

    # test mask data
    data = DetectionDataset(tiny_od_mask_data_path,
                            train_pct=0.75,
                            mask_dir="segmentation-masks")
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 7
    assert len(data.train_ds) == 24
Beispiel #6
0
def test_detection_dataset_init_basic(tiny_od_data_path, od_data_path_labels,
                                      tiny_od_mask_data_path):
    """ Tests that initialization of the Detection Dataset works. """
    data = DetectionDataset(tiny_od_data_path)
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 19
    assert len(data.train_ds) == 20

    # test random seed
    data = DetectionDataset(tiny_od_data_path, seed=9)
    data2 = DetectionDataset(tiny_od_data_path, seed=9)
    assert data.train_dl.dataset.indices == data2.train_dl.dataset.indices
    assert data.test_dl.dataset.indices == data2.test_dl.dataset.indices

    # test mask data
    data = DetectionDataset(tiny_od_mask_data_path,
                            mask_dir="segmentation-masks")
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 15
    assert len(data.train_ds) == 16
def test_detection_dataset_init_anno_im_dirs(func_tiny_od_data_path,
                                             od_data_path_labels):
    """ Tests that initialization with renamed anno/im dirs.
    NOTE: this test doesn't use the normal tiny_od_data_path fixture since it
    modifies the files in it. instead it uses the function level fixture.
    """
    data_path = Path(func_tiny_od_data_path)
    new_anno_dir_name = "bounding_boxes"
    new_im_dir_name = "photos"
    anno_dir = data_path / "annotations"
    anno_dir.rename(data_path / new_anno_dir_name)
    im_dir = data_path / "images"
    im_dir.rename(data_path / new_im_dir_name)
    data = DetectionDataset(str(data_path),
                            anno_dir=new_anno_dir_name,
                            im_dir=new_im_dir_name)
    validate_detection_dataset(data, od_data_path_labels)
Beispiel #8
0
def od_detection_mask_dataset(tiny_od_mask_data_path):
    """ returns a basic detection mask dataset. """
    return DetectionDataset(tiny_od_mask_data_path,
                            mask_dir="segmentation-masks")
Beispiel #9
0
def od_detection_dataset(tiny_od_data_path):
    """ returns a basic detection dataset. """
    return DetectionDataset(tiny_od_data_path)
Beispiel #10
0
def basic_detection_dataset(tiny_od_data_path) -> DetectionDataset:
    return DetectionDataset(tiny_od_data_path)
def test_detection_dataset_init_basic(tiny_od_data_path, od_data_path_labels):
    """ Tests that initialization of the Detection Dataset works. """
    data = DetectionDataset(tiny_od_data_path)
    validate_detection_dataset(data, od_data_path_labels)
    assert len(data.test_ds) == 19
    assert len(data.train_ds) == 20