Skip to content

Commit

Permalink
optimize import numpy (#451)
Browse files Browse the repository at this point in the history
Co-authored-by: zheng.shen <[email protected]>
  • Loading branch information
shenzheng-1 and zheng.shen authored Dec 25, 2024
1 parent 54a0e17 commit 023d33c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion face_recognition/face_recognition_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import time
from datetime import datetime, timedelta
import numpy as np
import json

from sqlalchemy.sql import text
Expand Down Expand Up @@ -104,6 +103,7 @@ def ensure_face_vectors(self, repo_id):
def face_cluster(self, repo_id):
try:
from sklearn.cluster import HDBSCAN
import numpy as np
except ImportError:
logger.warning('Package scikit-learn is not installed. ')
return
Expand Down
4 changes: 3 additions & 1 deletion face_recognition/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import posixpath

import numpy as np
from seaserv import seafile_api

from seafevents.repo_metadata.utils import query_metadata_rows, get_file_content
Expand All @@ -19,18 +18,21 @@


def feature_distance(feature1, feature2):
import numpy as np
diff = np.subtract(feature1, feature2)
dist = np.sum(np.square(diff), 0)
return dist


def b64encode_embeddings(embeddings):
import numpy as np
embedding_array = np.array(embeddings).astype(np.float32)
encode = base64.b64encode(embedding_array.tobytes())
return encode.decode('utf-8')


def b64decode_embeddings(encode):
import numpy as np
decode = base64.b64decode(encode)
embedding_array = np.frombuffer(decode, dtype=np.float32)
face_num = len(embedding_array) // FACE_EMBEDDING_DIM
Expand Down

0 comments on commit 023d33c

Please sign in to comment.