Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Fix normalizing video classification input #1213

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Fixed

- Fixed normalizing inputs to video classification ([#1213](https://github.com/PyTorchLightning/lightning-flash/pull/1213))

- Fixed examples (question answering), where NLTK's `punkt` module needs to be downloaded first. ([#1215](https://github.com/PyTorchLightning/lightning-flash/pull/1215/files))

- Fixed a bug where DDP would not work with Flash tasks ([#1182](https://github.com/PyTorchLightning/lightning-flash/pull/1182))
Expand Down
7 changes: 6 additions & 1 deletion flash/video/classification/input_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
ClipSampler, LabeledVideoDataset, EncodedVideo, ApplyTransformToKey = None, None, None, None


def normalize(x: torch.Tensor) -> torch.Tensor:
return x / 255.0


@requires("video")
@dataclass
class VideoClassificationInputTransform(InputTransform):
Expand All @@ -48,7 +52,8 @@ def per_sample_transform(self) -> Callable:
per_sample_transform = [CenterCrop(self.image_size)]

return ApplyToKeys(
"video", Compose([UniformTemporalSubsample(self.temporal_sub_sample)] + per_sample_transform)
"video",
Compose([UniformTemporalSubsample(self.temporal_sub_sample), normalize] + per_sample_transform),
)

def per_batch_transform_on_device(self) -> Callable:
Expand Down