简体   繁体   中英

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

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

i am using flask framework

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

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)

1- use slash instead of backslash

2- 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 string. if you set 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])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM