コード例 #1
0
ファイル: prepare_data.py プロジェクト: Dok11/nn-dldm
    def set_examples(self):
        # List of (index root image, index target image, cross value)
        # where index is index of image in the self.images_dict
        self.examples = []

        for source in self.data_sources:
            print('Start set_examples from ' + source['code'])

            progress_bar = Progbar(len(source['surface_match_data']))

            for item in source['surface_match_data']:
                root_frame_num = str(item[1]).zfill(4)
                image_root_path = '\\' + source[
                    'code'] + '_images\\real\\scene-' + str(
                        item[0]) + '\\' + root_frame_num + '.jpg'
                image_root_index = self.images_dict_flip[image_root_path]

                target_frame_num = str(item[2]).zfill(4)
                image_target_path = '\\' + source[
                    'code'] + '_images\\real\\scene-' + str(
                        item[0]) + '\\' + target_frame_num + '.jpg'
                image_target_index = self.images_dict_flip[image_target_path]

                self.examples.append(
                    (image_root_index, image_target_index, item[3]))
                progress_bar.add(1)
コード例 #2
0
ファイル: prepare_data.py プロジェクト: Dok11/nn-dldm
    def save_img(self):
        progress_bar = Progbar(len(self.images_np_arr))

        for i in range(len(self.images_np_arr)):
            image = self.images_np_arr[i].astype('float32') / 255.
            file = os.path.join(self.train_dir, 'images', str(i))
            save_img(file + '.png', image)

            if i % 100 == 0:
                progress_bar.add(100)
コード例 #3
0
ファイル: prepare_data.py プロジェクト: Dok11/nn-dldm
    def set_grouped_examples(self):
        self.grouped_examples = [[] for i in range(GROUP_COUNT)]

        progress_bar = Progbar(len(self.examples))

        for example in self.examples:
            example_value = example[2]
            group = round(example_value * (GROUP_COUNT - 1))
            self.grouped_examples[group].append(example)
            progress_bar.add(1)
コード例 #4
0
    def calc_values_for_images(self):
        print('Run calc_values_for_images()')
        counter = 0

        remain_images_to_calc = []

        for image_file in self.image_files:
            image_file_data = (image_file['scene'], image_file['root'],
                               image_file['frame'])
            if self.is_image_calculated(image_file_data):
                continue

            remain_images_to_calc.append(image_file)

        print('remain images to calc: ' + str(len(remain_images_to_calc)))

        # Progress bar for remain items to calculate
        progress_bar = Progbar(len(remain_images_to_calc))

        for image_file in remain_images_to_calc:
            img = Image.open(image_file['path'])
            img.thumbnail((16, 16))
            value = np.array(img).mean() / 255

            self.data.append((
                image_file['scene'],
                image_file['root'],
                image_file['frame'],
                round(value, 4),
            ))

            counter += 1

            if counter % 5000 == 0:
                progress_bar.add(5000)

            if counter % 1000000 == 0 and counter > 0:
                print('\nSave file partial with new records ' + str(counter))
                self.save_data()

        # Save data to json
        print('\nSave file complete with new records ' + str(counter))
        self.save_data()
コード例 #5
0
                int(indexes[index][0]),
                int(indexes[index][1]),
                delta
            ])

        if delta > save_images_error_threshold and save_images:
            r_val = 'r%.2f' % real_result
            p_val = 'p%.2f' % predicted_result

            root_name = str(batch) + '-' + str(index) + '-root_' + p_val + 'vs' + r_val + '.jpg'
            target_name = str(batch) + '-' + str(index) + '-target_' + p_val + 'vs' + r_val + '.jpg'

            save_img('bad_predictions/' + root_name, t_images_1[index])
            save_img('bad_predictions/' + target_name, t_images_2[index])

    if batch % 5 == 0 and batch > 0:
        progress_bar.add(5)

    if batch % 20 == 0 and batch > 0:
        save_file(hard_indexes)

# Update weight complexity
batch_generator.load_example_weights()

for sample in samples:
    batch_generator.update_weights(sample[0], sample[1], sample[2])

batch_generator.save_example_weights()

save_file(hard_indexes)