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
from typing import List, Optional, NamedTuple | |
# use to make model jittable | |
OptTensor = Optional[Tensor] | |
ListTensor = List[Tensor] | |
class TensorBatch(NamedTuple): | |
x: Tensor | |
edge_index: ListTensor | |
edge_attr: OptTensor |
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
def get_single_batch(datamodule): | |
for batch in datamodule.test_dataloader(): | |
return datamodule.gather_data(batch, 0) | |
def run(args): | |
datamodule: LightningDataModule = instantiate_datamodule(args) | |
model: LightningModule = instantiate_model(args, datamodule) | |
print(model) | |
model.jittable() | |
print(model) |
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
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "Python: test_params_groups_and_state_are_accessible", | |
"type": "python", | |
"request": "launch", |
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
model = VideoClassifier(backbone="x3d_xs", num_classes=datamodule.num_classes, serializer=Labels()) |
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
model = VideoClassifier( | |
backbone="x3d_xs", | |
num_classes=datamodule.num_classes, | |
serializer=Labels() | |
) |
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
predictions = model.predict(os.path.join(flash.PROJECT_ROOT, "data/kinetics/predict")) | |
print(predictions) | |
# ['archery', 'bowling', 'flying_kite', 'high_jump', 'marching'] |
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
import os | |
from typing import Callable, List | |
import kornia.augmentation as K | |
import torch | |
from pytorchvideo.transforms import ApplyTransformToKey, RandomShortSideScale, UniformTemporalSubsample | |
from torch.utils.data.sampler import RandomSampler | |
from torchvision.transforms import CenterCrop, Compose, RandomCrop, RandomHorizontalFlip | |
import flash |
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
# 1. Download a video clip dataset. | |
download_data("https://pl-flash-data.s3.amazonaws.com/kinetics.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
# 2. [Optional] Specify transforms to be used during training. | |
post_tensor_transform = [UniformTemporalSubsample(8), RandomShortSideScale(min_size=256, max_size=320)] | |
per_batch_transform_on_device = [K.Normalize(torch.tensor([0.45, 0.45, 0.45]), torch.tensor([0.225, 0.225, 0.225]))] | |
train_post_tensor_transform = post_tensor_transform + [RandomCrop(244), RandomHorizontalFlip(p=0.5)] | |
val_post_tensor_transform = post_tensor_transform + [CenterCrop(244)] | |
train_per_batch_transform_on_device = per_batch_transform_on_device |