mirror of
https://github.com/deepinsight/insightface.git
synced 2026-01-18 15:40:18 +00:00
Update
This commit is contained in:
@@ -2,7 +2,7 @@ from .inspireface import ImageStream, FaceExtended, FaceInformation, SessionCust
|
||||
launch, FeatureHubConfiguration, feature_hub_enable, feature_hub_disable, feature_comparison, \
|
||||
FaceIdentity, feature_hub_set_search_threshold, feature_hub_face_insert, SearchResult, \
|
||||
feature_hub_face_search, feature_hub_face_search_top_k, feature_hub_face_update, feature_hub_face_remove, \
|
||||
feature_hub_get_face_identity, feature_hub_get_face_count, view_table_in_terminal, version, query_launch_status, reload, set_expansive_pack_path, \
|
||||
feature_hub_get_face_identity, feature_hub_get_face_count, view_table_in_terminal, version, query_launch_status, reload, \
|
||||
set_logging_level, disable_logging, show_system_resource_statistics, get_recommended_cosine_threshold, cosine_similarity_convert_to_percentage, \
|
||||
get_similarity_converter_config, set_similarity_converter_config, pull_latest_model, \
|
||||
HF_PK_AUTO_INCREMENT, HF_PK_MANUAL_INPUT, HF_SEARCH_MODE_EAGER, HF_SEARCH_MODE_EXHAUSTIVE
|
||||
get_similarity_converter_config, set_similarity_converter_config, pull_latest_model, switch_landmark_engine, \
|
||||
HF_PK_AUTO_INCREMENT, HF_PK_MANUAL_INPUT, HF_SEARCH_MODE_EAGER, HF_SEARCH_MODE_EXHAUSTIVE
|
||||
File diff suppressed because it is too large
Load Diff
@@ -99,6 +99,14 @@ class ImageStream(object):
|
||||
if ret != 0:
|
||||
raise Exception("Error in creating ImageStream")
|
||||
|
||||
def write_to_file(self, file_path: str):
|
||||
"""
|
||||
Write the image stream to a file. Like PATH/image.jpg
|
||||
"""
|
||||
ret = HFDeBugImageStreamDecodeSave(self._handle, file_path)
|
||||
if ret != 0:
|
||||
logger.error(f"Write ImageStream to file error: {ret}")
|
||||
|
||||
def release(self):
|
||||
"""
|
||||
Release the resources associated with the ImageStream.
|
||||
@@ -365,6 +373,16 @@ class InspireFaceSession(object):
|
||||
|
||||
return np.asarray(landmark).reshape(-1, 2)
|
||||
|
||||
def print_track_cost_spend(self):
|
||||
ret = HFSessionPrintTrackCostSpend(self._sess)
|
||||
if ret != 0:
|
||||
logger.error(f"Print track cost spend error: {ret}")
|
||||
|
||||
def set_enable_track_cost_spend(self, enable: bool):
|
||||
ret = HFSessionSetEnableTrackCostSpend(self._sess, enable)
|
||||
if ret != 0:
|
||||
logger.error(f"Set enable track cost spend error: {ret}")
|
||||
|
||||
def set_detection_confidence_threshold(self, threshold: float):
|
||||
"""
|
||||
Sets the detection confidence threshold for the face detection session.
|
||||
@@ -633,13 +651,6 @@ def launch(model_name: str = "Pikachu", resource_path: str = None) -> bool:
|
||||
return False
|
||||
return True
|
||||
|
||||
def set_expansive_pack_path(path: str):
|
||||
path_c = String(bytes(path, encoding="utf8"))
|
||||
ret = HFSetExpansiveHardwareAppleCoreMLModelPath(path_c)
|
||||
if ret != 0:
|
||||
logger.error(f"Set expansive pack path error: {ret}")
|
||||
return False
|
||||
return True
|
||||
|
||||
def pull_latest_model(model_name: str = "Pikachu") -> str:
|
||||
sm = ResourceManager()
|
||||
@@ -676,6 +687,13 @@ def query_launch_status() -> bool:
|
||||
return False
|
||||
return status.value == 1
|
||||
|
||||
def switch_landmark_engine(engine: int):
|
||||
ret = HFSwitchLandmarkEngine(engine)
|
||||
if ret != 0:
|
||||
logger.error(f"Switch landmark engine error: {ret}")
|
||||
return False
|
||||
return True
|
||||
|
||||
@dataclass
|
||||
class FeatureHubConfiguration:
|
||||
"""
|
||||
@@ -840,7 +858,7 @@ class FaceIdentity(object):
|
||||
feature.size = HInt32(self.feature.size)
|
||||
feature.data = data_ptr
|
||||
return HFFaceFeatureIdentity(
|
||||
customId=HFaceId(self.id),
|
||||
id=HFaceId(self.id),
|
||||
feature=PHFFaceFeature(feature)
|
||||
)
|
||||
|
||||
@@ -1109,7 +1127,6 @@ def set_logging_level(level: int) -> None:
|
||||
"""
|
||||
HFSetLogLevel(level)
|
||||
|
||||
|
||||
def disable_logging() -> None:
|
||||
"""
|
||||
Disables all logging from the InspireFace library.
|
||||
@@ -1122,3 +1139,34 @@ def show_system_resource_statistics():
|
||||
"""
|
||||
HFDeBugShowResourceStatistics()
|
||||
|
||||
def switch_apple_coreml_inference_mode(mode: int):
|
||||
"""
|
||||
Switches the Apple CoreML inference mode.
|
||||
"""
|
||||
ret = HFSetAppleCoreMLInferenceMode(mode)
|
||||
if ret != 0:
|
||||
logger.error(f"Failed to set Apple CoreML inference mode: {ret}")
|
||||
return False
|
||||
return True
|
||||
|
||||
def set_expansive_hardware_rockchip_dma_heap_path(path: str):
|
||||
"""
|
||||
Sets the path to the expansive hardware Rockchip DMA heap.
|
||||
"""
|
||||
ret = HFSetExpansiveHardwareRockchipDmaHeapPath(path)
|
||||
if ret != 0:
|
||||
logger.error(f"Failed to set expansive hardware Rockchip DMA heap path: {ret}")
|
||||
return False
|
||||
return True
|
||||
|
||||
def query_expansive_hardware_rockchip_dma_heap_path() -> str:
|
||||
"""
|
||||
Queries the path to the expansive hardware Rockchip DMA heap.
|
||||
"""
|
||||
path = HString()
|
||||
ret = HFQueryExpansiveHardwareRockchipDmaHeapPath(path)
|
||||
if ret != 0:
|
||||
logger.error(f"Failed to query expansive hardware Rockchip DMA heap path: {ret}")
|
||||
return None
|
||||
return str(path.value)
|
||||
|
||||
|
||||
@@ -34,7 +34,22 @@ class ResourceManager:
|
||||
"url": "https://github.com/HyperInspire/InspireFace/releases/download/v1.x/Megatron",
|
||||
"filename": "Megatron",
|
||||
"md5": "28f2284c5e7cf53b0e152ff524a416c966ab21e724002643b1304aedc4af6b06"
|
||||
}
|
||||
},
|
||||
"Megatron_TRT": {
|
||||
"url": "https://github.com/HyperInspire/InspireFace/releases/download/v1.x/Megatron_TRT",
|
||||
"filename": "Megatron_TRT",
|
||||
"md5": "25fb4a585b73b0114ff0d64c2bc4071bd005a32a77149b66c474985077dc8f8a"
|
||||
},
|
||||
"Gundam_RK356X": {
|
||||
"url": "https://github.com/HyperInspire/InspireFace/releases/download/v1.x/Gundam_RK356X",
|
||||
"filename": "Gundam_RK356X",
|
||||
"md5": "69ea23b89851a38c729b32bb0ed33cf62ebd3c891ea5d596afeadeb1f1c79c69"
|
||||
},
|
||||
"Gundam_RK3588": {
|
||||
"url": "https://github.com/HyperInspire/InspireFace/releases/download/v1.x/Gundam_RK3588",
|
||||
"filename": "Gundam_RK3588",
|
||||
"md5": "030965798c5257aef11640657f85b89d82e9d170c3798d0b4f2b62ee6aa245ea"
|
||||
},
|
||||
}
|
||||
|
||||
def get_model(self, name: str, re_download: bool = False) -> str:
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
# Session option
|
||||
from inspireface.modules.core.native import HF_ENABLE_NONE, HF_ENABLE_FACE_RECOGNITION, HF_ENABLE_LIVENESS, HF_ENABLE_IR_LIVENESS, \
|
||||
HF_ENABLE_MASK_DETECT, HF_ENABLE_FACE_ATTRIBUTE, HF_ENABLE_QUALITY, HF_ENABLE_INTERACTION, HF_PK_AUTO_INCREMENT, HF_PK_MANUAL_INPUT
|
||||
HF_ENABLE_MASK_DETECT, HF_ENABLE_FACE_ATTRIBUTE, HF_ENABLE_QUALITY, HF_ENABLE_INTERACTION, HF_ENABLE_FACE_POSE, HF_PK_AUTO_INCREMENT, HF_PK_MANUAL_INPUT, \
|
||||
HF_LANDMARK_HYPLMV2_0_25, HF_LANDMARK_HYPLMV2_0_50, HF_LANDMARK_INSIGHTFACE_2D106_TRACK
|
||||
|
||||
# Face track mode
|
||||
from inspireface.modules.core.native import HF_DETECT_MODE_ALWAYS_DETECT, HF_DETECT_MODE_LIGHT_TRACK, HF_DETECT_MODE_TRACK_BY_DETECTION
|
||||
|
||||
71
cpp-package/inspireface/python/read_nv21.py
Normal file
71
cpp-package/inspireface/python/read_nv21.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
from inspireface import ImageStream
|
||||
import inspireface as isf
|
||||
|
||||
|
||||
def read_nv21(file_path, width, height, rotate=0):
|
||||
with open(file_path, 'rb') as f:
|
||||
nv21_data = f.read()
|
||||
|
||||
yuv = np.frombuffer(nv21_data, dtype=np.uint8)
|
||||
|
||||
expected_size = width * height * 3 // 2
|
||||
if len(yuv) < expected_size:
|
||||
raise ValueError(f"NV21 data size is not enough: expected {expected_size} bytes, actual {len(yuv)} bytes")
|
||||
|
||||
yuv_mat = np.zeros((height * 3 // 2, width), dtype=np.uint8)
|
||||
yuv_mat[:] = yuv[:height * width * 3 // 2].reshape(height * 3 // 2, width)
|
||||
|
||||
bgr_mat = cv2.cvtColor(yuv_mat, cv2.COLOR_YUV2BGR_NV21)
|
||||
|
||||
# add reverse rotate
|
||||
if rotate != 0:
|
||||
# calculate reverse rotate angle
|
||||
reverse_angle = (360 - rotate) % 360
|
||||
|
||||
# select rotate method by angle
|
||||
if reverse_angle == 90:
|
||||
bgr_mat = cv2.rotate(bgr_mat, cv2.ROTATE_90_CLOCKWISE)
|
||||
elif reverse_angle == 180:
|
||||
bgr_mat = cv2.rotate(bgr_mat, cv2.ROTATE_180)
|
||||
elif reverse_angle == 270:
|
||||
bgr_mat = cv2.rotate(bgr_mat, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
||||
else:
|
||||
# for non 90 degree angle, use affine transform
|
||||
center = (bgr_mat.shape[1] // 2, bgr_mat.shape[0] // 2)
|
||||
rotation_matrix = cv2.getRotationMatrix2D(center, reverse_angle, 1.0)
|
||||
bgr_mat = cv2.warpAffine(bgr_mat, rotation_matrix, (bgr_mat.shape[1], bgr_mat.shape[0]))
|
||||
|
||||
return bgr_mat
|
||||
|
||||
# example usage
|
||||
if __name__ == "__main__":
|
||||
image_width = 640
|
||||
image_height = 480
|
||||
nv21_file = ""
|
||||
pre_rotate = 90
|
||||
try:
|
||||
# read and reverse rotate image
|
||||
bgr_image = read_nv21(nv21_file, image_width, image_height, pre_rotate)
|
||||
|
||||
cv2.imshow("origin", bgr_image)
|
||||
|
||||
# show original image for comparison
|
||||
bgr_image_original = read_nv21(nv21_file, image_width, image_height)
|
||||
cv2.imshow("rotate ", bgr_image_original)
|
||||
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
except Exception as e:
|
||||
print(f"error: {e}")
|
||||
|
||||
with open(nv21_file, 'rb') as f:
|
||||
nv21_data = f.read()
|
||||
|
||||
stream = ImageStream.load_from_buffer(nv21_data, image_width, image_height, isf.HF_STREAM_YUV_NV21, isf.HF_CAMERA_ROTATION_90)
|
||||
|
||||
stream.debug_show()
|
||||
|
||||
|
||||
@@ -5,85 +5,91 @@ import click
|
||||
import numpy as np
|
||||
|
||||
race_tags = ["Black", "Asian", "Latino/Hispanic", "Middle Eastern", "White"]
|
||||
gender_tags = ["Female", "Male", ]
|
||||
age_bracket_tags = ["0-2 years old", "3-9 years old", "10-19 years old", "20-29 years old", "30-39 years old",
|
||||
"40-49 years old", "50-59 years old", "60-69 years old", "more than 70 years old"]
|
||||
gender_tags = ["Female", "Male"]
|
||||
age_bracket_tags = [
|
||||
"0-2 years old", "3-9 years old", "10-19 years old", "20-29 years old", "30-39 years old",
|
||||
"40-49 years old", "50-59 years old", "60-69 years old", "more than 70 years old"
|
||||
]
|
||||
|
||||
@click.command()
|
||||
@click.argument('image_path')
|
||||
def case_face_detection_image(image_path):
|
||||
@click.option('--show', is_flag=True, help='Display the image with detected faces.')
|
||||
def case_face_detection_image(image_path, show):
|
||||
"""
|
||||
This is a sample application for face detection and tracking using an image.
|
||||
It also includes pipeline extensions such as RGB liveness, mask detection, and face quality evaluation.
|
||||
"""
|
||||
# Optional features, loaded during session creation based on the modules specified.
|
||||
opt = isf.HF_ENABLE_FACE_RECOGNITION | isf.HF_ENABLE_QUALITY | isf.HF_ENABLE_MASK_DETECT | isf.HF_ENABLE_LIVENESS | isf.HF_ENABLE_INTERACTION | isf.HF_ENABLE_FACE_ATTRIBUTE
|
||||
opt = isf.HF_ENABLE_FACE_RECOGNITION | isf.HF_ENABLE_QUALITY | isf.HF_ENABLE_MASK_DETECT | \
|
||||
isf.HF_ENABLE_LIVENESS | isf.HF_ENABLE_INTERACTION | isf.HF_ENABLE_FACE_ATTRIBUTE
|
||||
session = isf.InspireFaceSession(opt, isf.HF_DETECT_MODE_ALWAYS_DETECT)
|
||||
|
||||
# Set detection confidence threshold
|
||||
session.set_detection_confidence_threshold(0.5)
|
||||
|
||||
# Load the image using OpenCV.
|
||||
# Load image
|
||||
image = cv2.imread(image_path)
|
||||
assert image is not None, "Please check that the image path is correct."
|
||||
|
||||
# Perform face detection on the image.
|
||||
# Dynamic drawing parameters (adjusted to image size)
|
||||
h, w = image.shape[:2]
|
||||
scale = max(w, h) / 1000.0
|
||||
line_thickness = max(1, int(2 * scale))
|
||||
circle_radius = max(1, int(1.5 * scale))
|
||||
font_scale = 0.5 * scale
|
||||
|
||||
# Detect faces
|
||||
faces = session.face_detection(image)
|
||||
print(f"face detection: {len(faces)} found")
|
||||
|
||||
# Copy the image for drawing the bounding boxes.
|
||||
|
||||
draw = image.copy()
|
||||
for idx, face in enumerate(faces):
|
||||
print(f"{'==' * 20}")
|
||||
print(f"idx: {idx}")
|
||||
print(f"detection confidence: {face.detection_confidence}")
|
||||
# Print Euler angles of the face.
|
||||
print(f"roll: {face.roll}, yaw: {face.yaw}, pitch: {face.pitch}")
|
||||
|
||||
# Get face bounding box
|
||||
x1, y1, x2, y2 = face.location
|
||||
|
||||
# Calculate center, size, and angle
|
||||
center = ((x1 + x2) / 2, (y1 + y2) / 2)
|
||||
size = (x2 - x1, y2 - y1)
|
||||
angle = face.roll
|
||||
|
||||
# Apply rotation to the bounding box corners
|
||||
rect = ((center[0], center[1]), (size[0], size[1]), angle)
|
||||
box = cv2.boxPoints(rect)
|
||||
box = box.astype(int)
|
||||
box = cv2.boxPoints(rect).astype(int)
|
||||
cv2.drawContours(draw, [box], 0, (100, 180, 29), line_thickness)
|
||||
|
||||
# Draw the rotated bounding box
|
||||
cv2.drawContours(draw, [box], 0, (100, 180, 29), 2)
|
||||
|
||||
# Draw landmarks
|
||||
# Draw landmark
|
||||
lmk = session.get_face_dense_landmark(face)
|
||||
for x, y in lmk.astype(int):
|
||||
cv2.circle(draw, (x, y), 0, (220, 100, 0), 2)
|
||||
cv2.circle(draw, (x, y), circle_radius, (220, 100, 0), -1)
|
||||
|
||||
# Features must be enabled during session creation to use them here.
|
||||
select_exec_func = isf.HF_ENABLE_QUALITY | isf.HF_ENABLE_MASK_DETECT | isf.HF_ENABLE_LIVENESS | isf.HF_ENABLE_INTERACTION | isf.HF_ENABLE_FACE_ATTRIBUTE
|
||||
# Execute the pipeline to obtain richer face information.
|
||||
# Optional: Add detection confidence (text) on the face box
|
||||
# label = f"{face.detection_confidence:.2f}"
|
||||
# cv2.putText(draw, label, (x1, max(y1 - 10, 0)), cv2.FONT_HERSHEY_SIMPLEX,
|
||||
# font_scale, (255, 255, 255), line_thickness)
|
||||
|
||||
# Execute extended functions (optional modules)
|
||||
select_exec_func = isf.HF_ENABLE_QUALITY | isf.HF_ENABLE_MASK_DETECT | \
|
||||
isf.HF_ENABLE_LIVENESS | isf.HF_ENABLE_INTERACTION | isf.HF_ENABLE_FACE_ATTRIBUTE
|
||||
extends = session.face_pipeline(image, faces, select_exec_func)
|
||||
|
||||
for idx, ext in enumerate(extends):
|
||||
print(f"{'==' * 20}")
|
||||
print(f"idx: {idx}")
|
||||
# For these pipeline results, you can set thresholds based on the specific scenario to make judgments.
|
||||
print(f"quality: {ext.quality_confidence}")
|
||||
print(f"rgb liveness: {ext.rgb_liveness_confidence}")
|
||||
print(f"face mask: {ext.mask_confidence}")
|
||||
print(
|
||||
f"face eyes status: left eye: {ext.left_eye_status_confidence} right eye: {ext.right_eye_status_confidence}")
|
||||
print(f"face eyes status: left eye: {ext.left_eye_status_confidence} right eye: {ext.right_eye_status_confidence}")
|
||||
print(f"gender: {gender_tags[ext.gender]}")
|
||||
print(f"race: {race_tags[ext.race]}")
|
||||
print(f"age: {age_bracket_tags[ext.age_bracket]}")
|
||||
|
||||
# Save the annotated image to the 'tmp/' directory.
|
||||
save_path = os.path.join("tmp/", "det.jpg")
|
||||
# Save the annotated image
|
||||
save_path = os.path.join("tmp", "det.jpg")
|
||||
os.makedirs("tmp", exist_ok=True)
|
||||
cv2.imwrite(save_path, draw)
|
||||
if show:
|
||||
cv2.imshow("Face Detection", draw)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
||||
print(f"\nSave annotated image to {save_path}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.makedirs("tmp", exist_ok=True)
|
||||
case_face_detection_image()
|
||||
|
||||
@@ -4,7 +4,7 @@ import click
|
||||
import cv2
|
||||
import inspireface as isf
|
||||
import numpy as np
|
||||
|
||||
import time
|
||||
|
||||
def generate_color(id):
|
||||
"""
|
||||
@@ -50,8 +50,13 @@ def case_face_tracker_from_video(source, show, out):
|
||||
"""
|
||||
# Optional features, loaded during session creation based on the modules specified.
|
||||
opt = isf.HF_ENABLE_NONE | isf.HF_ENABLE_INTERACTION
|
||||
session = isf.InspireFaceSession(opt, isf.HF_DETECT_MODE_LIGHT_TRACK, max_detect_num=25, detect_pixel_level=320) # Use video mode
|
||||
session = isf.InspireFaceSession(opt, isf.HF_DETECT_MODE_LIGHT_TRACK, max_detect_num=25, detect_pixel_level=160) # Use video mode
|
||||
session.set_track_mode_smooth_ratio(0.06)
|
||||
session.set_track_mode_num_smooth_cache_frame(15)
|
||||
session.set_filter_minimum_face_pixel_size(0)
|
||||
session.set_track_model_detect_interval(0)
|
||||
session.set_landmark_augmentation_num(1)
|
||||
session.set_enable_track_cost_spend(True)
|
||||
# Determine if the source is a digital webcam index or a video file path.
|
||||
try:
|
||||
source_index = int(source) # Try to convert source to an integer.
|
||||
@@ -82,8 +87,11 @@ def case_face_tracker_from_video(source, show, out):
|
||||
break # Exit loop if no more frames or error occurs.
|
||||
|
||||
# Process frame here (e.g., face detection/tracking).
|
||||
t1 = time.time()
|
||||
faces = session.face_detection(frame)
|
||||
|
||||
t2 = time.time()
|
||||
# print(f"Face detection time: {t2 - t1} seconds")
|
||||
session.print_track_cost_spend()
|
||||
exts = session.face_pipeline(frame, faces, isf.HF_ENABLE_INTERACTION)
|
||||
|
||||
for idx, face in enumerate(faces):
|
||||
|
||||
@@ -4,59 +4,14 @@ import inspireface as isf
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
FEATURE = np.asarray([ 0.0706566, 0.00640248, 0.0418103, -0.00597861, 0.0269879, 0.0187478, 0.0486305, 0.0349162, -0.0080779, -0.0550556, 0.0229963,
|
||||
-0.00683422, -0.0338589, 0.0533989, -0.0371725, 0.000972469, 0.0612415, 0.0389846, -0.00126743, -0.0128782, 0.0935529, 0.0588179,
|
||||
0.0164787, -0.00732871, -0.0458209, -0.0100137, -0.0372892, 0.000871123, 0.0245121, -0.0811471, -0.00481095, 0.0266868, 0.0712961,
|
||||
-0.0675362, -0.0117453, 0.0658745, -0.0694139, -0.00704822, -0.0237313, 0.0209365, 0.0131902, 0.00192449, -0.0593105, 0.0191942,
|
||||
-0.00625798, 0.00748682, 0.0533557, 0.0314002, -0.0627113, 0.0827862, 0.00336722, -0.0191575, -0.0180252, 0.0150318, -0.0686462,
|
||||
0.0465634, 0.0627244, 0.0449248, -0.037054, -0.0486668, 0.040752, 0.0143315, -0.0763842, -0.0161973, 0.0319588, 0.0112792,
|
||||
-0.102007, 0.0649219, 0.0630833, 0.0421069, 0.0519043, -0.084082, 0.0249516, 0.023046, 0.071994, -0.0272229, 0.0167103,
|
||||
-0.00694243, 0.0366775, 0.0672882, 0.0122419, -0.0233413, -0.0144258, -0.012853, -0.0202025, 0.000983093, -0.00776073, -0.0268638,
|
||||
0.00682446, 0.0262906, -0.0407654, -0.0144264, -0.0310807, 0.0596711, 0.0238081, -0.0138019, 0.000502882, 0.0496892, 0.0126823,
|
||||
0.0511028, -0.0310699, -0.0322141, 0.00996936, 0.0675392, -0.0164277, 0.0930009, -0.037467, 0.0419618, -0.00358901, -0.0309569,
|
||||
-0.0225608, -0.0332198, 0.00102291, 0.108814, -0.0831313, 0.048208, -0.0277542, -0.061584, 0.0721224, -0.0795082, 0.0340047,
|
||||
0.056139, -0.0166783, -0.0803042, -0.014245, -0.0476374, 0.048495, 0.0378856, 0.0706566, 0.00640248, 0.0418103, -0.00597861,
|
||||
0.0269879, 0.0187478, 0.0486305, 0.0349162, -0.0080779, -0.0550556, 0.0229963, -0.00683422, -0.0338589, 0.0533989, -0.0371725,
|
||||
0.000972469, 0.0612415, 0.0389846, -0.00126743, -0.0128782, 0.0935529, 0.0588179, 0.0164787, -0.00732871, -0.0458209, -0.0100137,
|
||||
-0.0372892, 0.000871123, 0.0245121, -0.0811471, -0.00481095, 0.0266868, 0.0712961, -0.0675362, -0.0117453, 0.0658745, -0.0694139,
|
||||
-0.00704822, -0.0237313, 0.0209365, 0.0131902, 0.00192449, -0.0593105, 0.0191942, -0.00625798, 0.00748682, 0.0533557, 0.0314002,
|
||||
-0.0627113, 0.0827862, 0.00336722, -0.0191575, -0.0180252, 0.0150318, -0.0686462, 0.0465634, 0.0627244, 0.0449248, -0.037054,
|
||||
-0.0486668, 0.040752, 0.0143315, -0.0763842, -0.0161973, 0.0319588, 0.0112792, -0.102007, 0.0649219, 0.0630833, 0.0421069,
|
||||
0.0519043, -0.084082, 0.0249516, 0.023046, 0.071994, -0.0272229, 0.0167103, -0.00694243, 0.0366775, 0.0672882, 0.0122419,
|
||||
-0.0233413, -0.0144258, -0.012853, -0.0202025, 0.000983093, -0.00776073, -0.0268638, 0.00682446, 0.0262906, -0.0407654, -0.0144264,
|
||||
-0.0310807, 0.0596711, 0.0238081, -0.0138019, 0.000502882, 0.0496892, 0.0126823, 0.0511028, -0.0310699, -0.0322141, 0.00996936,
|
||||
0.0675392, -0.0164277, 0.0930009, -0.037467, 0.0419618, -0.00358901, -0.0309569, -0.0225608, -0.0332198, 0.00102291, 0.108814,
|
||||
-0.0831313, 0.048208, -0.0277542, -0.061584, 0.0721224, -0.0795082, 0.0340047, 0.056139, -0.0166783, -0.0803042, -0.014245,
|
||||
-0.0476374, 0.048495, 0.0378856, 0.0706566, 0.00640248, 0.0418103, -0.00597861, 0.0269879, 0.0187478, 0.0486305, 0.0349162,
|
||||
-0.0080779, -0.0550556, 0.0229963, -0.00683422, -0.0338589, 0.0533989, -0.0371725, 0.000972469, 0.0612415, 0.0389846, -0.00126743,
|
||||
-0.0128782, 0.0935529, 0.0588179, 0.0164787, -0.00732871, -0.0458209, -0.0100137, -0.0372892, 0.000871123, 0.0245121, -0.0811471,
|
||||
-0.00481095, 0.0266868, 0.0712961, -0.0675362, -0.0117453, 0.0658745, -0.0694139, -0.00704822, -0.0237313, 0.0209365, 0.0131902,
|
||||
0.00192449, -0.0593105, 0.0191942, -0.00625798, 0.00748682, 0.0533557, 0.0314002, -0.0627113, 0.0827862, 0.00336722, -0.0191575,
|
||||
-0.0180252, 0.0150318, -0.0686462, 0.0465634, 0.0627244, 0.0449248, -0.037054, -0.0486668, 0.040752, 0.0143315, -0.0763842,
|
||||
-0.0161973, 0.0319588, 0.0112792, -0.102007, 0.0649219, 0.0630833, 0.0421069, 0.0519043, -0.084082, 0.0249516, 0.023046,
|
||||
0.071994, -0.0272229, 0.0167103, -0.00694243, 0.0366775, 0.0672882, 0.0122419, -0.0233413, -0.0144258, -0.012853, -0.0202025,
|
||||
0.000983093, -0.00776073, -0.0268638, 0.00682446, 0.0262906, -0.0407654, -0.0144264, -0.0310807, 0.0596711, 0.0238081, -0.0138019,
|
||||
0.000502882, 0.0496892, 0.0126823, 0.0511028, -0.0310699, -0.0322141, 0.00996936, 0.0675392, -0.0164277, 0.0930009, -0.037467,
|
||||
0.0419618, -0.00358901, -0.0309569, -0.0225608, -0.0332198, 0.00102291, 0.108814, -0.0831313, 0.048208, -0.0277542, -0.061584,
|
||||
0.0721224, -0.0795082, 0.0340047, 0.056139, -0.0166783, -0.0803042, -0.014245, -0.0476374, 0.048495, 0.0378856, 0.0706566,
|
||||
0.00640248, 0.0418103, -0.00597861, 0.0269879, 0.0187478, 0.0486305, 0.0349162, -0.0080779, -0.0550556, 0.0229963, -0.00683422,
|
||||
-0.0338589, 0.0533989, -0.0371725, 0.000972469, 0.0612415, 0.0389846, -0.00126743, -0.0128782, 0.0935529, 0.0588179, 0.0164787,
|
||||
-0.00732871, -0.0458209, -0.0100137, -0.0372892, 0.000871123, 0.0245121, -0.0811471, -0.00481095, 0.0266868, 0.0712961, -0.0675362,
|
||||
-0.0117453, 0.0658745, -0.0694139, -0.00704822, -0.0237313, 0.0209365, 0.0131902, 0.00192449, -0.0593105, 0.0191942, -0.00625798,
|
||||
0.00748682, 0.0533557, 0.0314002, -0.0627113, 0.0827862, 0.00336722, -0.0191575, -0.0180252, 0.0150318, -0.0686462, 0.0465634,
|
||||
0.0627244, 0.0449248, -0.037054, -0.0486668, 0.040752, 0.0143315, -0.0763842, -0.0161973, 0.0319588, 0.0112792, -0.102007,
|
||||
0.0649219, 0.0630833, 0.0421069, 0.0519043, -0.084082, 0.0249516, 0.023046, 0.071994, -0.0272229, 0.0167103, -0.00694243,
|
||||
0.0366775, 0.0672882, 0.0122419, -0.0233413, -0.0144258, -0.012853, -0.0202025, 0.000983093, -0.00776073, -0.0268638, 0.00682446,
|
||||
0.0262906, -0.0407654, -0.0144264, -0.0310807, 0.0596711, 0.0238081, -0.0138019, 0.000502882, 0.0496892, 0.0126823, 0.0511028,
|
||||
-0.0310699, -0.0322141, 0.00996936, 0.0675392, -0.0164277, 0.0930009, -0.037467, 0.0419618, -0.00358901, -0.0309569, -0.0225608,
|
||||
-0.0332198, 0.00102291, 0.108814, -0.0831313, 0.048208, -0.0277542, -0.061584, 0.0721224, -0.0795082, 0.0340047, 0.056139,
|
||||
-0.0166783, -0.0803042, -0.014245, -0.0476374, 0.048495, 0.0378856,], dtype=np.float32)
|
||||
|
||||
def case_feature_hub():
|
||||
# Gen a random feature
|
||||
gen = np.random.rand(512).astype(np.float32)
|
||||
# Set db path
|
||||
db_path = "test.db"
|
||||
# Configure the feature management system.
|
||||
feature_hub_config = isf.FeatureHubConfiguration(
|
||||
primary_key_mode=isf.HF_PK_AUTO_INCREMENT,
|
||||
primary_key_mode=isf.HF_PK_MANUAL_INPUT,
|
||||
enable_persistence=True,
|
||||
persistence_db_path=db_path,
|
||||
search_threshold=0.48,
|
||||
@@ -64,16 +19,17 @@ def case_feature_hub():
|
||||
)
|
||||
ret = isf.feature_hub_enable(feature_hub_config)
|
||||
assert ret, "Failed to enable FeatureHub."
|
||||
print(isf.feature_hub_get_face_count())
|
||||
print('T1, face count:', isf.feature_hub_get_face_count())
|
||||
for i in range(10):
|
||||
v = np.random.rand(512).astype(np.float32)
|
||||
feature = isf.FaceIdentity(v, -1)
|
||||
isf.feature_hub_face_insert(feature)
|
||||
feature = isf.FaceIdentity(FEATURE, -1)
|
||||
feature = isf.FaceIdentity(v, i)
|
||||
ret, new_id = isf.feature_hub_face_insert(feature)
|
||||
assert ret, "Failed to insert face feature data into FeatureHub."
|
||||
assert new_id == i, "Failed to get the correct new id."
|
||||
feature = isf.FaceIdentity(gen, -1)
|
||||
isf.feature_hub_face_insert(feature)
|
||||
print(isf.feature_hub_get_face_count())
|
||||
result = isf.feature_hub_face_search(FEATURE)
|
||||
print(result.confidence, result.similar_identity.id)
|
||||
result = isf.feature_hub_face_search(gen)
|
||||
print(f"result: {result}")
|
||||
assert os.path.exists(db_path), "FeatureHub database file not found."
|
||||
|
||||
|
||||
|
||||
@@ -7,14 +7,17 @@ import os
|
||||
def get_version():
|
||||
"""Get version number"""
|
||||
version_path = os.path.join(os.path.dirname(__file__), 'version.txt')
|
||||
with open(version_path, 'r') as f:
|
||||
return f.read().strip()
|
||||
try:
|
||||
with open(version_path, 'r') as f:
|
||||
return f.read().strip()
|
||||
except FileNotFoundError:
|
||||
return "0.0.0"
|
||||
|
||||
def get_wheel_platform_tag():
|
||||
"""Get wheel package platform tag"""
|
||||
system = platform.system().lower()
|
||||
machine = platform.machine().lower()
|
||||
|
||||
|
||||
arch_mapping = {
|
||||
'x86_64': {
|
||||
'windows': 'win_amd64',
|
||||
@@ -37,7 +40,10 @@ def get_wheel_platform_tag():
|
||||
'darwin': 'macosx_11_0_arm64'
|
||||
}
|
||||
}
|
||||
platform_arch = arch_mapping.get(machine, {}).get(system)
|
||||
if os.getenv('INSPIRE_FACE_TARGET_AARCH_MAPPING'):
|
||||
platform_arch = os.getenv('INSPIRE_FACE_TARGET_AARCH_MAPPING')
|
||||
else:
|
||||
platform_arch = arch_mapping.get(machine, {}).get(system)
|
||||
if not platform_arch:
|
||||
print("Unsupported platform: {} {}".format(system, machine))
|
||||
raise RuntimeError("Unsupported platform: {} {}".format(system, machine))
|
||||
@@ -77,8 +83,22 @@ class BinaryDistWheel(bdist_wheel):
|
||||
self.plat_name = get_wheel_platform_tag()
|
||||
self.universal = False
|
||||
|
||||
|
||||
def get_target_platform_for_envs():
|
||||
"""Get target platform for environments"""
|
||||
system = os.environ.get('INSPIRE_FACE_TARGET_PLATFORM')
|
||||
if system is None:
|
||||
system = get_lib_path_info()[0]
|
||||
|
||||
machine = os.environ.get('INSPIRE_FACE_TARGET_ARCH')
|
||||
if machine is None:
|
||||
machine = get_lib_path_info()[1]
|
||||
|
||||
return system, machine
|
||||
|
||||
# Get current platform information
|
||||
system, arch = get_lib_path_info()
|
||||
system, arch = get_target_platform_for_envs()
|
||||
print(f"Building for system: {system}, arch: {arch}")
|
||||
|
||||
# Build library file path relative to package
|
||||
lib_path = os.path.join('modules', 'core', 'libs', system, arch, '*')
|
||||
|
||||
Reference in New Issue
Block a user