Skip to content

Commit

Permalink
Fixed pylint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Iván de Paz committed Oct 8, 2024
1 parent 724752a commit dc3b16b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pylint
pip install requirements requirements-tf
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
32 changes: 17 additions & 15 deletions mtcnn/mtcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import tensorflow as tf
import numpy as np

from mtcnn.stages import StagePNet, StageRNet, StageONet

from mtcnn.utils.images import load_images_batch, standarize_batch
from mtcnn.utils.bboxes import fix_bboxes_offsets, limit_bboxes, to_json

import tensorflow as tf
import numpy as np


COMMON_STAGES = {
"face_detection_only": [StagePNet, StageRNet],
Expand Down Expand Up @@ -87,15 +87,15 @@ def get_stage(self, stage_id=None, stage_name=None):

return None

def predict(self, image, fit_to_image=True, limit_boundaries_landmarks=False, box_format="xywh", output_type="json", postprocess=True,
def predict(self, image, fit_to_image=True, limit_boundaries_landmarks=False, box_format="xywh", output_type="json", postprocess=True,
**kwargs):
"""
Alias for detect_faces().
"""
return self.detect_faces(image, fit_to_image=fit_to_image, limit_boundaries_landmarks=limit_boundaries_landmarks,
return self.detect_faces(image, fit_to_image=fit_to_image, limit_boundaries_landmarks=limit_boundaries_landmarks,
box_format=box_format, output_type=output_type, postprocess=postprocess, **kwargs)

def detect_faces(self, image, fit_to_image=True, limit_boundaries_landmarks=False, box_format="xywh", output_type="json",
def detect_faces(self, image, fit_to_image=True, limit_boundaries_landmarks=False, box_format="xywh", output_type="json",
postprocess=True, batch_stack_justification="center", **kwargs):
"""
Runs face detection on a single image or batch of images through the configured stages.
Expand All @@ -111,7 +111,8 @@ def detect_faces(self, image, fit_to_image=True, limit_boundaries_landmarks=Fals
postprocess (bool, optional): Flag to enable postprocessing. The postprocessing includes functionality affected by `fit_to_image`,
`limit_boundaries_landmarks` and removing padding effects caused by batching images with different shapes.
batch_stack_justification (str, optional): The justification of the smaller images w.r.t. the largest images when
stacking in batch processing, which requires padding smaller images to the size of the biggest one.
stacking in batch processing, which requires padding smaller images to the size of the
biggest one.
**kwargs: Additional parameters passed to the stages. The following parameters are used:
- **StagePNet**:
Expand All @@ -131,9 +132,11 @@ def detect_faces(self, image, fit_to_image=True, limit_boundaries_landmarks=Fals
- nms_onet (float, optional): IoU threshold for Non-Maximum Suppression in ONet. Default is 0.7.
Returns:
list or list of lists: A list of detected faces (in case a single image) or a list of lists of detected faces (one per image in the batch).
If the stages are `face_and_landmarks_detection`, the output will have the detected faces and landmarks in JSON format.
In case of `face_detection_only`, only the bounding boxes will be provided in JSON format.
list or list of lists: A list of detected faces (in case a single image) or a list of lists of detected faces
(one per image in the batch). If the stages are `face_and_landmarks_detection`,
the output will have the detected faces and landmarks in JSON format.
In case of `face_detection_only`, only the bounding boxes will be provided in
JSON format.
"""
return_tensor = output_type == "numpy"
as_width_height = box_format == "xywh"
Expand All @@ -142,11 +145,11 @@ def detect_faces(self, image, fit_to_image=True, limit_boundaries_landmarks=Fals
images = image if is_batch else [image]

with tf.device(self._device):
# Load the images into memory and normalize them into a single tensor
# Load the images into memory and normalize them into a single tensor
try:
images_raw = load_images_batch(images)
images_normalized, images_oshapes, pad_param = standarize_batch(images_raw,
justification=batch_stack_justification,
justification=batch_stack_justification,
normalize=True)

bboxes_batch = None
Expand Down Expand Up @@ -176,11 +179,10 @@ def detect_faces(self, image, fit_to_image=True, limit_boundaries_landmarks=Fals
result[:, 4] = result[:, 4] - result[:, 2]

else:
result = to_json(bboxes_batch,
result = to_json(bboxes_batch,
images_count=len(images),
output_as_width_height=as_width_height,
output_as_width_height=as_width_height,
input_as_width_height=False)
result = result[0] if (not is_batch and len(result) > 0) else result

return result

0 comments on commit dc3b16b

Please sign in to comment.