示例#1
0
    def test_distributed_sampler_and_uniform_clip_sampler(self, tmpdir):
        video_list = get_list_of_videos(tmpdir,
                                        num_videos=3,
                                        sizes=[25, 25, 25])
        video_clips = VideoClips(video_list, 5, 5)
        clip_sampler = UniformClipSampler(video_clips, 3)

        distributed_sampler_rank0 = DistributedSampler(
            clip_sampler,
            num_replicas=2,
            rank=0,
            group_size=3,
        )
        indices = torch.tensor(list(iter(distributed_sampler_rank0)))
        assert len(distributed_sampler_rank0) == 6
        assert_equal(indices, torch.tensor([0, 2, 4, 10, 12, 14]))

        distributed_sampler_rank1 = DistributedSampler(
            clip_sampler,
            num_replicas=2,
            rank=1,
            group_size=3,
        )
        indices = torch.tensor(list(iter(distributed_sampler_rank1)))
        assert len(distributed_sampler_rank1) == 6
        assert_equal(indices, torch.tensor([5, 7, 9, 0, 2, 4]))
示例#2
0
 def test_uniform_clip_sampler_insufficient_clips(self, tmpdir):
     video_list = get_list_of_videos(tmpdir, num_videos=3, sizes=[10, 25, 25])
     video_clips = VideoClips(video_list, 5, 5)
     sampler = UniformClipSampler(video_clips, 3)
     assert len(sampler) == 3 * 3
     indices = torch.tensor(list(iter(sampler)))
     assert_equal(indices, torch.tensor([0, 0, 1, 2, 4, 6, 7, 9, 11]))
 def test_video_clips_custom_fps(self, tmpdir):
     video_list = get_list_of_videos(tmpdir, num_videos=3, sizes=[12, 12, 12], fps=[3, 4, 6])
     num_frames = 4
     for fps in [1, 3, 4, 10]:
         video_clips = VideoClips(video_list, num_frames, num_frames, fps, num_workers=2)
         for i in range(video_clips.num_clips()):
             video, audio, info, video_idx = video_clips.get_clip(i)
             assert video.shape[0] == num_frames
             assert info["video_fps"] == fps
示例#4
0
 def test_random_clip_sampler(self, tmpdir):
     video_list = get_list_of_videos(tmpdir, num_videos=3, sizes=[25, 25, 25])
     video_clips = VideoClips(video_list, 5, 5)
     sampler = RandomClipSampler(video_clips, 3)
     assert len(sampler) == 3 * 3
     indices = torch.tensor(list(iter(sampler)))
     videos = torch.div(indices, 5, rounding_mode="floor")
     v_idxs, count = torch.unique(videos, return_counts=True)
     assert_equal(v_idxs, torch.tensor([0, 1, 2]))
     assert_equal(count, torch.tensor([3, 3, 3]))
示例#5
0
 def test_random_clip_sampler_unequal(self, tmpdir):
     video_list = get_list_of_videos(tmpdir, num_videos=3, sizes=[10, 25, 25])
     video_clips = VideoClips(video_list, 5, 5)
     sampler = RandomClipSampler(video_clips, 3)
     assert len(sampler) == 2 + 3 + 3
     indices = list(iter(sampler))
     assert 0 in indices
     assert 1 in indices
     # remove elements of the first video, to simplify testing
     indices.remove(0)
     indices.remove(1)
     indices = torch.tensor(indices) - 2
     videos = torch.div(indices, 5, rounding_mode="floor")
     v_idxs, count = torch.unique(videos, return_counts=True)
     assert_equal(v_idxs, torch.tensor([0, 1]))
     assert_equal(count, torch.tensor([3, 3]))
    def test_video_clips(self, tmpdir):
        video_list = get_list_of_videos(tmpdir, num_videos=3)
        video_clips = VideoClips(video_list, 5, 5, num_workers=2)
        assert video_clips.num_clips() == 1 + 2 + 3
        for i, (v_idx, c_idx) in enumerate([(0, 0), (1, 0), (1, 1), (2, 0), (2, 1), (2, 2)]):
            video_idx, clip_idx = video_clips.get_clip_location(i)
            assert video_idx == v_idx
            assert clip_idx == c_idx

        video_clips = VideoClips(video_list, 6, 6)
        assert video_clips.num_clips() == 0 + 1 + 2
        for i, (v_idx, c_idx) in enumerate([(1, 0), (2, 0), (2, 1)]):
            video_idx, clip_idx = video_clips.get_clip_location(i)
            assert video_idx == v_idx
            assert clip_idx == c_idx

        video_clips = VideoClips(video_list, 6, 1)
        assert video_clips.num_clips() == 0 + (10 - 6 + 1) + (15 - 6 + 1)
        for i, v_idx, c_idx in [(0, 1, 0), (4, 1, 4), (5, 2, 0), (6, 2, 1)]:
            video_idx, clip_idx = video_clips.get_clip_location(i)
            assert video_idx == v_idx
            assert clip_idx == c_idx