예제 #1
0
    def build_batch(self, data_dir):
        """ Build batch images and. """

        print("Building batch images for %s..." % self.batch_dir)
        filenames = util.get_files_in_directory(data_dir)
        images_count = 0

        util.make_dir(self.batch_dir)
        util.clean_dir(self.batch_dir)
        util.make_dir(self.batch_dir + "/" + INPUT_IMAGE_DIR)
        util.make_dir(self.batch_dir + "/" + INTERPOLATED_IMAGE_DIR)
        util.make_dir(self.batch_dir + "/" + TRUE_IMAGE_DIR)

        processed_images = 0
        for filename in filenames:
            output_window_size = self.batch_image_size * self.scale
            output_window_stride = self.stride * self.scale

            input_image, input_interpolated_image, true_image = \
                build_image_set(filename, channels=self.channels, resampling_method=self.resampling_method,
                                scale=self.scale, print_console=False)

            # split into batch images
            input_batch_images = util.get_split_images(input_image, self.batch_image_size, stride=self.stride)
            input_interpolated_batch_images = util.get_split_images(input_interpolated_image, output_window_size,
                                                                    stride=output_window_stride)

            if input_batch_images is None or input_interpolated_batch_images is None:
                # if the original image size * scale is less than batch image size
                continue
            input_count = input_batch_images.shape[0]

            true_batch_images = util.get_split_images(true_image, output_window_size, stride=output_window_stride)

            for i in range(input_count):
                self.save_input_batch_image(images_count, input_batch_images[i])
                self.save_interpolated_batch_image(images_count, input_interpolated_batch_images[i])
                self.save_true_batch_image(images_count, true_batch_images[i])
                images_count += 1
            processed_images += 1
            if processed_images % 10 == 0:
                print('.', end='', flush=True)

        print("Finished")
        self.count = images_count

        print("%d mini-batch images are built(saved)." % images_count)

        config = configparser.ConfigParser()
        config.add_section("batch")
        config.set("batch", "count", str(images_count))
        config.set("batch", "scale", str(self.scale))
        config.set("batch", "batch_image_size", str(self.batch_image_size))
        config.set("batch", "stride", str(self.stride))
        config.set("batch", "channels", str(self.channels))

        with open(self.batch_dir + "/batch_images.ini", "w") as configfile:
            config.write(configfile)
예제 #2
0
	def build_batch(self, data_dir, batch_dir):
		""" load from input files. Then save batch images on file to reduce memory consumption. """

		print("Building batch images for %s..." % batch_dir)
		filenames = util.get_files_in_directory(data_dir)
		images_count = 0

		util.make_dir(batch_dir)
		util.clean_dir(batch_dir)
		util.make_dir(batch_dir + "/" + INPUT_IMAGE_DIR)
		util.make_dir(batch_dir + "/" + INTERPOLATED_IMAGE_DIR)
		util.make_dir(batch_dir + "/" + TRUE_IMAGE_DIR)

		for filename in filenames:
			output_window_size = self.batch_image_size * self.scale
			output_window_stride = self.stride * self.scale

			input_image, input_interpolated_image = self.input.load_input_image(filename, rescale=True,
			                                                                    resampling_method=self.resampling_method)
			test_image = self.true.load_test_image(filename)

			# split into batch images
			input_batch_images = util.get_split_images(input_image, self.batch_image_size, stride=self.stride)
			input_interpolated_batch_images = util.get_split_images(input_interpolated_image, output_window_size,
			                                                        stride=output_window_stride)
			if input_batch_images is None or input_interpolated_batch_images is None:
				continue
			input_count = input_batch_images.shape[0]

			test_batch_images = util.get_split_images(test_image, output_window_size, stride=output_window_stride)

			for i in range(input_count):
				save_input_batch_image(batch_dir, images_count, input_batch_images[i])
				save_interpolated_batch_image(batch_dir, images_count, input_interpolated_batch_images[i])
				save_true_batch_image(batch_dir, images_count, test_batch_images[i])
				images_count += 1

		print("%d mini-batch images are built(saved)." % images_count)

		config = configparser.ConfigParser()
		config.add_section("batch")
		config.set("batch", "count", str(images_count))
		config.set("batch", "scale", str(self.scale))
		config.set("batch", "batch_image_size", str(self.batch_image_size))
		config.set("batch", "stride", str(self.stride))
		config.set("batch", "channels", str(self.channels))
		config.set("batch", "jpeg_mode", str(self.jpeg_mode))
		config.set("batch", "max_value", str(self.max_value))

		with open(batch_dir + "/batch_images.ini", "w") as configfile:
			config.write(configfile)
예제 #3
0
def build_batch(data_dir, thread, threads):
    """ Build batch images and. """

    filenames = util.get_files_in_directory(data_dir)
    images_count = 0
    processed_images = int(len(filenames)/threads*(thread))
    for filename in filenames[int(len(filenames)/threads*thread):int(len(filenames)/threads*(thread+1))]:
        output_window_size = BatchDataSets.batch_image_size * BatchDataSets.scale
        output_window_stride = BatchDataSets.stride * BatchDataSets.scale

        input_image, input_interpolated_image, true_image = \
            build_image_set(filename, channels=BatchDataSets.channels, resampling_method=BatchDataSets.resampling_method,
                            scale=BatchDataSets.scale, print_console=False)

        # split into batch images
        input_batch_images = util.get_split_images(input_image, BatchDataSets.batch_image_size, stride=BatchDataSets.stride)
        input_interpolated_batch_images = util.get_split_images(input_interpolated_image, output_window_size,
                                                                stride=output_window_stride)

        if input_batch_images is None or input_interpolated_batch_images is None:
            # if the original image size * scale is less than batch image size
            continue
        input_count = input_batch_images.shape[0]

        true_batch_images = util.get_split_images(true_image, output_window_size, stride=output_window_stride)

        for i in range(input_count):
            BatchDataSets.save_input_batch_image(thread*1000000+images_count, input_batch_images[i])
            BatchDataSets.save_interpolated_batch_image(thread*1000000+images_count, input_interpolated_batch_images[i])
            BatchDataSets.save_true_batch_image(thread*1000000+images_count, true_batch_images[i])
            images_count += 1
        processed_images += 1
        if processed_images % 10 == 0:
            print('.', end='', flush=True)

    print("Finished")
    BatchDataSets.count = images_count

    print("%d mini-batch images are built(saved)." % images_count)

    config = configparser.ConfigParser()
    config.add_section("batch")
    config.set("batch", "count", str(images_count))
    config.set("batch", "scale", str(BatchDataSets.scale))
    config.set("batch", "batch_image_size", str(BatchDataSets.batch_image_size))
    config.set("batch", "stride", str(BatchDataSets.stride))
    config.set("batch", "channels", str(BatchDataSets.channels))

    with open(BatchDataSets.batch_dir + "/batch_images.ini", "w") as configfile:
        config.write(configfile)