Ejemplo n.º 1
0
    def get_questions_processed_path(self, dataset_name=None):

        if dataset_name is None:
            dataset_name = self.get_current_dataset()

        path = get_path(self.evaluation_type, dataset_name, 'questions_processed')

        return path
Ejemplo n.º 2
0
def main(starting_counter):
    test_args, test_exps = [], []

    path = get_path('validation', 'abstract_scenes_v1', 'questions')

    test_args.append([29994, 6, path])
    test_exps.append(6)

    test_args.append([29900, 32, path])
    test_exps.append(32)

    test_args.append([20000, 20, path])
    test_exps.append(20)

    tests_basis.create_tests([test_fn] * len(test_args), test_args, test_exps)

    return tests_basis.main_tester("Testing questions batch loading",
                                   starting_counter)
def main(starting_counter):
    test_args, test_exps = [], []

    path = get_path('validation', 'abstract_scenes_v1', 'annotations')

    question_ids = [275780, 275781, 275782, 255060, 255061, 255062]

    test_args.append([question_ids, path])
    test_exps.append(len(question_ids))

    test_args.append([question_ids[:1], path])
    test_exps.append(1)

    test_args.append([question_ids[:5], path])
    test_exps.append(5)

    tests_basis.create_tests([test_fn] * len(test_args), test_args, test_exps)
    return tests_basis.main_tester("Testing annotations batch loading",
                                   starting_counter)
def main(starting_counter):
    test_args, test_exps = [], []

    path = get_path('validation', 'abstract_scenes_v1', 'images')

    image_ids = [
        20000, 20001, 20002, 20003, 20004, 20005, 20006, 20007, 20008, 20009
    ]

    test_args.append([image_ids, path])
    test_exps.append(len(image_ids))

    test_args.append([image_ids[:1], path])
    test_exps.append(1)

    test_args.append([image_ids[:5], path])
    test_exps.append(5)

    tests_basis.create_tests([test_fn] * len(test_args), test_args, test_exps)
    return tests_basis.main_tester("Testing image batch loading",
                                   starting_counter)
def _get_all_directory_paths():
    images_directory_paths = []
    features_directory_paths = []

    images_directory_paths.append(
        data_path.get_path('training', 'balanced_real_images', 'images'))
    images_directory_paths.append(
        data_path.get_path('training', 'balanced_binary_abstract_scenes',
                           'images'))
    images_directory_paths.append(
        data_path.get_path('training', 'abstract_scenes_v1', 'images'))

    images_directory_paths.append(
        data_path.get_path('validation', 'balanced_real_images', 'images'))
    images_directory_paths.append(
        data_path.get_path('validation', 'balanced_binary_abstract_scenes',
                           'images'))
    images_directory_paths.append(
        data_path.get_path('validation', 'abstract_scenes_v1', 'images'))

    features_directory_paths.append(
        data_path.get_path('training', 'balanced_real_images',
                           'images_features'))
    features_directory_paths.append(
        data_path.get_path('training', 'balanced_binary_abstract_scenes',
                           'images_features'))
    features_directory_paths.append(
        data_path.get_path('training', 'abstract_scenes_v1',
                           'images_features'))

    features_directory_paths.append(
        data_path.get_path('validation', 'balanced_real_images',
                           'images_features'))
    features_directory_paths.append(
        data_path.get_path('validation', 'balanced_binary_abstract_scenes',
                           'images_features'))
    features_directory_paths.append(
        data_path.get_path('validation', 'abstract_scenes_v1',
                           'images_features'))

    return images_directory_paths, features_directory_paths
Ejemplo n.º 6
0
    def get_img_features_path(self, dataset_name=None):

        if dataset_name is None:
            dataset_name = self.get_current_dataset()

        return get_path(self.evaluation_type, dataset_name, 'images_features')
Ejemplo n.º 7
0
    def get_annotations_path(self, dataset_name=None):

        if dataset_name is None:
            dataset_name = self.get_current_dataset()

        return get_path(self.evaluation_type, dataset_name, 'annotations')
Ejemplo n.º 8
0
 def get_img_path(self):
     return get_path(self.evaluation_type, self.get_current_dataset(), 'images')
def get_top_answers_map():

    global TOP_ANSWERS_MAP, TOP_ANSWERS_LIST, CLASS_WEIGHT

    if os.path.exists(TOP_ANSWERS_PATH):

        with open(TOP_ANSWERS_PATH, 'rb') as fp:
            TOP_ANSWERS_MAP, TOP_ANSWERS_LIST, CLASS_WEIGHT = pickle.load(fp)

        return TOP_ANSWERS_MAP, TOP_ANSWERS_LIST, CLASS_WEIGHT

    top_answers_dict = {}

    # get_annotations()[1] will return a dictionary of question id and multiple choice answer for this question
    annotations_abstract_v1 = _get_annotations(
        get_path('training', 'abstract_scenes_v1', 'annotations'))[1]
    annotations_balanced_binary_abstract = _get_annotations(
        get_path('training', 'balanced_binary_abstract_scenes',
                 'annotations'))[1]
    annotations_balanced_real = _get_annotations(
        get_path('training', 'balanced_real_images', 'annotations'))[1]

    all_annotations = [
        annotations_abstract_v1, annotations_balanced_binary_abstract,
        annotations_balanced_real
    ]

    for annot_dict in all_annotations:
        for key, multiple_choice_answer in annot_dict.items():

            if multiple_choice_answer in top_answers_dict:
                top_answers_dict[multiple_choice_answer] += 1
            else:
                top_answers_dict[multiple_choice_answer] = 1

    # return 2 columns array sorted on the second column, the first column is the answer and the second column is the count
    sorted_top_answers = sorted(top_answers_dict.items(),
                                key=operator.itemgetter(1),
                                reverse=True)
    # return the first column of the sorted_top_answers, that are the words

    if TOP_ANSWERS_COUNT > len(sorted_top_answers):
        raise ValueError(
            "Top answers count is more than the number of answers !\n TOP_ANSWERS_COUNT = "
            + TOP_ANSWERS_COUNT)

    TOP_ANSWERS_LIST = ([
        row[0] for row in sorted_top_answers[:TOP_ANSWERS_COUNT]
    ])

    TOP_ANSWERS_MAP = {}

    for i in range(len(TOP_ANSWERS_LIST)):
        ans = TOP_ANSWERS_LIST[i]
        TOP_ANSWERS_MAP[ans] = i

    CLASS_WEIGHT = _calculate_class_weights(TOP_ANSWERS_LIST, top_answers_dict)

    # Write map and list to file
    with open(TOP_ANSWERS_PATH, 'wb') as fp:
        pickle.dump([TOP_ANSWERS_MAP, TOP_ANSWERS_LIST, CLASS_WEIGHT], fp)

    return TOP_ANSWERS_MAP, TOP_ANSWERS_LIST, CLASS_WEIGHT