-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Country dataset #5138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Country dataset #5138
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
02dc5f7
Add Country211 dataset
puhuk 83921ec
Add Country211 dataset
puhuk 43869e7
Update country211.py
puhuk c383093
Update country211.py
puhuk 21ee738
Code review reflected
puhuk b7b3109
Update test_datasets.py
puhuk 999d386
Update with review
puhuk 7144d5c
inherit from ImageFolder
pmeier c5f2852
Merge branch 'main' into country_dataset
pmeier dc185c9
Update test/test_datasets.py
pmeier 9eb4f11
Docstring + minor test update
NicolasHug f0883a5
Merge branch 'main' of github.com:pytorch/vision into country_dataset
NicolasHug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from pathlib import Path | ||
from typing import Callable, Optional | ||
|
||
from .folder import ImageFolder | ||
from .utils import verify_str_arg, download_and_extract_archive | ||
|
||
|
||
class Country211(ImageFolder): | ||
"""`The Country211 Data Set <https://github.com/openai/CLIP/blob/main/data/country211.md>`_ from OpenAI. | ||
|
||
This dataset was built by filtering the images from the YFCC100m dataset | ||
that have GPS coordinate corresponding to a ISO-3166 country code. The | ||
dataset is balanced by sampling 150 train images, 50 validation images, and | ||
100 test images images for each country. | ||
|
||
Args: | ||
root (string): Root directory of the dataset. | ||
split (string, optional): The dataset split, supports ``"train"`` (default), ``"valid"`` and ``"test"``. | ||
transform (callable, optional): A function/transform that takes in an PIL image and returns a transformed | ||
version. E.g, ``transforms.RandomCrop``. | ||
target_transform (callable, optional): A function/transform that takes in the target and transforms it. | ||
download (bool, optional): If True, downloads the dataset from the internet and puts it into | ||
``root/country211/``. If dataset is already downloaded, it is not downloaded again. | ||
""" | ||
|
||
_URL = "https://openaipublic.azureedge.net/clip/data/country211.tgz" | ||
_MD5 = "84988d7644798601126c29e9877aab6a" | ||
|
||
def __init__( | ||
self, | ||
root: str, | ||
split: str = "train", | ||
transform: Optional[Callable] = None, | ||
target_transform: Optional[Callable] = None, | ||
download: bool = True, | ||
NicolasHug marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> None: | ||
self._split = verify_str_arg(split, "split", ("train", "valid", "test")) | ||
|
||
root = Path(root).expanduser() | ||
self.root = str(root) | ||
self._base_folder = root / "country211" | ||
|
||
if download: | ||
self._download() | ||
|
||
if not self._check_exists(): | ||
raise RuntimeError("Dataset not found. You can use download=True to download it") | ||
|
||
super().__init__(str(self._base_folder / self._split), transform=transform, target_transform=target_transform) | ||
self.root = str(root) | ||
|
||
def _check_exists(self) -> bool: | ||
return self._base_folder.exists() and self._base_folder.is_dir() | ||
|
||
def _download(self) -> None: | ||
if self._check_exists(): | ||
return | ||
download_and_extract_archive(self._URL, download_root=self.root, md5=self._MD5) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.