-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/optimize face detection #26
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ab79e6
fix : remove load_model
maya-ots a777cfe
fix : remove init_model
maya-ots 2125e6d
fix : add prepare() method
maya-ots a724903
fix : swap the for loop with a list (for faces iteration)
maya-ots ca7866a
fix: resolve mypy lint errors in FaceDetection
maya-ots e99fc0e
fix: add missing numpy import
maya-ots 20c4c65
fix: remove unused typing imports
maya-ots a363a80
fix: remove prepare()
maya-ots c3b41ba
fix: add load_model
maya-ots 901b1db
fix: add init_model back
maya-ots 0c6f296
fix: move face_detection.py out of AIService
maya-ots 1370b77
fix : removed test files
maya-ots 67cc498
fix : removed unused folders
maya-ots File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,27 @@ | ||
| from insightface.app import FaceAnalysis # type: ignore | ||
| from typing import Optional | ||
| import numpy as np | ||
|
|
||
| BBox = tuple[int, int, int, int] | ||
|
|
||
| class FaceDetection: | ||
| def __init__(self, model_name: str = "buffalo_l") -> None: | ||
| self.model = model_name | ||
| self.app: Optional[FaceAnalysis] = None | ||
|
|
||
| def load_model(self) -> None: | ||
| self.app = FaceAnalysis(name=self.model, allowed_modules=['detection']) | ||
| print("[FaceDetection] model loaded successfully!") | ||
|
|
||
| def init_model(self) -> None: | ||
| if self.app is None: | ||
| raise ValueError("Model not loaded. Call load_model() first.") | ||
| self.app.prepare(ctx_id=-1, det_size=(640, 640)) # type: ignore | ||
| print("[FaceDetection] model initialized and ready.") | ||
|
|
||
| def detect(self, image: np.ndarray) -> list[BBox]: | ||
| if self.app is None: | ||
| raise ValueError("Model not ready. Call load_model() first.") | ||
|
|
||
| faces = self.app.get(image) | ||
| return [(int(x1), int(y1), int(x2), int(y2)) for x1, y1, x2, y2 in [f.bbox for f in faces]] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we have removed this folder stick to the main folder structure