-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Type Hints for Enhanced Code Clarity and Maintenance #922
Conversation
deepface/DeepFace.py
Outdated
align=True, | ||
normalization="base", | ||
): | ||
img1_path: str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all image path variables (img_path, img1_path, img2_path) can be string or numpy array. So, these should accept numpy array as
from typing import Union
import numpy as np
def verify(img1_path: Union[str, np.ndarray]):
pass
deepface/DeepFace.py
Outdated
@@ -45,7 +46,7 @@ | |||
# ----------------------------------- | |||
|
|||
|
|||
def build_model(model_name): | |||
def build_model(model_name: str) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build_model returns one of these objects:
- keras.engine.functional.Functional
- deepface.basemodels.DlibResNet.DlibResNet
- deepface.basemodels.SFace.SFaceModel
So, this should be typed as
from typing import Union
from keras.engine.functional import Functional
from deepface.basemodels import DlibResNet, SFace
def build_model(model_name: str) -> Union[Functional, DlibResNet.DlibResNet, SFace.SFaceModel]:
pass
We should then get rid of Any import in this module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you may consider to use Functional and any. Because except 2 models, this function returns Functional.
Union[Functional, Any]
I've updated the type hints in the image paths and build_model function as per your suggestions. The new commit is pushed to this PR. Could you please take another look when you have a chance? Thank you! |
deepface/DeepFace.py
Outdated
align=True, | ||
silent=False, | ||
): | ||
img_path: Union[str, np.ndarray],, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double comma at the end of the line breaks the code
Objective:
This pull request introduces type hints to the existing codebase for deepface.py. The addition of type hints aims to enhance code clarity, facilitate maintenance, and improve the development experience for contributors and users of the repository.
Key Changes:
No Breaking Changes: These additions are non-intrusive and backward compatible. They do not alter the logic or functionality of the existing code.
Request for Review:
I request the maintainers to review these changes. Feedback and suggestions for further refinement are highly appreciated.