-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43b90b0
commit ec414fd
Showing
4 changed files
with
56 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# author: Arun Ponnusamy | ||
# website: https://www.arunponnusamy.com | ||
|
||
__version__ = "0.1.6" | ||
__version__ = "0.1.7" | ||
|
||
from .face_detection import detect_face | ||
from .object_detection import detect_common_objects | ||
from .gender_detection import detect_gender |
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,48 @@ | ||
import cv2 | ||
import os | ||
import numpy as np | ||
from keras.utils import get_file | ||
from keras.models import load_model | ||
from keras.preprocessing.image import img_to_array | ||
|
||
is_initialized = False | ||
model = None | ||
|
||
def pre_process(face): | ||
|
||
face = cv2.resize(face, (96,96)) | ||
face = face.astype("float") / 255.0 | ||
face = img_to_array(face) | ||
face = np.expand_dims(face, axis=0) | ||
|
||
return face | ||
|
||
def detect_gender(face): | ||
|
||
global is_initialized | ||
global model | ||
|
||
labels = ['man', 'woman'] | ||
|
||
|
||
if not is_initialized: | ||
|
||
print("[INFO] initializing ... ") | ||
|
||
dwnld_link = "https://s3.ap-south-1.amazonaws.com/arunponnusamy/pre-trained-weights/gender_detection.model" | ||
|
||
model_path = get_file("gender_detection.model", dwnld_link, | ||
cache_dir= os.path.expanduser('~') + os.path.sep + '.cvlib' + os.path.sep + 'pre-trained') | ||
|
||
model = load_model(model_path) | ||
|
||
is_initialized = True | ||
|
||
|
||
face = pre_process(face) | ||
|
||
conf = model.predict(face)[0] | ||
|
||
return (labels, conf) | ||
|
||
|
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