-
Notifications
You must be signed in to change notification settings - Fork 7.1k
add Country211 prototype dataset #5506
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b8df1c8
add country211
2afa6c4
remove unused import
4b8d518
map val to valid and use path comparator
927ae6e
remove unused import
3813fb6
resolve keyerror
7fe356a
map split names in dataset mock
1fb15f7
Merge branch 'main' into country211
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
211 changes: 211 additions & 0 deletions
211
torchvision/prototype/datasets/_builtin/country211.categories
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,211 @@ | ||
AD | ||
AE | ||
AF | ||
AG | ||
AI | ||
AL | ||
AM | ||
AO | ||
AQ | ||
AR | ||
AT | ||
AU | ||
AW | ||
AX | ||
AZ | ||
BA | ||
BB | ||
BD | ||
BE | ||
BF | ||
BG | ||
BH | ||
BJ | ||
BM | ||
BN | ||
BO | ||
BQ | ||
BR | ||
BS | ||
BT | ||
BW | ||
BY | ||
BZ | ||
CA | ||
CD | ||
CF | ||
CH | ||
CI | ||
CK | ||
CL | ||
CM | ||
CN | ||
CO | ||
CR | ||
CU | ||
CV | ||
CW | ||
CY | ||
CZ | ||
DE | ||
DK | ||
DM | ||
DO | ||
DZ | ||
EC | ||
EE | ||
EG | ||
ES | ||
ET | ||
FI | ||
FJ | ||
FK | ||
FO | ||
FR | ||
GA | ||
GB | ||
GD | ||
GE | ||
GF | ||
GG | ||
GH | ||
GI | ||
GL | ||
GM | ||
GP | ||
GR | ||
GS | ||
GT | ||
GU | ||
GY | ||
HK | ||
HN | ||
HR | ||
HT | ||
HU | ||
ID | ||
IE | ||
IL | ||
IM | ||
IN | ||
IQ | ||
IR | ||
IS | ||
IT | ||
JE | ||
JM | ||
JO | ||
JP | ||
KE | ||
KG | ||
KH | ||
KN | ||
KP | ||
KR | ||
KW | ||
KY | ||
KZ | ||
LA | ||
LB | ||
LC | ||
LI | ||
LK | ||
LR | ||
LT | ||
LU | ||
LV | ||
LY | ||
MA | ||
MC | ||
MD | ||
ME | ||
MF | ||
MG | ||
MK | ||
ML | ||
MM | ||
MN | ||
MO | ||
MQ | ||
MR | ||
MT | ||
MU | ||
MV | ||
MW | ||
MX | ||
MY | ||
MZ | ||
NA | ||
NC | ||
NG | ||
NI | ||
NL | ||
NO | ||
NP | ||
NZ | ||
OM | ||
PA | ||
PE | ||
PF | ||
PG | ||
PH | ||
PK | ||
PL | ||
PR | ||
PS | ||
PT | ||
PW | ||
PY | ||
QA | ||
RE | ||
RO | ||
RS | ||
RU | ||
RW | ||
SA | ||
SB | ||
SC | ||
SD | ||
SE | ||
SG | ||
SH | ||
SI | ||
SJ | ||
SK | ||
SL | ||
SM | ||
SN | ||
SO | ||
SS | ||
SV | ||
SX | ||
SY | ||
SZ | ||
TG | ||
TH | ||
TJ | ||
TL | ||
TM | ||
TN | ||
TO | ||
TR | ||
TT | ||
TW | ||
TZ | ||
UA | ||
UG | ||
US | ||
UY | ||
UZ | ||
VA | ||
VE | ||
VG | ||
VI | ||
VN | ||
VU | ||
WS | ||
XK | ||
YE | ||
ZA | ||
ZM | ||
ZW |
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,56 @@ | ||
import pathlib | ||
from typing import Any, Dict, List, Tuple | ||
|
||
from torchdata.datapipes.iter import IterDataPipe, Mapper, Filter | ||
from torchvision.prototype.datasets.utils import Dataset, DatasetConfig, DatasetInfo, HttpResource, OnlineResource | ||
from torchvision.prototype.datasets.utils._internal import path_comparator, hint_sharding, hint_shuffling | ||
from torchvision.prototype.features import EncodedImage, Label | ||
|
||
|
||
class Country211(Dataset): | ||
def _make_info(self) -> DatasetInfo: | ||
return DatasetInfo( | ||
"country211", | ||
homepage="https://github.com/openai/CLIP/blob/main/data/country211.md", | ||
valid_options=dict(split=("train", "val", "test")), | ||
) | ||
|
||
def resources(self, config: DatasetConfig) -> List[OnlineResource]: | ||
return [ | ||
HttpResource( | ||
"https://openaipublic.azureedge.net/clip/data/country211.tgz", | ||
sha256="c011343cdc1296a8c31ff1d7129cf0b5e5b8605462cffd24f89266d6e6f4da3c", | ||
) | ||
] | ||
|
||
_SPLIT_NAME_MAPPER = { | ||
"train": "train", | ||
"val": "valid", | ||
"test": "test", | ||
} | ||
|
||
def _prepare_sample(self, data: Tuple[str, Any]) -> Dict[str, Any]: | ||
path, buffer = data | ||
category = pathlib.Path(path).parent.name | ||
return dict( | ||
label=Label.from_category(category, categories=self.categories), | ||
path=path, | ||
image=EncodedImage.from_file(buffer), | ||
) | ||
|
||
def _filter_split(self, data: Tuple[str, Any], *, split: str) -> bool: | ||
return pathlib.Path(data[0]).parent.parent.name == split | ||
|
||
def _make_datapipe( | ||
self, resource_dps: List[IterDataPipe], *, config: DatasetConfig | ||
) -> IterDataPipe[Dict[str, Any]]: | ||
dp = resource_dps[0] | ||
dp = Filter(dp, path_comparator("parent.parent.name", self._SPLIT_NAME_MAPPER[config.split])) | ||
dp = hint_sharding(dp) | ||
dp = hint_shuffling(dp) | ||
return Mapper(dp, self._prepare_sample) | ||
|
||
def _generate_categories(self, root: pathlib.Path) -> List[str]: | ||
resources = self.resources(self.default_config) | ||
dp = resources[0].load(root) | ||
return sorted({pathlib.Path(path).parent.name for path, _ in dp}) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed.