Exemplo n.º 1
0
def test_maths() -> None:
    """
    Test maths.
    """
    # test numpy string length
    input_list = [["Lorem", "Ipsum"], ["Dolor", "Sit Amet"]]
    input_arr = np.array(input_list)
    assert np.all(np_str_len(input_list) == np.array([[5, 5], [5, 8]]))
    assert np.all(np_str_len(input_arr) == np.array([[5, 5], [5, 8]]))
    with pytest.raises(TypeError):
        np_str_len(77)

    # test rounding for bankers round
    assert rnd(.7) == 1
    assert rnd(1.5) == 2
    assert rnd(2.5) == 2

    # test floor and ceil
    assert floor(.5) == 0
    assert ceil(.5) == 1

    # test rounding halfs down
    assert np.all(np_round_half_down([0, 0.7, 0.5, 1.5]) == [0, 1, 0, 1])

    # test compute_indices
    assert np.all(compute_indices(5, 10, is_train=False) == [0, 0, 1, 1, 2, 2, 3, 3, 4, 4])
    assert np.all(compute_indices(8, 6, is_train=False) == [0, 2, 3, 4, 6, 7])
    np.random.seed(0)
    assert np.all(compute_indices(80, 6, is_train=True) == [7, 20, 32, 49, 59, 78])
Exemplo n.º 2
0
    def get_vid_feat_by_amount(self, key: str, num_frames: int) -> np.ndarray:
        """
        Load a given number of frames from a video.

        Args:
            key: Video key.
            num_frames: Number of frames desired

        Returns:
            Frame features with shape (num_frames, feature_dim)
        """
        indices = maths.compute_indices(self.meta[key]["num_frames_vid"],
                                        num_frames, self.is_train)
        indices += self.meta[key]["start_frame_vid"]
        return self.get_vid_frames_by_indices(key, indices)
Exemplo n.º 3
0
    def get_clip_frames_by_amount(self, key: str, seg_num: int,
                                  num_frames: int) -> np.ndarray:
        """
        Load a given number of frames from a clip.

        Args:
            key: Video key.
            seg_num: Segment number.
            num_frames: Number of frames desired.

        Returns:
            Frame features with shape (num_frames, feature_dim)
        """
        seg = self.meta[key]["vid_segments"][seg_num]
        indices = maths.compute_indices(seg["num_frames"], num_frames,
                                        self.is_train)
        indices += seg["start_frame"]
        return self.get_vid_frames_by_indices(key, indices)