Skip to content

Commit

Permalink
sface class
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed May 10, 2022
1 parent b15294e commit 631cf64
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Face recognition, facial attribute analysis and vector representation functions

**Command Line Interface**

DeepFace comes with a command line interface as well. You are able to access its functions in command line in the command line as shown below. It expects the function name as 1st argument and function arguments respectively.
DeepFace comes with a command line interface as well. You are able to access its functions in command line as shown below. The command deepface expects the function name as 1st argument and function arguments thereafter.

```shell
deepface verify -img1_path tests/dataset/img1.jpg -img2_path tests/dataset/img2.jpg
Expand Down
4 changes: 2 additions & 2 deletions deepface/DeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pickle
import fire

from deepface.basemodels import VGGFace, OpenFace, Facenet, Facenet512, FbDeepFace, DeepID, DlibWrapper, ArcFace, Boosting, SFaceWrapper
from deepface.basemodels import VGGFace, OpenFace, Facenet, Facenet512, FbDeepFace, DeepID, DlibWrapper, ArcFace, SFace, Boosting
from deepface.extendedmodels import Age, Gender, Race, Emotion
from deepface.commons import functions, realtime, distance as dst

Expand Down Expand Up @@ -47,7 +47,7 @@ def build_model(model_name):
'DeepID': DeepID.loadModel,
'Dlib': DlibWrapper.loadModel,
'ArcFace': ArcFace.loadModel,
'SFace': SFaceWrapper.load_model,
'SFace': SFace.load_model,
'Emotion': Emotion.loadModel,
'Age': Age.loadModel,
'Gender': Gender.loadModel,
Expand Down
48 changes: 48 additions & 0 deletions deepface/basemodels/SFace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import numpy as np
import cv2 as cv
import gdown

from deepface.commons import functions

class _Layer:
input_shape = (None, 112, 112, 3)
output_shape = (None, 1, 128)

class SFaceModel:

def __init__(self, model_path):

self.model = cv.FaceRecognizerSF.create(
model = model_path,
config = "",
backend_id = 0,
target_id = 0)

self.layers = [_Layer()]

def predict(self, image):
# Preprocess
input_blob = (image[0] * 255).astype(np.uint8) # revert the image to original format and preprocess using the model

# Forward
embeddings = self.model.feature(input_blob)

return embeddings


def load_model(url = "https://github.com/opencv/opencv_zoo/raw/master/models/face_recognition_sface/face_recognition_sface_2021dec.onnx"):

home = functions.get_deepface_home()

file_name = home + '/.deepface/weights/face_recognition_sface_2021dec.onnx'

if not os.path.isfile(file_name):

print("sface weights will be downloaded...")

gdown.download(url, file_name, quiet=False)

model = SFaceModel(model_path = file_name)

return model
53 changes: 0 additions & 53 deletions deepface/basemodels/SFaceWrapper.py

This file was deleted.

0 comments on commit 631cf64

Please sign in to comment.