Skip to content

Commit

Permalink
Make sure faces are np.int64, even on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
prouast committed Jul 18, 2024
1 parent f520eab commit c4b3760
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import numpy as np
import os
from prpy.ffmpeg.probe import probe_video
from prpy.ffmpeg.readwrite import read_video_from_path
Expand Down Expand Up @@ -52,7 +53,7 @@ def test_video_faces(request):
test_video_fps = request.getfixturevalue('test_video_fps')
boxes, _ = det(test_video_ndarray, fps=test_video_fps)
boxes = (boxes * [test_video_ndarray.shape[2], test_video_ndarray.shape[1], test_video_ndarray.shape[2], test_video_ndarray.shape[1]]).astype(int)
return boxes[:,0]
return boxes[:,0].astype(np.int64)

@pytest.fixture(scope='session')
def test_dev_api_key():
Expand Down
2 changes: 1 addition & 1 deletion vitallens/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __call__(
logging.warn("No faces to analyze")
return []
# Convert to absolute units
faces = (faces_rel * [width, height, width, height]).astype(int)
faces = (faces_rel * [width, height, width, height]).astype(np.int64)
# Face axis first
faces = np.transpose(faces, (1, 0, 2))
# Check if the faces are valid
Expand Down
2 changes: 1 addition & 1 deletion vitallens/methods/simple_rppg_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __call__(
Args:
frames: The video frames. Shape (n_frames, h, w, c)
faces: The face detection boxes. Shape (n_frames, 4) in form (x0, y0, x1, y1)
faces: The face detection boxes as np.int64. Shape (n_frames, 4) in form (x0, y0, x1, y1)
fps: The rate at which video was sampled.
override_fps_target: Override the method's default inference fps (optional).
Returns:
Expand Down
2 changes: 1 addition & 1 deletion vitallens/methods/vitallens.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __call__(
Args:
frames: The video to analyze. Either a np.ndarray of shape (n_frames, h, w, 3)
in unscaled uint8 RGB format, or a path to a video file.
faces: The face detection boxes. Shape (n_frames, 4) in form (x0, y0, x1, y1)
faces: The face detection boxes as np.int64. Shape (n_frames, 4) in form (x0, y0, x1, y1)
fps: The rate at which video was sampled.
override_fps_target: Override the method's default inference fps (optional).
Returns:
Expand Down
4 changes: 2 additions & 2 deletions vitallens/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ def check_faces(
if faces is None:
# Assume that each entire frame is a single face
logging.info("No faces given - assuming that frames have been cropped to a single face")
faces = np.tile(np.asarray([0, 0, w, h]), (n_frames, 1))[np.newaxis] # (1, n_frames, 4)
faces = np.tile(np.asarray([0, 0, w, h], dtype=np.int64), (n_frames, 1))[np.newaxis] # (1, n_frames, 4)
else:
faces = np.asarray(faces)
faces = np.asarray(faces, dtype=np.int64)
if faces.shape[-1] != 4: raise ValueError("Face detections must be in flat point form")
if len(faces.shape) == 1:
# Single face detection given - repeat for n_frames
Expand Down

0 comments on commit c4b3760

Please sign in to comment.