-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EFRS-885 Add age/gender recognition as an independent plugin
- Loading branch information
Showing
22 changed files
with
722 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import attr | ||
from typing import Tuple, List, Optional, Dict | ||
|
||
from src.services.dto.bounding_box import BoundingBoxDTO | ||
from src.services.dto.json_encodable import JSONEncodable | ||
from src.services.imgtools.types import Array1D, Array3D | ||
|
||
|
||
class PluginResultDTO(JSONEncodable): | ||
def to_json(self) -> dict: | ||
""" Serialize only public properties """ | ||
return {k: v for k, v in self.__dict__.items() if not k.startswith('_')} | ||
|
||
|
||
@attr.s(auto_attribs=True, frozen=True) | ||
class EmbeddingDTO(PluginResultDTO): | ||
embedding: Array1D | ||
|
||
|
||
@attr.s(auto_attribs=True, frozen=True) | ||
class GenderDTO(PluginResultDTO): | ||
gender: str | ||
gender_probability: float = attr.ib(converter=float, default=None) | ||
|
||
|
||
@attr.s(auto_attribs=True, frozen=True) | ||
class AgeDTO(PluginResultDTO): | ||
age: Tuple[int, int] | ||
age_probability: float = attr.ib(converter=float, default=None) | ||
|
||
|
||
@attr.s(auto_attribs=True) | ||
class FaceDTO(PluginResultDTO): | ||
box: BoundingBoxDTO | ||
_img: Optional[Array3D] | ||
_face_img: Optional[Array3D] | ||
_plugins_dto: List[PluginResultDTO] = attr.Factory(list) | ||
execution_time: Dict[str, float] = attr.Factory(dict) | ||
|
||
def to_json(self): | ||
data = super().to_json() | ||
for plugin_dto in self._plugins_dto: | ||
data.update(plugin_dto.to_json()) | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) 2020 the original author or authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
# or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
import os | ||
from importlib.util import find_spec | ||
|
||
modules_by_lib = { | ||
'tensorflow': ('facenet', 'rude_carnie'), | ||
'mexnet': ('insightface',) | ||
} | ||
modules_to_skip = [] | ||
for lib, modules in modules_by_lib.items(): | ||
if find_spec(lib) is None: | ||
modules_to_skip.extend(modules) | ||
|
||
|
||
def pytest_ignore_collect(path): | ||
_, last_path = os.path.split(path) | ||
for module in modules: | ||
if last_path.startswith(module): | ||
return True |
Oops, something went wrong.