Merge pull request #323 from PBWebMedia/configure-model-path

Configure models path via ENV variable
This commit is contained in:
Sefik Ilkin Serengil 2021-08-23 16:46:52 +03:00 committed by GitHub
commit 61e6de4048
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 52 additions and 23 deletions

View File

@ -817,4 +817,4 @@ def detectFace(img_path, detector_backend = 'opencv', enforce_detection = True,
#--------------------------- #---------------------------
#main #main
functions.initializeFolder() functions.initialize_folder()

View File

@ -10,6 +10,8 @@ import os
from pathlib import Path from pathlib import Path
import gdown import gdown
from deepface.commons import functions
#url = "https://drive.google.com/uc?id=1LVB3CdVejpmGHM28BpqqkbZP5hDEcdZY" #url = "https://drive.google.com/uc?id=1LVB3CdVejpmGHM28BpqqkbZP5hDEcdZY"
def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/arcface_weights.h5'): def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/arcface_weights.h5'):
@ -26,7 +28,7 @@ def loadModel(url = 'https://github.com/serengil/deepface_models/releases/downlo
#--------------------------------------- #---------------------------------------
#check the availability of pre-trained weights #check the availability of pre-trained weights
home = str(Path.home()) home = functions.get_deepface_home()
file_name = "arcface_weights.h5" file_name = "arcface_weights.h5"
output = home+'/.deepface/weights/'+file_name output = home+'/.deepface/weights/'+file_name

View File

@ -44,7 +44,7 @@ def build_gbm():
#this is not a must dependency #this is not a must dependency
import lightgbm as lgb #lightgbm==2.3.1 import lightgbm as lgb #lightgbm==2.3.1
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/face-recognition-ensemble-model.txt') != True: if os.path.isfile(home+'/.deepface/weights/face-recognition-ensemble-model.txt') != True:
print("face-recognition-ensemble-model.txt will be downloaded...") print("face-recognition-ensemble-model.txt will be downloaded...")

View File

@ -7,6 +7,8 @@ from tensorflow import keras
from tensorflow.keras.models import Model from tensorflow.keras.models import Model
from tensorflow.keras.layers import Conv2D, Activation, Input, Add, MaxPooling2D, Flatten, Dense, Dropout from tensorflow.keras.layers import Conv2D, Activation, Input, Add, MaxPooling2D, Flatten, Dense, Dropout
from deepface.commons import functions
#------------------------------------- #-------------------------------------
#url = 'https://drive.google.com/uc?id=1uRLtBCTQQAvHJ_KVrdbRJiCKxU8m5q2J' #url = 'https://drive.google.com/uc?id=1uRLtBCTQQAvHJ_KVrdbRJiCKxU8m5q2J'
@ -41,7 +43,7 @@ def loadModel(url = 'https://github.com/serengil/deepface_models/releases/downlo
#--------------------------------- #---------------------------------
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/deepid_keras_weights.h5') != True: if os.path.isfile(home+'/.deepface/weights/deepid_keras_weights.h5') != True:
print("deepid_keras_weights.h5 will be downloaded...") print("deepid_keras_weights.h5 will be downloaded...")

View File

@ -5,6 +5,8 @@ import gdown
import numpy as np import numpy as np
from pathlib import Path from pathlib import Path
from deepface.commons import functions
class DlibResNet: class DlibResNet:
def __init__(self): def __init__(self):
@ -16,7 +18,7 @@ class DlibResNet:
#--------------------- #---------------------
home = str(Path.home()) home = functions.get_deepface_home()
weight_file = home+'/.deepface/weights/dlib_face_recognition_resnet_model_v1.dat' weight_file = home+'/.deepface/weights/dlib_face_recognition_resnet_model_v1.dat'
#--------------------- #---------------------

View File

@ -3,6 +3,8 @@ from pathlib import Path
import gdown import gdown
from functools import partial from functools import partial
from deepface.commons import functions
import tensorflow as tf import tensorflow as tf
tf_version = int(tf.__version__.split(".")[0]) tf_version = int(tf.__version__.split(".")[0])
@ -555,7 +557,7 @@ def loadModel(url = 'https://github.com/serengil/deepface_models/releases/downlo
#----------------------------------- #-----------------------------------
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/facenet_weights.h5') != True: if os.path.isfile(home+'/.deepface/weights/facenet_weights.h5') != True:
print("facenet_weights.h5 will be downloaded...") print("facenet_weights.h5 will be downloaded...")

View File

@ -3,13 +3,15 @@ from pathlib import Path
import os import os
import gdown import gdown
from deepface.commons import functions
def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/facenet512_weights.h5'): def loadModel(url = 'https://github.com/serengil/deepface_models/releases/download/v1.0/facenet512_weights.h5'):
model = Facenet.InceptionResNetV2(dimension = 512) model = Facenet.InceptionResNetV2(dimension = 512)
#------------------------- #-------------------------
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/facenet512_weights.h5') != True: if os.path.isfile(home+'/.deepface/weights/facenet512_weights.h5') != True:
print("facenet512_weights.h5 will be downloaded...") print("facenet512_weights.h5 will be downloaded...")

View File

@ -7,6 +7,8 @@ from tensorflow import keras
from tensorflow.keras.models import Model, Sequential from tensorflow.keras.models import Model, Sequential
from tensorflow.keras.layers import Convolution2D, LocallyConnected2D, MaxPooling2D, Flatten, Dense, Dropout from tensorflow.keras.layers import Convolution2D, LocallyConnected2D, MaxPooling2D, Flatten, Dense, Dropout
from deepface.commons import functions
#------------------------------------- #-------------------------------------
def loadModel(url = 'https://github.com/swghosh/DeepFace/releases/download/weights-vggface2-2d-aligned/VGGFace2_DeepFace_weights_val-0.9034.h5.zip'): def loadModel(url = 'https://github.com/swghosh/DeepFace/releases/download/weights-vggface2-2d-aligned/VGGFace2_DeepFace_weights_val-0.9034.h5.zip'):
@ -24,7 +26,7 @@ def loadModel(url = 'https://github.com/swghosh/DeepFace/releases/download/weigh
#--------------------------------- #---------------------------------
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/VGGFace2_DeepFace_weights_val-0.9034.h5') != True: if os.path.isfile(home+'/.deepface/weights/VGGFace2_DeepFace_weights_val-0.9034.h5') != True:
print("VGGFace2_DeepFace_weights_val-0.9034.h5 will be downloaded...") print("VGGFace2_DeepFace_weights_val-0.9034.h5 will be downloaded...")

View File

@ -11,6 +11,8 @@ from tensorflow.keras.layers import MaxPooling2D, AveragePooling2D
from tensorflow.keras.models import load_model from tensorflow.keras.models import load_model
from tensorflow.keras import backend as K from tensorflow.keras import backend as K
from deepface.commons import functions
#--------------------------------------- #---------------------------------------
#url = 'https://drive.google.com/uc?id=1LSe1YCV1x-BfNnfb7DFZTNpv_Q9jITxn' #url = 'https://drive.google.com/uc?id=1LSe1YCV1x-BfNnfb7DFZTNpv_Q9jITxn'
@ -232,7 +234,7 @@ def loadModel(url = 'https://github.com/serengil/deepface_models/releases/downlo
#----------------------------------- #-----------------------------------
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/openface_weights.h5') != True: if os.path.isfile(home+'/.deepface/weights/openface_weights.h5') != True:
print("openface_weights.h5 will be downloaded...") print("openface_weights.h5 will be downloaded...")

View File

@ -2,6 +2,8 @@ import os
from pathlib import Path from pathlib import Path
import gdown import gdown
from deepface.commons import functions
import tensorflow as tf import tensorflow as tf
tf_version = int(tf.__version__.split(".")[0]) tf_version = int(tf.__version__.split(".")[0])
@ -71,7 +73,7 @@ def loadModel(url = 'https://github.com/serengil/deepface_models/releases/downlo
#----------------------------------- #-----------------------------------
home = str(Path.home()) home = functions.get_deepface_home()
output = home+'/.deepface/weights/vgg_face_weights.h5' output = home+'/.deepface/weights/vgg_face_weights.h5'
if os.path.isfile(output) != True: if os.path.isfile(output) != True:

View File

@ -43,18 +43,20 @@ def initialize_input(img1_path, img2_path = None):
return img_list, bulkProcess return img_list, bulkProcess
def initializeFolder(): def initialize_folder():
home = get_deepface_home()
home = str(Path.home())
if not os.path.exists(home+"/.deepface"): if not os.path.exists(home+"/.deepface"):
os.mkdir(home+"/.deepface") os.makedirs(home+"/.deepface")
print("Directory ", home, "/.deepface created") print("Directory ", home, "/.deepface created")
if not os.path.exists(home+"/.deepface/weights"): if not os.path.exists(home+"/.deepface/weights"):
os.mkdir(home+"/.deepface/weights") os.makedirs(home+"/.deepface/weights")
print("Directory ", home, "/.deepface/weights created") print("Directory ", home, "/.deepface/weights created")
def get_deepface_home():
return str(os.getenv('DEEPFACE_HOME', default=Path.home()))
def loadBase64Img(uri): def loadBase64Img(uri):
encoded_data = uri.split(',')[1] encoded_data = uri.split(',')[1]
nparr = np.fromstring(base64.b64decode(encoded_data), np.uint8) nparr = np.fromstring(base64.b64decode(encoded_data), np.uint8)

View File

@ -3,9 +3,11 @@ import gdown
import bz2 import bz2
import os import os
from deepface.commons import functions
def build_model(): def build_model():
home = str(Path.home()) home = functions.get_deepface_home()
import dlib #this requirement is not a must that's why imported here import dlib #this requirement is not a must that's why imported here

View File

@ -5,10 +5,11 @@ import cv2
import pandas as pd import pandas as pd
from deepface.detectors import OpenCvWrapper from deepface.detectors import OpenCvWrapper
from deepface.commons import functions
def build_model(): def build_model():
home = str(Path.home()) home = functions.get_deepface_home()
#model structure #model structure
if os.path.isfile(home+'/.deepface/weights/deploy.prototxt') != True: if os.path.isfile(home+'/.deepface/weights/deploy.prototxt') != True:

View File

@ -4,6 +4,8 @@ from pathlib import Path
import gdown import gdown
import numpy as np import numpy as np
from deepface.commons import functions
import tensorflow as tf import tensorflow as tf
tf_version = int(tf.__version__.split(".")[0]) tf_version = int(tf.__version__.split(".")[0])
@ -38,7 +40,7 @@ def loadModel(url = 'https://github.com/serengil/deepface_models/releases/downlo
#load weights #load weights
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/age_model_weights.h5') != True: if os.path.isfile(home+'/.deepface/weights/age_model_weights.h5') != True:
print("age_model_weights.h5 will be downloaded...") print("age_model_weights.h5 will be downloaded...")

View File

@ -3,6 +3,8 @@ import gdown
from pathlib import Path from pathlib import Path
import zipfile import zipfile
from deepface.commons import functions
import tensorflow as tf import tensorflow as tf
tf_version = int(tf.__version__.split(".")[0]) tf_version = int(tf.__version__.split(".")[0])
@ -49,7 +51,7 @@ def loadModel(url = 'https://github.com/serengil/deepface_models/releases/downlo
#---------------------------- #----------------------------
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/facial_expression_model_weights.h5') != True: if os.path.isfile(home+'/.deepface/weights/facial_expression_model_weights.h5') != True:
print("facial_expression_model_weights.h5 will be downloaded...") print("facial_expression_model_weights.h5 will be downloaded...")

View File

@ -4,6 +4,8 @@ from pathlib import Path
import gdown import gdown
import numpy as np import numpy as np
from deepface.commons import functions
import tensorflow as tf import tensorflow as tf
tf_version = int(tf.__version__.split(".")[0]) tf_version = int(tf.__version__.split(".")[0])
@ -36,7 +38,7 @@ def loadModel(url = 'https://github.com/serengil/deepface_models/releases/downlo
#load weights #load weights
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/gender_model_weights.h5') != True: if os.path.isfile(home+'/.deepface/weights/gender_model_weights.h5') != True:
print("gender_model_weights.h5 will be downloaded...") print("gender_model_weights.h5 will be downloaded...")

View File

@ -6,6 +6,8 @@ import gdown
import numpy as np import numpy as np
import zipfile import zipfile
from deepface.commons import functions
import tensorflow as tf import tensorflow as tf
tf_version = int(tf.__version__.split(".")[0]) tf_version = int(tf.__version__.split(".")[0])
@ -38,7 +40,7 @@ def loadModel(url = 'https://github.com/serengil/deepface_models/releases/downlo
#load weights #load weights
home = str(Path.home()) home = functions.get_deepface_home()
if os.path.isfile(home+'/.deepface/weights/race_model_single_batch.h5') != True: if os.path.isfile(home+'/.deepface/weights/race_model_single_batch.h5') != True:
print("race_model_single_batch.h5 will be downloaded...") print("race_model_single_batch.h5 will be downloaded...")