def train_arcface_model(face_detector, config, dataset_folder,
                        embedding_folder):
    objs = []
    register_image_bbox_objs = []
    registered_ids = []

    for folder in os.listdir(dataset_folder):
        if not folder.endswith('.txt'):
            for face in os.listdir(f"{dataset_folder}/{folder}"):
                raw_image_path = f"{dataset_folder}/{folder}/{face}"
                train_image_id = ImageId(channel='train_img',
                                         timestamp=arrow.now().timestamp,
                                         file_format=os.path.splitext(face)[1])
                train_image_obj = Image(train_image_id,
                                        raw_image_path=raw_image_path)

                try:
                    face_detection_result = face_detector.detect(
                        train_image_obj, label=folder)
                    if len(face_detection_result.detected_objects) == 1:
                        register_image_bbox_objs.append(
                            face_detection_result.detected_objects[0])
                        registered_ids.append(
                            face_detection_result.detected_objects[0].label)
                        objs += train_image_obj.fetch_bbox_pil_objs(
                            register_image_bbox_objs)
                except:
                    print(
                        f"[ERROR] An error occured with the face detector model. Can't open the photo {dataset_folder}/{folder}/{face}"
                    )
                register_image_bbox_objs = []

    objects_frame = resize_and_stack_image_objs((112, 112), objs)
    print("Object_frame shape:", objects_frame.shape)

    objects_frame = np.transpose(objects_frame, (0, 3, 1, 2))
    with SimpleTimer("[INFO] Extracting embedding for our dataset"):
        arcface_classifier = ArcFaceClassifier(config,
                                               registered_ids,
                                               objects_frame=objects_frame)

    embedding_path = f"{embedding_folder}/faces.pkl"
    print(f"[INFO] Store face embedding to {embedding_path}")
    arcface_classifier.store_embedding_info(embedding_path)

    ids_path = f"{embedding_folder}/registered_ids.txt"
    print(f"[INFO] Store registered ids to {ids_path}")
    with open(ids_path, 'w') as filehandle:
        for registered_id in registered_ids:
            filehandle.write('%s\n' % registered_id)

    return arcface_classifier
                         y2=1007,
                         label='Zoe',
                         score=1,
                         meta=''),
        #BoundedBoxObject(x1=946, y1=551, x2=1149, y2=784, label='Amine', score=1, meta=''),
        BoundedBoxObject(x1=1364,
                         y1=564,
                         x2=1492,
                         y2=720,
                         label='Lu',
                         score=1,
                         meta='')
        #BoundedBoxObject(x1=2286, y1=1272, x2=2629, y2=1738, label='Hedi', score=1, meta='')
    ]

    objs = train_image_obj.fetch_bbox_pil_objs(register_image_bbox_objs)
    objects_frame = resize_and_stack_image_objs((112, 112), objs)
    objects_frame = np.transpose(objects_frame, (0, 3, 1, 2))
    registered_ids = [i.label for i in register_image_bbox_objs]

    # Création du classifier et réentrainement
    model_name = 'Arcface'
    with SimpleTimer("Loading model %s" % model_name):
        arcface_classifier = ArcFaceClassifier(registered_ids,
                                               objects_frame=objects_frame)

    # Test de reconnaissance
    raw_image_path = 'demo/183club/test_imag2.jpg'
    test_image_id = ImageId(channel='demo',
                            timestamp=arrow.now().timestamp,
                            file_format='jpg')