-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ! processing case if face regions for image are not detected
- Loading branch information
1 parent
6e1ac70
commit 9e8440e
Showing
33 changed files
with
1,196 additions
and
725 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class StorageKeyError(Exception): | ||
""" | ||
Exception raised when the storage key does not exist. | ||
""" | ||
|
||
def __init__(self, key: str) -> None: | ||
self.key = key | ||
super().__init__(f"Storage key '{key}' does not exist.") |
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,26 @@ | ||
from django.forms import CharField, ValidationError | ||
|
||
|
||
class MeanValuesTupleField(CharField): | ||
def to_python(self, value: str) -> tuple[float, float, float]: | ||
try: | ||
values = tuple(map(float, value.split(", "))) | ||
if len(values) != 3: | ||
raise ValueError("The tuple must have exactly three elements.") | ||
if not all(-255 <= v <= 255 for v in values): | ||
raise ValueError( | ||
"Each value in the tuple must be between -255 and 255." | ||
) | ||
return values | ||
except Exception as e: | ||
raise ValidationError( | ||
""" | ||
Enter a valid tuple of three float values separated by commas and spaces, e.g. '0.0, 0.0, 0.0'. | ||
Each value must be between -255 and 255. | ||
""" | ||
) from e | ||
|
||
def prepare_value(self, value: tuple[float, float, float]) -> str: | ||
if isinstance(value, tuple): | ||
return ", ".join(map(str, value)) | ||
return super().prepare_value(value) |
Empty file.
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,38 @@ | ||
from django.conf import settings | ||
|
||
from constance import config | ||
from cv2 import dnn, dnn_Net | ||
|
||
from hope_dedup_engine.apps.core.storage import CV2DNNStorage | ||
|
||
|
||
class DNNInferenceManager: | ||
""" | ||
A class to manage the loading and configuration of a neural network model using OpenCV's DNN module. | ||
The DNNInferenceManager class provides functionality to load a neural network model from Caffe files stored in a | ||
specified storage and configure the model with preferred backend and target settings. | ||
""" | ||
|
||
def __init__(self, storage: CV2DNNStorage) -> None: | ||
""" | ||
Loads and configures the neural network model using the specified storage. | ||
Args: | ||
storage (CV2DNNStorage): The storage object from which to load the neural network model. | ||
""" | ||
self.net = dnn.readNetFromCaffe( | ||
storage.path(settings.PROTOTXT_FILE), | ||
storage.path(settings.CAFFEMODEL_FILE), | ||
) | ||
self.net.setPreferableBackend(int(config.DNN_BACKEND)) | ||
self.net.setPreferableTarget(int(config.DNN_TARGET)) | ||
|
||
def get_model(self) -> dnn_Net: | ||
""" | ||
Get the loaded and configured neural network model. | ||
Returns: | ||
cv2.dnn_Net: The neural network model loaded and configured by this manager. | ||
""" | ||
return self.net |
Oops, something went wrong.