как правильно сохранить словарь в многопроцессорном пуле - PullRequest
0 голосов
/ 20 апреля 2020

Я пытаюсь распараллелить функцию в python, для этого мне нужно закодировать некоторые лица, а затем сохранить текст, я понимаю, что когда я пробую свой код, он сохранил только последнюю часть данных, которые его обрабатывают, здесь это код

train_dir = "/home/workstation/Desktop/fv/api/"
names = [l for l in os.listdir(train_dir)]
def functionist(name_list):
    X = []
    y = []
    verbose = True
    # Loop through each person in the training set
    for class_dir in name_list:

        # Loop through each training image for the current person
        for img_path in image_files_in_folder(os.path.join(train_dir, class_dir)):
            image = face_recognition.load_image_file(img_path)
            face_bounding_boxes = face_recognition.face_locations(image)

            if len(face_bounding_boxes) != 1:
                # If there are no people (or too many people) in a training image, skip the image.
                if verbose:
                    print("Image {} not suitable for training: {}".format(img_path, "Didn't find a face" if len(face_bounding_boxes) < 1 else "Found more than one face"), end="\r")
            else:
                # Add face encoding for current image to the training set
                X.append(face_recognition.face_encodings(image, known_face_locations=face_bounding_boxes)[0])
                y.append(class_dir)

    dictionary = dict(zip(y, X))
    with open('dataset_faces.dat', 'wb') as f:
        pickle.dump(dictionary, f)
    return dictionary

cores = mp.cpu_count()
df_split = np.array_split(names, cores, axis=0)
pool = Pool(cores)
df_out = np.vstack(pool.map(functionist, df_split))
pool.close()
pool.join()
pool.clear()

Надеюсь, вы поможете мне понять, как я могу сохранить его в словаре кодировок лиц? Большое спасибо за чтение

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...