Ubong Essien
Ubong Essien

Reputation: 1

OSError: [Errno 22] Invalid argument in deepface used in flask

I am building a face recognition system using the deepface framework and I got the below error I don't seem to know what I did wrong deepface is supposed to create a .pkl file with facial embeddings for images in my face database but it fails and returns this error:

File "C:\Users\UBONG\face_recog_project\venv\lib\site-packages\deepface\DeepFace.py", line 594, in find
    f = open(db_path+'/'+file_name, "wb")
OSError: [Errno 22] Invalid argument: 'C:\\Users\\UBONG\\face_recog_project\\facedb/representations_<keras.engine.functional.functional object at 0x00000210cf89c790>.pkl'
def mark_attendnace(class_folder,db_path):
    models = ["VGG-Face", "Facenet", "Facenet512", "OpenFace", "DeepFace", "DeepID", "ArcFace", "Dlib"]
    backends = ['opencv', 'ssd', 'dlib', 'mtcnn', 'retinaface', 'mediapipe']
    metrics = ["cosine", "euclidean", "euclidean_l2"]
    
   # access_type=1 #2=local,1=web    
  
  
    face_req_model = DeepFace.build_model(models[1])
   
    
    #declare the parent folder
    parent_dir = "C:/Users/UBONG/face_recog_project/class_assets/"
    
            
   
    c_folder = os.path.join(parent_dir, class_folder)
    detected_directory = c_folder + '\\detected' + "_" + class_folder + "\\"

    school_details = get_school_details()
    cur_session = school_details[1]
    cur_semester = school_details[2]
    
    #create a detected file imafge array 
    detected_list = []
    for detected_filename in os.listdir(detected_directory):
        #print(detected_filename)
        if detected_filename.endswith(".jpg"):
            detected_list.append(detected_directory + detected_filename)
        # print(detected_filename)

        else:
            print("Wrong file type")

    df = DeepFace.find(detected_list, db_path, model_name = face_req_model,model=face_req_model,enforce_detection=False,detector_backend = backends[3],distance_metric = metrics[0])
    print(df)
    x=0
    y=0
    for x in range(len(df)):
        
        for y in df[x]['identity']:
            file = ntpath.basename(y)
            filename,ext = os.path.splitext(file)
            file_name = filename.split("-")
            #print(file_name)
            fname = file_name[0].replace("_","/")
            status = insert(fname,cur_session,cur_semester)
            #print(type(filename))

    return status

Also I am using the flask framework and this is where I am calling the function above:

@app.route("/start")
def start():
    db_path = os.path.join(sys.path[0]) + "\\facedb"
    at_st = mark_attendnace(active_folder,db_path)
    return render_template("startapp.html",at_st)

Upvotes: 0

Views: 403

Answers (1)

sefiks
sefiks

Reputation: 1650

1- Use slash(/) instead of backslash(\).

2- Do you have a <keras.engine.functional.functional object at 0x00000210cf89c790> term in the path? this is because you set model_name as an object instead of a string. if you set the model name argument as shown below, you will not have any trouble.

df = DeepFace.find(detected_list, db_path, model_name = models[1], enforce_detection=False, detector_backend = backends[3],distance_metric = metrics[0])

Upvotes: 1

Related Questions