Skip to content
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

Removing Open CV dependencies #1679

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 4 additions & 13 deletions tests/data/test_VideoDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import List
from unittest import mock

import cv2
import numpy as np
import PIL
import torch
Expand Down Expand Up @@ -51,37 +50,29 @@ def create_dataset_specified_frames_per_video(
self.input_dir = tempfile.mkdtemp()
self.ensure_dir(self.input_dir)
self.frames_over_videos = [
(np.random.randn(frames, w, h, c) * 255).astype(np.uint8)
(torch.randn(frames, w, h, c) * 255).to(torch.uint8)
for frames in frames_per_video
]
self.extensions = ".avi"

for frames in self.frames_over_videos:
path = os.path.join(self.input_dir, f"output-{len(frames):03}.avi")
print(path)
out = cv2.VideoWriter(path, 0, 1, (w, h))
for frame in frames:
out.write(frame)
out.release()
out = torchvision.io.write_video(path, self.frames_over_videos, frames)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out = torchvision.io.write_video(path, self.frames_over_videos, frames)
out = torchvision.io.write_video(filename=path, video_array=frames, fps=1)

self.frames_over_videos is a list of videos and we want to save every video individually.


def create_dataset(self, n_videos=5, n_frames_per_video=10, w=32, h=32, c=3):
self.n_videos = n_videos
self.n_frames_per_video = n_frames_per_video

self.input_dir = tempfile.mkdtemp()
self.ensure_dir(self.input_dir)
self.frames = (np.random.randn(n_frames_per_video, w, h, c) * 255).astype(
np.uint8
)
self.frames = (torch.randn(n_frames_per_video, w, h, c) * 255).to(torch.uint8)
self.extensions = ".avi"

for i in range(n_videos):
path = os.path.join(self.input_dir, f"output-{i}.avi")
print(path)
out = cv2.VideoWriter(path, 0, 1, (w, h))
for frame in self.frames:
out.write(frame)
out.release()
out = torchvision.io.write_video(path, self.frames, n_frames_per_video)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out = torchvision.io.write_video(path, self.frames, n_frames_per_video)
out = torchvision.io.write_video(filename=path, video_array=self.frames, fps=1)


@unittest.skipUnless(
PYAV_AVAILABLE and VIDEO_READER_AVAILABLE,
Expand Down
Loading