Skip to content

Commit f0444d4

Browse files
committed
.
1 parent 2ae49ac commit f0444d4

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

examples/basic_example.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
# :ref:`creating_decoder`.
2020

2121
from typing import Optional
22-
23-
import requests
2422
import torch
23+
import requests
2524

2625

2726
# Video source: https://www.pexels.com/video/dog-eating-854132/
@@ -34,16 +33,16 @@
3433
raw_video_bytes = response.content
3534

3635

37-
def plot(frames: torch.Tensor, title: Optional[str] = None):
36+
def plot(frames: torch.Tensor, title : Optional[str] = None):
3837
try:
39-
import matplotlib.pyplot as plt
40-
from torchvision.transforms.v2.functional import to_pil_image
4138
from torchvision.utils import make_grid
39+
from torchvision.transforms.v2.functional import to_pil_image
40+
import matplotlib.pyplot as plt
4241
except ImportError:
4342
print("Cannot plot, please run `pip install torchvision matplotlib`")
4443
return
4544

46-
plt.rcParams["savefig.bbox"] = "tight"
45+
plt.rcParams["savefig.bbox"] = 'tight'
4746
fig, ax = plt.subplots()
4847
ax.imshow(to_pil_image(make_grid(frames)))
4948
ax.set(xticklabels=[], yticklabels=[], xticks=[], yticks=[])
@@ -77,7 +76,7 @@ def plot(frames: torch.Tensor, title: Optional[str] = None):
7776
# ---------------------------------------
7877

7978
first_frame = decoder[0] # using a single int index
80-
every_twenty_frame = decoder[0:-1:20] # using slices
79+
every_twenty_frame = decoder[0 : -1 : 20] # using slices
8180

8281
print(f"{first_frame.shape = }")
8382
print(f"{first_frame.dtype = }")
@@ -107,10 +106,9 @@ def plot(frames: torch.Tensor, title: Optional[str] = None):
107106
# The decoder is a normal iterable object and can be iterated over like so:
108107

109108
for frame in decoder:
110-
assert isinstance(frame, torch.Tensor) and frame.shape == (
111-
3,
112-
decoder.metadata.height,
113-
decoder.metadata.width,
109+
assert (
110+
isinstance(frame, torch.Tensor)
111+
and frame.shape == (3, decoder.metadata.height, decoder.metadata.width)
114112
)
115113

116114
# %%

0 commit comments

Comments
 (0)