-
Notifications
You must be signed in to change notification settings - Fork 7.1k
add HMDB51 and UCF101 datasets as well as prototype for new style video decoding #5335
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
Closed
pmeier
wants to merge
5
commits into
pytorch:revamp-prototype-features-transforms
from
pmeier:datasets/video-decoding
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9c66ddc
add hmdb51 dataset and prototype for new style video decoding
pmeier 1c025f1
port UCF101
pmeier afd8bc1
appease mypy
pmeier 5b98c64
fix resource loading
pmeier 07d78b2
Merge branch 'revamp-prototype-features-transforms' into datasets/vid…
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
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,51 @@ | ||
brush_hair | ||
cartwheel | ||
catch | ||
chew | ||
clap | ||
climb | ||
climb_stairs | ||
dive | ||
draw_sword | ||
dribble | ||
drink | ||
eat | ||
fall_floor | ||
fencing | ||
flic_flac | ||
golf | ||
handstand | ||
hit | ||
hug | ||
jump | ||
kick | ||
kick_ball | ||
kiss | ||
laugh | ||
pick | ||
pour | ||
pullup | ||
punch | ||
push | ||
pushup | ||
ride_bike | ||
ride_horse | ||
run | ||
shake_hands | ||
shoot_ball | ||
shoot_bow | ||
shoot_gun | ||
sit | ||
situp | ||
smile | ||
smoke | ||
somersault | ||
stand | ||
swing_baseball | ||
sword | ||
sword_exercise | ||
talk | ||
throw | ||
turn | ||
walk | ||
wave |
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,116 @@ | ||
import functools | ||
import pathlib | ||
import re | ||
from typing import Any, Dict, List, Tuple, BinaryIO | ||
|
||
from torchdata.datapipes.iter import IterDataPipe, Mapper, Filter, CSVDictParser, IterKeyZipper | ||
from torchvision.prototype.datasets.utils import ( | ||
Dataset, | ||
DatasetConfig, | ||
DatasetInfo, | ||
HttpResource, | ||
OnlineResource, | ||
) | ||
from torchvision.prototype.datasets.utils._internal import ( | ||
INFINITE_BUFFER_SIZE, | ||
getitem, | ||
path_accessor, | ||
hint_sharding, | ||
hint_shuffling, | ||
) | ||
from torchvision.prototype.features import EncodedVideo, Label | ||
|
||
|
||
class HMDB51(Dataset): | ||
def _make_info(self) -> DatasetInfo: | ||
return DatasetInfo( | ||
"hmdb51", | ||
homepage="https://serre-lab.clps.brown.edu/resource/hmdb-a-large-human-motion-database/", | ||
dependencies=("rarfile",), | ||
valid_options=dict( | ||
split=("train", "test"), | ||
split_number=("1", "2", "3"), | ||
), | ||
) | ||
|
||
def _extract_videos_archive(self, path: pathlib.Path) -> pathlib.Path: | ||
folder = OnlineResource._extract(path) | ||
for rar_file in folder.glob("*.rar"): | ||
OnlineResource._extract(rar_file) | ||
rar_file.unlink() | ||
return folder | ||
|
||
def resources(self, config: DatasetConfig) -> List[OnlineResource]: | ||
url_root = "https://serre-lab.clps.brown.edu/wp-content/uploads/2013/10" | ||
|
||
splits = HttpResource( | ||
f"{url_root}/test_train_splits.rar", | ||
sha256="229c94f845720d01eb3946d39f39292ea962d50a18136484aa47c1eba251d2b7", | ||
) | ||
videos = HttpResource( | ||
f"{url_root}/hmdb51_org.rar", | ||
sha256="9e714a0d8b76104d76e932764a7ca636f929fff66279cda3f2e326fa912a328e", | ||
) | ||
videos._preprocess = self._extract_videos_archive | ||
return [splits, videos] | ||
|
||
_SPLIT_FILE_PATTERN = re.compile(r"(?P<category>\w+?)_test_split(?P<split_number>[1-3])[.]txt") | ||
|
||
def _is_split_number(self, data: Tuple[str, Any], *, split_number: str) -> bool: | ||
path = pathlib.Path(data[0]) | ||
return self._SPLIT_FILE_PATTERN.match(path.name)["split_number"] == split_number # type: ignore[index] | ||
|
||
_SPLIT_ID_TO_NAME = { | ||
"1": "train", | ||
"2": "test", | ||
} | ||
|
||
def _is_split(self, data: Dict[str, Any], *, split: str) -> bool: | ||
split_id = data["split_id"] | ||
|
||
# TODO: explain | ||
if split_id not in self._SPLIT_ID_TO_NAME: | ||
return False | ||
|
||
return self._SPLIT_ID_TO_NAME[split_id] == split | ||
|
||
def _prepare_sample(self, data: Tuple[List[str], Tuple[str, BinaryIO]]) -> Dict[str, Any]: | ||
_, (path, buffer) = data | ||
path = pathlib.Path(path) | ||
return dict( | ||
label=Label.from_category(path.parent.name, categories=self.categories), | ||
video=EncodedVideo.from_file(buffer, path=path), | ||
) | ||
|
||
def _make_datapipe( | ||
self, | ||
resource_dps: List[IterDataPipe], | ||
*, | ||
config: DatasetConfig, | ||
) -> IterDataPipe[Dict[str, Any]]: | ||
splits_dp, videos_dp = resource_dps | ||
|
||
splits_dp = Filter(splits_dp, functools.partial(self._is_split_number, split_number=config.split_number)) | ||
splits_dp = CSVDictParser(splits_dp, fieldnames=("filename", "split_id"), delimiter=" ") | ||
splits_dp = Filter(splits_dp, functools.partial(self._is_split, split=config.split)) | ||
splits_dp = hint_sharding(splits_dp) | ||
splits_dp = hint_shuffling(splits_dp) | ||
|
||
dp = IterKeyZipper( | ||
splits_dp, | ||
videos_dp, | ||
key_fn=getitem("filename"), | ||
ref_key_fn=path_accessor("name"), | ||
buffer_size=INFINITE_BUFFER_SIZE, | ||
) | ||
return Mapper(dp, self._prepare_sample) | ||
|
||
def _generate_categories(self, root: pathlib.Path) -> List[str]: | ||
config = self.default_config | ||
resources = self.resources(config) | ||
|
||
dp = resources[0].load(root) | ||
categories = { | ||
self._SPLIT_FILE_PATTERN.match(pathlib.Path(path).name)["category"] for path, _ in dp # type: ignore[index] | ||
} | ||
return sorted(categories) |
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 |
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.
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.
@NicolasHug The archive is a rar of rars so using a single
extract=True
won't cut it. We need the full extraction since reading from rar archives is rather slow and with this we get a significant performance increase.Another option would be to use this "recursive extraction" by default when setting
extract=True
.