Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
torzdf committed Nov 22, 2022
2 parents 5fec189 + 2faef58 commit ffe8f9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion plugins/extract/align/_base/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def _handle_realigns(self, queue: "Queue") -> Optional[Tuple[bool, AlignerBatch]
exhausted = True
logger.debug("All items processed. Returning empty batch")
self._filter.output_counts()
self._eof_seen = False # Reset for plugin re-use
return exhausted, AlignerBatch(batch_id=-1)

return None
Expand Down Expand Up @@ -288,7 +289,7 @@ def get_batch(self, queue: "Queue") -> Tuple[bool, AlignerBatch]:
if item == "EOF":
logger.debug("EOF received")
self._eof_seen = True
exhausted = not self._re_align.items_tracked
exhausted = not self._re_align.active
break

# Put frames with no faces or are already aligned into the out queue
Expand Down
25 changes: 13 additions & 12 deletions plugins/extract/align/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def process_input(self, batch: BatchType) -> None:
The current batch to process input for
"""
assert isinstance(batch, AlignerBatch)
logger.trace("Aligning faces around center") # type:ignore
logger.trace("Aligning faces around center") # type:ignore[attr-defined]
center_scale = self.get_center_scale(batch.detected_faces)
batch.feed = np.array(self.crop(batch, center_scale))[..., :3]
batch.data.append(dict(center_scale=center_scale))
logger.trace("Aligned image around center") # type:ignore
logger.trace("Aligned image around center") # type:ignore[attr-defined]

def get_center_scale(self, detected_faces: List["DetectedFace"]) -> np.ndarray:
""" Get the center and set scale of bounding box
Expand All @@ -92,7 +92,7 @@ def get_center_scale(self, detected_faces: List["DetectedFace"]) -> np.ndarray:
:class:`numpy.ndarray`
The center and scale of the bounding box
"""
logger.trace("Calculating center and scale") # type:ignore
logger.trace("Calculating center and scale") # type:ignore[attr-defined]
center_scale = np.empty((len(detected_faces), 68, 3), dtype='float32')
for index, face in enumerate(detected_faces):
x_center = (cast(int, face.left) + face.right) / 2.0
Expand All @@ -101,7 +101,7 @@ def get_center_scale(self, detected_faces: List["DetectedFace"]) -> np.ndarray:
center_scale[index, :, 0] = np.full(68, x_center, dtype='float32')
center_scale[index, :, 1] = np.full(68, y_center, dtype='float32')
center_scale[index, :, 2] = np.full(68, scale, dtype='float32')
logger.trace("Calculated center and scale: %s", center_scale) # type:ignore
logger.trace("Calculated center and scale: %s", center_scale) # type:ignore[attr-defined]
return center_scale

def _crop_image(self,
Expand Down Expand Up @@ -159,7 +159,7 @@ def crop(self, batch: AlignerBatch, center_scale: np.ndarray) -> List[np.ndarray
list
List of cropped images for the batch
"""
logger.debug("Cropping images")
logger.trace("Cropping images") # type:ignore[attr-defined]
batch_shape = center_scale.shape[:2]
resolutions = np.full(batch_shape, self.input_size, dtype='float32')
matrix_ones = np.ones(batch_shape + (3,), dtype='float32')
Expand All @@ -171,7 +171,7 @@ def crop(self, batch: AlignerBatch, center_scale: np.ndarray) -> List[np.ndarray
# TODO second pass .. convert to matrix
new_images = [self._crop_image(image, top_left, bottom_right)
for image, top_left, bottom_right in zip(batch.image, upper_left, bot_right)]
logger.trace("Cropped images") # type:ignore
logger.trace("Cropped images") # type:ignore[attr-defined]
return new_images

@classmethod
Expand All @@ -190,7 +190,7 @@ def transform(cls,
resolutions: :class:`numpy.ndarray`
The resolutions
"""
logger.debug("Transforming Points")
logger.trace("Transforming Points") # type:ignore[attr-defined]
num_images, num_landmarks = points.shape[:2]
transform_matrix = np.eye(3, dtype='float32')
transform_matrix = np.repeat(transform_matrix[None, :], num_landmarks, axis=0)
Expand All @@ -203,7 +203,7 @@ def transform(cls,
transform_matrix[:, :, 1, 2] = translations[:, :, 1] # y translation
new_points = np.einsum('abij, abj -> abi', transform_matrix, points, optimize='greedy')
retval = new_points[:, :, :2].astype('float32')
logger.trace("Transformed Points: %s", retval) # type:ignore
logger.trace("Transformed Points: %s", retval) # type:ignore[attr-defined]
return retval

def predict(self, feed: np.ndarray) -> np.ndarray:
Expand All @@ -219,11 +219,11 @@ def predict(self, feed: np.ndarray) -> np.ndarray:
:class:`numpy.ndarray`
The predictions from the aligner
"""
logger.trace("Predicting Landmarks") # type:ignore
logger.trace("Predicting Landmarks") # type:ignore[attr-defined]
# TODO Remove lazy transpose and change points from predict to use the correct
# order
retval = self.model.predict(feed)[-1].transpose(0, 3, 1, 2)
logger.trace(retval.shape) # type:ignore
logger.trace(retval.shape) # type:ignore[attr-defined]
return retval

def process_output(self, batch: BatchType) -> None:
Expand All @@ -246,7 +246,7 @@ def get_pts_from_predict(self, batch: AlignerBatch) -> None:
batch: :class:`AlignerBatch`
The current batch from the model with :attr:`predictions` populated
"""
logger.trace("Obtain points from prediction") # type:ignore
logger.trace("Obtain points from prediction") # type:ignore[attr-defined]
num_images, num_landmarks = batch.prediction.shape[:2]
image_slice = np.repeat(np.arange(num_images)[:, None], num_landmarks, axis=1)
landmark_slice = np.repeat(np.arange(num_landmarks)[None, :], num_images, axis=0)
Expand Down Expand Up @@ -276,4 +276,5 @@ def get_pts_from_predict(self, batch: AlignerBatch) -> None:
batch.landmarks = self.transform(subpixel_landmarks,
batch.data[0]["center_scale"],
resolution)
logger.trace("Obtained points from prediction: %s", batch.landmarks) # type:ignore
logger.trace("Obtained points from prediction: %s", # type:ignore[attr-defined]
batch.landmarks)

0 comments on commit ffe8f9a

Please sign in to comment.