-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[WIP] UCF101 prototype with utilities for video loading #4838
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
Open
bjuncek
wants to merge
52
commits into
pytorch:main
Choose a base branch
from
bjuncek:bkorbar/prototypes/ucf101
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
9c9b27e
stash
bjuncek e00c095
Merge branch 'pytorch:main' into bkorbar/prototypes/ucf101
bjuncek 914380f
base implementation
9dd6786
Format and add documentation to the video utilities
7ad8357
simple driver for Philip to play with
dc205e9
format ucf101 and lint stuff
711adf3
Update torchvision/prototype/datasets/_builtin/ucf101.py
bjuncek 56c1779
Update torchvision/prototype/datasets/_builtin/ucf101.py
bjuncek 65f3c64
Update torchvision/prototype/datasets/video_utils.py
bjuncek 017e9b9
Merge branch 'main' into bkorbar/prototypes/ucf101
bjuncek 666ca6e
Merge branch 'main' into bkorbar/prototypes/ucf101
bjuncek acc0e54
address https://github.com/pytorch/vision/pull/4838#pullrequestreview…
c209153
Update torchvision/prototype/datasets/_builtin/ucf101.py
bjuncek 31c0eb7
Merge branch 'bkorbar/prototypes/ucf101' of https://github.com/bjunce…
f5eb8fd
use internal utils
0a66ff0
remove transform antipattern
d29d22b
change return/pop stuff
cf4f354
remove unnecessary and uncalled methods
52b2b67
make changes to catch up with the master
5e2f15d
minor flake
b608f6d
lint
4f281c4
add video default decoder
ab6a2b8
revert changes to the decoder
bjuncek 9800f8e
Apply suggestions from code review
bjuncek 64b644f
apply suggestions from code review
7557931
Merge branch 'bkorbar/prototypes/ucf101' of https://github.com/bjunce…
18eb9c0
Merge branch 'main' into bkorbar/prototypes/ucf101
pmeier 587723e
Update torchvision/prototype/datasets/_builtin/ucf101.py
bjuncek a3737ab
addressing comments 1
8fce5ff
remove shuffler comment
a10a3a0
remove main.py
697fdfd
clange and flake being mad at me
ebef4f2
Merge branch 'main' into bkorbar/prototypes/ucf101
bjuncek 62078b6
Merge branch 'main' into bkorbar/prototypes/ucf101
bjuncek a574089
addig type annotations
d809cb9
pass flake8
8f57ee6
Decoder typing change
8f21f0e
remove unused parameters
8dbda84
fixing _api with decoder changes
788d82a
build errors
31a8929
remove unused
84cdecb
Merge branch 'main' into bkorbar/prototypes/ucf101
pmeier 4386c48
fix python lint
pmeier 97bd457
cleanup decoder
pmeier 4609783
mypy fix
1c77e6f
Merge branch 'bkorbar/prototypes/ucf101' of https://github.com/bjunce…
6019ce7
[DIRTY] Merge branch 'main' into bkorbar/prototypes/ucf101
pmeier 25c3668
revert decoder changes
pmeier 08a616c
add categories and fix data loading
pmeier 0675649
cleanup
pmeier 381f70e
Merge branch 'main' into bkorbar/prototypes/ucf101
pmeier f1a69e0
use shuffling hint
pmeier 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
101 changes: 101 additions & 0 deletions
101
torchvision/prototype/datasets/_builtin/ucf101.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,101 @@ | ||
ApplyEyeMakeup | ||
ApplyLipstick | ||
Archery | ||
BabyCrawling | ||
BalanceBeam | ||
BandMarching | ||
BaseballPitch | ||
Basketball | ||
BasketballDunk | ||
BenchPress | ||
Biking | ||
Billiards | ||
BlowDryHair | ||
BlowingCandles | ||
BodyWeightSquats | ||
Bowling | ||
BoxingPunchingBag | ||
BoxingSpeedBag | ||
BreastStroke | ||
BrushingTeeth | ||
CleanAndJerk | ||
CliffDiving | ||
CricketBowling | ||
CricketShot | ||
CuttingInKitchen | ||
Diving | ||
Drumming | ||
Fencing | ||
FieldHockeyPenalty | ||
FloorGymnastics | ||
FrisbeeCatch | ||
FrontCrawl | ||
GolfSwing | ||
Haircut | ||
Hammering | ||
HammerThrow | ||
HandstandPushups | ||
HandstandWalking | ||
HeadMassage | ||
HighJump | ||
HorseRace | ||
HorseRiding | ||
HulaHoop | ||
IceDancing | ||
JavelinThrow | ||
JugglingBalls | ||
JumpingJack | ||
JumpRope | ||
Kayaking | ||
Knitting | ||
LongJump | ||
Lunges | ||
MilitaryParade | ||
Mixing | ||
MoppingFloor | ||
Nunchucks | ||
ParallelBars | ||
PizzaTossing | ||
PlayingCello | ||
PlayingDaf | ||
PlayingDhol | ||
PlayingFlute | ||
PlayingGuitar | ||
PlayingPiano | ||
PlayingSitar | ||
PlayingTabla | ||
PlayingViolin | ||
PoleVault | ||
PommelHorse | ||
PullUps | ||
Punch | ||
PushUps | ||
Rafting | ||
RockClimbingIndoor | ||
RopeClimbing | ||
Rowing | ||
SalsaSpin | ||
ShavingBeard | ||
Shotput | ||
SkateBoarding | ||
Skiing | ||
Skijet | ||
SkyDiving | ||
SoccerJuggling | ||
SoccerPenalty | ||
StillRings | ||
SumoWrestling | ||
Surfing | ||
Swing | ||
TableTennisShot | ||
TaiChi | ||
TennisSwing | ||
ThrowDiscus | ||
TrampolineJumping | ||
Typing | ||
UnevenBars | ||
VolleyballSpiking | ||
WalkingWithDog | ||
WallPushups | ||
WritingOnBoard | ||
YoYo |
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,102 @@ | ||
import csv | ||
import io | ||
import pathlib | ||
from typing import Any, Callable, Dict, List, Optional, Tuple, cast | ||
|
||
import torch | ||
from torch.utils.data import IterDataPipe | ||
from torch.utils.data.datapipes.iter import Filter, Mapper | ||
from torchdata.datapipes.iter import CSVParser, IterKeyZipper | ||
from torchvision.prototype.datasets.utils import ( | ||
Dataset, | ||
DatasetConfig, | ||
DatasetInfo, | ||
HttpResource, | ||
OnlineResource, | ||
DatasetType, | ||
) | ||
from torchvision.prototype.datasets.utils._internal import ( | ||
path_accessor, | ||
path_comparator, | ||
hint_sharding, | ||
hint_shuffling, | ||
) | ||
from torchvision.prototype.features import Label | ||
|
||
csv.register_dialect("ucf101", delimiter=" ") | ||
|
||
|
||
class UCF101(Dataset): | ||
""" | ||
`UCF101 <https://www.crcv.ucf.edu/data/UCF101.php>`_ dataset. | ||
|
||
UCF101 is an action recognition video dataset, containing 101 classes | ||
of various human actions. | ||
""" | ||
|
||
def _make_info(self) -> DatasetInfo: | ||
return DatasetInfo( | ||
"ucf101", | ||
type=DatasetType.VIDEO, | ||
dependencies=("rarfile",), | ||
valid_options=dict( | ||
split=("train", "test"), | ||
fold=("1", "2", "3"), | ||
), | ||
homepage="https://www.crcv.ucf.edu/data/UCF101.php", | ||
) | ||
|
||
def resources(self, config: DatasetConfig) -> List[OnlineResource]: | ||
return [ | ||
HttpResource( | ||
"https://www.crcv.ucf.edu/data/UCF101/UCF101TrainTestSplits-RecognitionTask.zip", | ||
sha256="5c0d1a53b8ed364a2ac830a73f405e51bece7d98ce1254fd19ed4a36b224bd27", | ||
), | ||
HttpResource( | ||
"https://www.crcv.ucf.edu/data/UCF101/UCF101.rar", | ||
sha256="ca8dfadb4c891cb11316f94d52b6b0ac2a11994e67a0cae227180cd160bd8e55", | ||
extract=True, | ||
), | ||
] | ||
|
||
def _collate_and_decode( | ||
self, | ||
data: Tuple[Tuple[str, str], Tuple[str, io.IOBase]], | ||
*, | ||
decoder: Optional[Callable[[io.IOBase], Dict[str, Any]]] = None, | ||
) -> Dict[str, Any]: | ||
split_data, image_data = data | ||
_, label_idx = split_data | ||
path, buffer = image_data | ||
label_idx = int(label_idx) | ||
return dict( | ||
label=Label(label_idx, category=self.categories[label_idx]), | ||
path=path, | ||
video=decoder(buffer) if decoder else buffer, | ||
) | ||
|
||
def _make_datapipe( | ||
self, | ||
resource_dps: List[IterDataPipe], | ||
*, | ||
config: DatasetConfig, | ||
decoder: Optional[Callable[[io.IOBase], torch.Tensor]], | ||
) -> IterDataPipe[Dict[str, Any]]: | ||
splits_dp, images_dp = resource_dps | ||
|
||
splits_dp: IterDataPipe[Tuple[str, io.IOBase]] = Filter( | ||
splits_dp, path_comparator("name", f"{config.split}list0{config.fold}.txt") | ||
) | ||
splits_dp = CSVParser(splits_dp, dialect="ucf101") | ||
splits_dp = hint_sharding(splits_dp) | ||
splits_dp = hint_shuffling(splits_dp) | ||
|
||
dp = IterKeyZipper(splits_dp, images_dp, path_accessor("name")) | ||
return Mapper(dp, self._collate_and_decode, fn_kwargs=dict(decoder=decoder)) | ||
|
||
def _generate_categories(self, root: pathlib.Path) -> Tuple[str, ...]: | ||
dp = self.resources(self.default_config)[0].load(pathlib.Path(root) / self.name) | ||
dp: IterDataPipe[Tuple[str, io.IOBase]] = Filter(dp, path_comparator("name", "classInd.txt")) | ||
dp = CSVParser(dp, dialect="ucf101") | ||
_, categories = zip(*dp) | ||
return cast(Tuple[str, ...], 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
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
Oops, something went wrong.
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.