sadmiaw
sadmiaw

Reputation: 1

Arcface model can't be loaded

i'm working on face recognition system where i used arcface as its algortihm, and i download the arcface model from github in this link https://github.com/Martlgap/livefaceidapp/blob/main/model.onnx%5C. But i encountered this error:

ERROR:root:An error occurred: A KerasTensor cannot be used as input to a 
TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, 
used when constructing Keras Functional models or Keras Functions. You can only 
use it as input to a Keras layer or a Keras operation (from the namespaces 
`keras.layers` and `keras.operations`). You are likely doing something like:


    x = Input(...)
    ...
    tf_fn(x)  # Invalid.



What you should do instead is wrap `tf_fn` in a layer:



    class MyLayer(Layer):
        def call(self, x):
            return tf_fn(x)
    
    x = MyLayer()(x)

i already ask the ai or gpt about this problem and it says about the compability of tensorflow libraries but when i see the requirements on that github, there is no specific version of the tensorflow needed. i also already check if the model works on the new py file and it works perfectly fine, and i use the model.onnx to generate embeddings and it works perfectly fine too.

What's happening on my face recognition script and how to resolve it?

incase you guys want to see how i initialize the arcface model, here it is

import cv2
import os
import time
import logging
import numpy as np
import pandas as pd
from tkinter import font as tkFont
from PIL import Image, ImageTk
import torch
from arcface import ArcFace 
import psycopg2
import datetime
import face_alignment 
import onnxruntime
from retinaface import RetinaFace

# ArcFace model
arcface_model = onnxruntime.InferenceSession(r"RetinaFace_ArcFace\model.onnx")

DATABASE_CONFIG = {
    'database': 'postgres',  
    'user': 'postgres',       
    'password': 'root', 
    'host': 'localhost',           
    'port': 5432                  
}

class Face_Recognizer:
    def __init__(self):
        self.font = cv2.FONT_HERSHEY_SIMPLEX
        # FPS
        self.frame_time = 0
        self.frame_start_time = 0
        self.fps = 0
        self.fps_show = 0
        self.start_time = time.time()
    
        # cnt for frame
        self.frame_cnt = 0
    
        #  Save the features of faces in the database
        self.face_features_known_list = []
        # / Save the name of faces in the database
        self.face_name_known_list = []
    
        #  List to save centroid positions of ROI in frame N-1 and N
        self.last_frame_face_centroid_list = None
        self.current_frame_face_centroid_list = None
    
        # List to save names of objects in frame N-1 and N
        self.last_frame_face_name_list = [None]
        self.current_frame_face_name_list = None
    
        #  cnt for faces in frame N-1 and N
        self.last_frame_face_cnt = 0
        self.current_frame_face_cnt = 0
    
        # Save the e-distance for faceX when recognizing
        self.current_frame_face_X_e_distance_list = []
    
        # Save the positions and names of current faces captured
        self.current_frame_face_position_list = []
        #  Save the features of people in current frame
        self.current_frame_face_feature_list = []
    
        # e distance between centroid of ROI in last and current frame
        self.last_current_frame_centroid_e_distance = 0
    
        #  Reclassify after 'reclassify_interval' frames
        self.reclassify_interval_cnt = 0
        self.reclassify_interval = 10
    
         # Bounding Box Persistence
        self.bbox_history = {} 
        self.bbox_persistence_frames = 12
        
        # Connnect to database
        self.connect_to_db()
    
    def get_face_database(self):
        if os.path.exists("data/features_arcface.csv"):
            path_features_known_csv = "data/features_arcface.csv"
            csv_rd = pd.read_csv(path_features_known_csv, header=None)
            for i in range(csv_rd.shape[0]):
                features_someone_arr = []
                self.face_name_known_list.append(csv_rd.iloc[i][0])
                for j in range(1, 513):
                    features_someone_arr.append(float(csv_rd.iloc[i][j]))
                self.face_features_known_list.append(features_someone_arr)
            logging.info("Faces in Database: %d", len(self.face_features_known_list))
            return 1
        else:
            logging.warning("'features_arcface.csv' not found!")
            logging.warning("Run the code to generate face features first!")
            return 0

Upvotes: 0

Views: 91

Answers (0)

Related Questions