forked from isaaccorley/torchrs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request isaaccorley#33 from isaaccorley/datasets-ucm
UC Merced Dataset
- Loading branch information
Showing
6 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,4 @@ | ||
mkdir -p .data/ | ||
wget http://weegee.vision.ucmerced.edu/datasets/UCMerced_LandUse.zip -O UCMerced_LandUse.zip | ||
unzip UCMerced_LandUse.zip -d .data/ | ||
rm UCMerced_LandUse.zip |
This file contains 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 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,21 @@ | ||
import os | ||
|
||
import torchvision.transforms as T | ||
from torchvision.datasets import ImageFolder | ||
|
||
|
||
class UCM(ImageFolder): | ||
""" UC Merced Land Use dataset from 'Bag-Of-Visual-Words and | ||
Spatial Extensions for Land-Use Classification', Yang at al. (2010) | ||
https://faculty.ucmerced.edu/snewsam/papers/Yang_ACMGIS10_BagOfVisualWords.pdf | ||
""" | ||
def __init__( | ||
self, | ||
root: str = ".data/UCMerced_LandUse", | ||
transform: T.Compose = T.Compose([T.ToTensor()]) | ||
): | ||
super().__init__( | ||
root=os.path.join(root, "Images"), | ||
transform=transform | ||
) |
This file contains 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 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,26 @@ | ||
from typing import Optional | ||
|
||
import torchvision.transforms as T | ||
|
||
from torchrs.datasets.utils import dataset_split | ||
from torchrs.train.datamodules import BaseDataModule | ||
from torchrs.datasets import UCM | ||
|
||
|
||
class UCMDataModule(BaseDataModule): | ||
|
||
def __init__( | ||
self, | ||
root: str = ".data/UCMerced_LandUse", | ||
transform: T.Compose = T.Compose([T.ToTensor()]), | ||
*args, **kwargs | ||
): | ||
super().__init__(*args, **kwargs) | ||
self.root = root | ||
self.transform = transform | ||
|
||
def setup(self, stage: Optional[str] = None): | ||
dataset = UCM(root=self.root, transform=self.transform) | ||
self.train_dataset, self.val_dataset, self.test_dataset = dataset_split( | ||
dataset, val_pct=self.val_split, test_pct=self.test_split | ||
) |