コード例 #1
0
def func_tiny_od_data_path(tmp_session) -> str:
    """ Returns the path to the fridge object detection dataset. """
    return unzip_url(
        od_urls.fridge_objects_tiny_path,
        fpath=f"{tmp_session}/tmp",
        dest=f"{tmp_session}/tmp",
        exist_ok=True,
    )
コード例 #2
0
def tiny_ic_data_path(tmp_session) -> str:
    """ Returns the path to the tiny fridge objects dataset. """
    return unzip_url(
        ic_urls.fridge_objects_tiny_path,
        fpath=tmp_session,
        dest=tmp_session,
        exist_ok=True,
    )
コード例 #3
0
def tiny_od_mask_data_path(tmp_session) -> str:
    """ Returns the path to the fridge object detection mask dataset. """
    return unzip_url(
        od_urls.fridge_objects_mask_tiny_path,
        fpath=tmp_session,
        dest=tmp_session,
        exist_ok=True,
    )
コード例 #4
0
def tiny_od_keypoint_data_path(tmp_session) -> str:
    """ Returns the path to the fridge object detection keypoint dataset. """
    return unzip_url(
        od_urls.fridge_objects_keypoint_milk_bottle_tiny_path,
        fpath=tmp_session,
        dest=tmp_session,
        exist_ok=True,
    )
コード例 #5
0
ファイル: conftest.py プロジェクト: sravan90/ComputerVision
def tiny_ic_databunch(tmp_session):
    """ Returns a databunch object for the tiny fridge objects dataset. """
    im_paths = unzip_url(Urls.fridge_objects_tiny_path,
                         tmp_session,
                         exist_ok=True)
    return (ImageList.from_folder(im_paths).split_by_rand_pct(
        valid_pct=0.1, seed=20).label_from_folder().transform(
            size=50).databunch(bs=16).normalize(imagenet_stats))
コード例 #6
0
ファイル: conftest.py プロジェクト: sravan90/ComputerVision
def testing_im_list(tmp_session):
    """ Set of 5 images from the can/ folder of the Fridge Objects dataset
     used to test positive example rank calculations"""
    im_paths = unzip_url(Urls.fridge_objects_tiny_path,
                         tmp_session,
                         exist_ok=True)
    can_im_paths = os.listdir(os.path.join(im_paths, "can"))
    can_im_paths = [
        os.path.join(im_paths, "can", im_name) for im_name in can_im_paths
    ][0:5]
    return can_im_paths
コード例 #7
0
def test_unzip_url_exist_ok(tmp_path):
    """
    Test if exist_ok is true and (file exists, file does not exist)
    """
    os.makedirs(tmp_path / "fridgeObjects")
    fridge_object_path = unzip_url(Urls.fridge_objects_path,
                                   fpath=tmp_path,
                                   dest=tmp_path,
                                   exist_ok=True)
    # should skip unzipping since the path already exist
    assert len(os.listdir(fridge_object_path)) == 0
    shutil.rmtree(tmp_path / "fridgeObjects")
    fridge_object_path = unzip_url(
        Urls.fridge_objects_watermark_path,
        fpath=tmp_path,
        dest=tmp_path,
        exist_ok=True,
    )
    # should unzip all four data class directories
    assert len(os.listdir(fridge_object_path)) == 4
コード例 #8
0
def _test_url_data(url: str, path: Union[Path, str], dir_name: str):
    dest_path = os.path.join(path, dir_name)
    # dir should not exist yet for valid testing
    assert not os.path.isdir(dest_path)

    unzipped_path = unzip_url(url, fpath=path, dest=path, exist_ok=True)
    # assert zip file exists
    assert os.path.exists(os.path.join(path, f"{dir_name}.zip"))
    # assert unzipped file (titled {dir_name}) exists
    assert os.path.exists(dest_path)
    # assert unzipped file equals the returned {data_path}
    assert os.path.realpath(dest_path) == os.path.realpath(unzipped_path)
コード例 #9
0
def tiny_seg_data_path(tmp_session, seg_classes) -> str:
    """ Returns the path to the segmentation tiny fridge objects dataset. """
    path = unzip_url(
        seg_urls.fridge_objects_tiny_path,
        fpath=tmp_session,
        dest=tmp_session,
        exist_ok=True,
    )
    classes_path = Path(path) / "classes.txt"
    with open(classes_path, "w") as f:
        for c in seg_classes:
            f.write(c + "\n")
    return path
コード例 #10
0
def test_unzip_url_not_exist_ok(tmp_path):
    """
    Test if exist_ok is false and (file exists, file does not exist)
    """
    os.makedirs(tmp_path / "fridgeObjects")

    # should throw an error
    with pytest.raises(FileExistsError):
        unzip_url(
            Urls.fridge_objects_path,
            fpath=tmp_path,
            dest=tmp_path,
            exist_ok=False,
        )
    shutil.rmtree(tmp_path / "fridgeObjects")
    os.remove(tmp_path / "fridgeObjects.zip")
    fridge_object_path = unzip_url(Urls.fridge_objects_path,
                                   fpath=tmp_path,
                                   dest=tmp_path,
                                   exist_ok=False)

    # should unzip all four data class directories
    assert len(os.listdir(fridge_object_path)) == 4
コード例 #11
0
ファイル: conftest.py プロジェクト: sravan90/ComputerVision
def testing_databunch(tmp_session):
    """ Builds a databunch from the Fridge Objects
    and returns its validation component that is used
    to test comparative_set_builder"""
    im_paths = unzip_url(Urls.fridge_objects_tiny_path,
                         tmp_session,
                         exist_ok=True)
    can_im_paths = os.listdir(os.path.join(im_paths, "can"))
    can_im_paths = [
        os.path.join(im_paths, "can", im_name) for im_name in can_im_paths
    ][0:5]
    random.seed(642)
    data = (ImageList.from_folder(im_paths).split_by_rand_pct(
        valid_pct=0.2, seed=20).label_from_folder().transform(
            size=300).databunch(bs=16).normalize(imagenet_stats))

    validation_bunch = data.valid_ds

    return validation_bunch
コード例 #12
0
ファイル: conftest.py プロジェクト: sravan90/ComputerVision
def multilabel_ic_data_path(tmp_session) -> str:
    """ Returns the path to the tiny fridge objects dataset. """
    return unzip_url(Urls.multilabel_fridge_objects_path,
                     tmp_session,
                     exist_ok=True)