def execute():
    mode = 'train'

    path_to_json_file = 'dataset/All/' + mode + '/All_' + mode + '.json'
    print(path_to_json_file)
    with open(path_to_json_file) as json_file:
        data = json.load(json_file)
    keys = list(data.keys())
    key = keys[0]
    for key in keys:
        ground_truth = {}

        fname = re.search(r'^([^.]+)', data[key]['filename']).group(0)
        print(fname + " is handled!")
        regions = data[key]['regions']
        for region in regions:
            ground_truth[region['region_attributes']
                         ['class']] = region['shape_attributes']

        image_path = 'dataset/All/' + mode + '/' + fname + '.jpg'
        print(image_path)
        image = cv2.imread(image_path)
        fname = os.path.basename(image_path)
        fnameWithoutExt = os.path.splitext(fname)[0]

        path_for_calculate_map = current_path + "/mAP-master/input/detection-results/" + fnameWithoutExt + ".txt"
        path_for_result_detection_net = current_path + "/mAP-master/data/predicted/" + fnameWithoutExt + ".txt"

        detects, recogns, aligns, time = adapter.recognize_faces(
            image, path_for_calculate_map, path_for_result_detection_net,
            ground_truth)
        cv2.imwrite('recognitions/' + fname + '.jpg', recogns)
    path_images_in_dir = []
    p = path_to_dataset + name + "/" + mode + "/"
    for r, d, f in os.walk(p):
        for file in f:
            if '.jpg' in file:
                path_images_in_dir.append(os.path.join(r, file))

    for image_path in path_images_in_dir:
        image = cv2.imread(image_path)
        fname = os.path.basename(image_path)
        fnameWithoutExt = os.path.splitext(fname)[0]

        path_for_calculate_map = current_path + "/mAP-master/input/detection-results/" + fnameWithoutExt + ".txt"
        path_for_result_detection_net = current_path + "/mAP-master/data/predicted/" + fnameWithoutExt + ".txt"
        print(image_path)
        detects, recogns, aligns, time = adapter.recognize_faces(
            image, path_for_calculate_map, path_for_result_detection_net, None)

#write ground-truth files
for name in name_dir:
    path_to_json_file = path_to_dataset + name + '/' + mode + '/' + name + '_' + mode + '.json'
    print(path_to_json_file)
    if (name != "Ion" or (name == "Ion" and mode == "train")):
        with open(path_to_json_file) as json_file:
            data = json.load(json_file)
        keys = list(data.keys())
        key = keys[0]
        for key in keys:
            fname = re.search(r'^([^.]+)', data[key]['filename']).group(0)
            final_fname_map = path_to_save_for_mAP + fname + '.txt'
            f_map = open(final_fname_map, "w")
            final_fname_other = path_to_save_for_other + fname + '.txt'