mirror of
https://github.com/deepinsight/insightface.git
synced 2026-07-07 20:27:55 +00:00
Update inspireface to 1.2.0
This commit is contained in:
@@ -1,36 +1,34 @@
|
||||
import os
|
||||
import cv2
|
||||
import inspireface as ifac
|
||||
from inspireface.param import *
|
||||
import inspireface as isf
|
||||
import click
|
||||
|
||||
@click.command()
|
||||
@click.argument("resource_path")
|
||||
@click.argument('test_data_folder')
|
||||
def case_face_recognition(resource_path, test_data_folder):
|
||||
def case_face_recognition(test_data_folder):
|
||||
"""
|
||||
Launches the face recognition system, inserts face features into a database, and performs searches.
|
||||
Args:
|
||||
resource_path (str): Path to the resource directory for face recognition algorithms.
|
||||
test_data_folder (str): Path to the test data containing images for insertion and recognition tests.
|
||||
"""
|
||||
# Initialize the face recognition system with provided resources.
|
||||
ret = ifac.launch(resource_path)
|
||||
# If you need to switch from the default Pikachu model to another model like Megatron, you can use reload
|
||||
ret = isf.reload("Megatron")
|
||||
assert ret, "Launch failure. Please ensure the resource path is correct."
|
||||
|
||||
# Enable face recognition features.
|
||||
opt = HF_ENABLE_FACE_RECOGNITION
|
||||
session = ifac.InspireFaceSession(opt, HF_DETECT_MODE_ALWAYS_DETECT)
|
||||
opt = isf.HF_ENABLE_FACE_RECOGNITION
|
||||
session = isf.InspireFaceSession(opt, isf.HF_DETECT_MODE_ALWAYS_DETECT)
|
||||
|
||||
# Configure the feature management system.
|
||||
feature_hub_config = ifac.FeatureHubConfiguration(
|
||||
feature_block_num=10,
|
||||
enable_use_db=False,
|
||||
db_path="",
|
||||
feature_hub_config = isf.FeatureHubConfiguration(
|
||||
primary_key_mode=isf.HF_PK_AUTO_INCREMENT,
|
||||
enable_persistence=False,
|
||||
persistence_db_path="",
|
||||
search_threshold=0.48,
|
||||
search_mode=HF_SEARCH_MODE_EAGER,
|
||||
search_mode=isf.HF_SEARCH_MODE_EAGER,
|
||||
)
|
||||
ret = ifac.feature_hub_enable(feature_hub_config)
|
||||
ret = isf.feature_hub_enable(feature_hub_config)
|
||||
assert ret, "Failed to enable FeatureHub."
|
||||
|
||||
# Insert face features from 'bulk' directory.
|
||||
@@ -46,11 +44,11 @@ def case_face_recognition(resource_path, test_data_folder):
|
||||
if faces:
|
||||
face = faces[0] # Assume the most prominent face is what we want.
|
||||
feature = session.face_feature_extract(image, face)
|
||||
identity = ifac.FaceIdentity(feature, custom_id=idx, tag=name)
|
||||
ret = ifac.feature_hub_face_insert(identity)
|
||||
identity = isf.FaceIdentity(feature, id=idx)
|
||||
ret, alloc_id = isf.feature_hub_face_insert(identity)
|
||||
assert ret, "Failed to insert face."
|
||||
|
||||
count = ifac.feature_hub_get_face_count()
|
||||
count = isf.feature_hub_get_face_count()
|
||||
print(f"Number of faces inserted: {count}")
|
||||
|
||||
# Process faces from 'RD' directory and insert them.
|
||||
@@ -66,11 +64,11 @@ def case_face_recognition(resource_path, test_data_folder):
|
||||
if faces:
|
||||
face = faces[0]
|
||||
feature = session.face_feature_extract(image, face)
|
||||
identity = ifac.FaceIdentity(feature, custom_id=idx+count+1, tag=name)
|
||||
ret = ifac.feature_hub_face_insert(identity)
|
||||
identity = isf.FaceIdentity(feature, id=idx+count+1)
|
||||
ret, alloc_id = isf.feature_hub_face_insert(identity)
|
||||
assert ret, "Failed to insert face."
|
||||
|
||||
count = ifac.feature_hub_get_face_count()
|
||||
count = isf.feature_hub_get_face_count()
|
||||
print(f"Total number of faces after insertion: {count}")
|
||||
|
||||
# Search for a similar face using the last image in RD directory.
|
||||
@@ -81,18 +79,18 @@ def case_face_recognition(resource_path, test_data_folder):
|
||||
face = faces[0]
|
||||
feature = session.face_feature_extract(remain, face)
|
||||
|
||||
search = ifac.feature_hub_face_search(feature)
|
||||
if search.similar_identity.custom_id != -1:
|
||||
print(f"Found similar identity with ID: {search.similar_identity.custom_id}, Tag: {search.similar_identity.tag}, Confidence: {search.confidence:.2f}")
|
||||
search = isf.feature_hub_face_search(feature)
|
||||
if search.similar_identity.id != -1:
|
||||
print(f"Found similar identity with ID: {search.similar_identity.id}, Confidence: {search.confidence:.2f}")
|
||||
else:
|
||||
print("No similar identity found.")
|
||||
|
||||
# Display top-k similar face identities.
|
||||
print("Top-k similar identities:")
|
||||
search_top_k = ifac.feature_hub_face_search_top_k(feature, 10)
|
||||
for idx, (conf, custom_id) in enumerate(search_top_k):
|
||||
identity = ifac.feature_hub_get_face_identity(custom_id)
|
||||
print(f"Top-{idx + 1}: {identity.tag}, ID: {custom_id}, Confidence: {conf:.2f}")
|
||||
search_top_k = isf.feature_hub_face_search_top_k(feature, 10)
|
||||
for idx, (conf, _id) in enumerate(search_top_k):
|
||||
identity = isf.feature_hub_get_face_identity(_id)
|
||||
print(f"Top-{idx + 1}: ID: {_id}, Confidence: {conf:.2f}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user