mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 11:35:21 +00:00
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import os
|
|
import gdown
|
|
import tensorflow as tf
|
|
from deepface.basemodels import VGGFace
|
|
from deepface.commons import functions
|
|
|
|
# --------------------------
|
|
# pylint: disable=line-too-long
|
|
# --------------------------
|
|
# dependency configurations
|
|
tf_version = int(tf.__version__.split(".", maxsplit=1)[0])
|
|
|
|
if tf_version == 1:
|
|
from keras.models import Model, Sequential
|
|
from keras.layers import Convolution2D, Flatten, Activation
|
|
elif tf_version == 2:
|
|
from tensorflow.keras.models import Model, Sequential
|
|
from tensorflow.keras.layers import Convolution2D, Flatten, Activation
|
|
# --------------------------
|
|
def loadModel(
|
|
url="https://github.com/serengil/deepface_models/releases/download/v1.0/race_model_single_batch.h5",
|
|
):
|
|
|
|
model = VGGFace.baseModel()
|
|
|
|
# --------------------------
|
|
|
|
classes = 6
|
|
base_model_output = Sequential()
|
|
base_model_output = Convolution2D(classes, (1, 1), name="predictions")(model.layers[-4].output)
|
|
base_model_output = Flatten()(base_model_output)
|
|
base_model_output = Activation("softmax")(base_model_output)
|
|
|
|
# --------------------------
|
|
|
|
race_model = Model(inputs=model.input, outputs=base_model_output)
|
|
|
|
# --------------------------
|
|
|
|
# load weights
|
|
|
|
home = functions.get_deepface_home()
|
|
|
|
if os.path.isfile(home + "/.deepface/weights/race_model_single_batch.h5") != True:
|
|
print("race_model_single_batch.h5 will be downloaded...")
|
|
|
|
output = home + "/.deepface/weights/race_model_single_batch.h5"
|
|
gdown.download(url, output, quiet=False)
|
|
|
|
race_model.load_weights(home + "/.deepface/weights/race_model_single_batch.h5")
|
|
|
|
return race_model
|