Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions ptgaze/common/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def project_points(self,
tvec: Optional[np.ndarray] = None) -> np.ndarray:
assert points3d.shape[1] == 3
if rvec is None:
rvec = np.zeros(3, dtype=np.float)
rvec = np.zeros(3, dtype=float)
if tvec is None:
tvec = np.zeros(3, dtype=np.float)
tvec = np.zeros(3, dtype=float)
points2d, _ = cv2.projectPoints(points3d, rvec, tvec,
self.camera_matrix,
self.dist_coefficients)
Expand Down
7 changes: 2 additions & 5 deletions ptgaze/common/face_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import dataclasses

import cv2
import numpy as np
from scipy.spatial.transform import Rotation
Expand All @@ -8,7 +6,6 @@
from .face import Face


@dataclasses.dataclass(frozen=True)
class FaceModel:
LANDMARKS: np.ndarray
REYE_INDICES: np.ndarray
Expand All @@ -26,8 +23,8 @@ def estimate_head_pose(self, face: Face, camera: Camera) -> None:
# The default values of rvec and tvec below mean that the
# initial estimate of the head pose is not rotated and the
# face is in front of the camera.
rvec = np.zeros(3, dtype=np.float)
tvec = np.array([0, 0, 1], dtype=np.float)
rvec = np.zeros(3, dtype=float)
tvec = np.array([0, 0, 1], dtype=float)
_, rvec, tvec = cv2.solvePnP(self.LANDMARKS,
face.landmarks,
camera.camera_matrix,
Expand Down
3 changes: 0 additions & 3 deletions ptgaze/common/face_model_68.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import dataclasses

import numpy as np

from .face_model import FaceModel


@dataclasses.dataclass(frozen=True)
class FaceModel68(FaceModel):
"""3D face model for Multi-PIE 68 points mark-up.

Expand Down
3 changes: 0 additions & 3 deletions ptgaze/common/face_model_mediapipe.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import dataclasses

import numpy as np

from .face_model import FaceModel


@dataclasses.dataclass(frozen=True)
class FaceModelMediaPipe(FaceModel):
"""3D face model for MediaPipe 468 points mark-up.

Expand Down
6 changes: 3 additions & 3 deletions ptgaze/common/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def draw_bbox(self,
lw: int = 1) -> None:
assert self.image is not None
assert bbox.shape == (2, 2)
bbox = np.round(bbox).astype(np.int).tolist()
bbox = np.round(bbox).astype(np.int64).tolist()
cv2.rectangle(self.image, tuple(bbox[0]), tuple(bbox[1]), color, lw)

@staticmethod
def _convert_pt(point: np.ndarray) -> Tuple[int, int]:
return tuple(np.round(point).astype(np.int).tolist())
return tuple(np.round(point).astype(np.int64).tolist())

def draw_points(self,
points: np.ndarray,
Expand Down Expand Up @@ -71,7 +71,7 @@ def draw_model_axes(self, face: Face, length: float, lw: int = 2) -> None:
assert face.head_position is not None
assert face.landmarks is not None
# Get the axes of the model coordinate system
axes3d = np.eye(3, dtype=np.float) @ Rotation.from_euler(
axes3d = np.eye(3, dtype=float) @ Rotation.from_euler(
'XYZ', [0, np.pi, 0]).as_matrix()
axes3d = axes3d * length
axes2d = self._camera.project_points(axes3d,
Expand Down
12 changes: 6 additions & 6 deletions ptgaze/head_pose_estimation/face_landmark_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def __init__(self, config: DictConfig):
elif self.mode == 'face_alignment_dlib':
self.detector = dlib.get_frontal_face_detector()
self.predictor = face_alignment.FaceAlignment(
face_alignment.LandmarksType._2D,
face_alignment.LandmarksType.TWO_D,
face_detector='dlib',
flip_input=False,
device=config.device)
elif self.mode == 'face_alignment_sfd':
self.detector = face_alignment.detection.sfd.sfd_detector.SFDDetector(
device=config.device)
self.predictor = face_alignment.FaceAlignment(
face_alignment.LandmarksType._2D,
face_alignment.LandmarksType.TWO_D,
flip_input=False,
device=config.device)
elif self.mode == 'mediapipe':
Expand Down Expand Up @@ -57,10 +57,10 @@ def _detect_faces_dlib(self, image: np.ndarray) -> List[Face]:
for bbox in bboxes:
predictions = self.predictor(image[:, :, ::-1], bbox)
landmarks = np.array([(pt.x, pt.y) for pt in predictions.parts()],
dtype=np.float)
dtype=float)
bbox = np.array([[bbox.left(), bbox.top()],
[bbox.right(), bbox.bottom()]],
dtype=np.float)
dtype=float)
detected.append(Face(bbox, landmarks))
return detected

Expand All @@ -77,7 +77,7 @@ def _detect_faces_face_alignment_dlib(self,
predictions = []
detected = []
for bbox, landmarks in zip(bboxes, predictions):
bbox = np.array(bbox, dtype=np.float).reshape(2, 2)
bbox = np.array(bbox, dtype=float).reshape(2, 2)
detected.append(Face(bbox, landmarks))
return detected

Expand All @@ -91,7 +91,7 @@ def _detect_faces_face_alignment_sfd(self,
predictions = []
detected = []
for bbox, landmarks in zip(bboxes, predictions):
bbox = np.array(bbox, dtype=np.float).reshape(2, 2)
bbox = np.array(bbox, dtype=float).reshape(2, 2)
detected.append(Face(bbox, landmarks))
return detected

Expand Down
2 changes: 1 addition & 1 deletion ptgaze/head_pose_estimation/head_pose_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def _get_scale_matrix(self, distance: float) -> np.ndarray:
[0, 1, 0],
[0, 0, self.normalized_distance / distance],
],
dtype=np.float)
dtype=float)
6 changes: 4 additions & 2 deletions ptgaze/models/mpiifacegaze/backbones/resnet_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ def __init__(self, config: DictConfig):

pretrained_name = config.model.backbone.pretrained
if pretrained_name:
state_dict = torch.hub.load_state_dict_from_url(
torchvision.models.resnet.model_urls[pretrained_name])
if pretrained_name != 'resnet18':
raise NotImplementedError()
url = torchvision.models.resnet.ResNet18_Weights.IMAGENET1K_V1.url
state_dict = torch.hub.load_state_dict_from_url(url)
self.load_state_dict(state_dict, strict=False)
# While the pretrained models of torchvision are trained
# using images with RGB channel order, in this repository
Expand Down