Beispiel #1
0
    def __init__(self,
                 paths,
                 image_size,
                 root='.',
                 dtype=None,
                 transform_probability=0,
                 use_imgaug=True,
                 keep_aspect_ratio=False,
                 image_mode='RGB',
                 full_normalize=False,
                 resize_after_load=True):
        _check_pillow_availability()
        assert isinstance(paths,
                          six.string_types), "paths must be a file name!"
        assert os.path.splitext(paths)[
            -1] == ".json", "You have to supply gt information as json file!"

        if not isinstance(image_size, Size):
            image_size = Size(*image_size)

        with open(paths) as handle:
            self.gt_data = json.load(handle)

        self.root = root
        self.dtype = chainer.get_dtype(dtype)
        self.image_size = image_size
        self.transform_probability = transform_probability
        self.use_imgaug = use_imgaug
        self.keep_aspect_ratio = keep_aspect_ratio
        self.image_mode = image_mode
        self.augmentations = self.init_augmentations()
        self.full_normalize = full_normalize  # normalize each image to be in range of [0, 1] even if brightest pixel is != 255
        self.resize_after_load = resize_after_load  # resize the image to self.image_size after loading
    def __init__(self,
                 gt_file,
                 image_size,
                 root='.',
                 dtype=None,
                 transform_probability=0,
                 image_mode='L',
                 keep_aspect_ratio=False,
                 resize_after_load=True):
        _check_pillow_availability()
        assert isinstance(gt_file,
                          six.string_types), "paths must be a file name!"
        assert os.path.splitext(gt_file)[
            -1] == ".json", "You have to supply gt information as json file!"

        if not isinstance(image_size, Size):
            image_size = Size(*image_size)

        with open(gt_file) as handle:
            self.gt_data = json.load(handle)

        self.root = root
        self.dtype = chainer.get_dtype(dtype)
        self.image_size = image_size
        self.transform_probability = transform_probability
        self.keep_aspect_ratio = keep_aspect_ratio
        self.resize_after_load = resize_after_load
        self.image_mode = image_mode
        self.augmentations = self.init_augmentations()
Beispiel #3
0
    def __init__(self,
                 image_size,
                 npz_file=None,
                 memory_manager=None,
                 base_name=None,
                 root='.',
                 dtype=None,
                 transform_probability=0,
                 use_imgaug=True,
                 keep_aspect_ratio=False,
                 image_mode='RGB',
                 full_normalize=False,
                 resize_after_load=True):
        _check_pillow_availability()

        if not isinstance(image_size, Size):
            image_size = Size(*image_size)

        self.shared_buffers = []
        self.root = root
        self.dtype = chainer.get_dtype(dtype)
        self.image_size = image_size
        self.transform_probability = transform_probability
        self.use_imgaug = use_imgaug
        self.keep_aspect_ratio = keep_aspect_ratio
        self.image_mode = image_mode
        self.full_normalize = full_normalize  # normalize each image to be in range of [0, 1] even if brightest pixel is != 255
        self.resize_after_load = resize_after_load  # resize the image to self.image_size after loading

        if npz_file is not None:
            assert isinstance(npz_file,
                              six.string_types), "paths must be a file name!"
            assert os.path.splitext(npz_file)[
                -1] == ".npz", "You have to supply gt information as npz file!"

            with numpy.load(npz_file, allow_pickle=True) as gt_data:
                self.gt_data = self.copy_npz_data_to_ram(gt_data)
            self.memory_manager = None
            self.base_name = None
            self.length = len(self.gt_data['file_name'])
        else:
            assert memory_manager is not None, "If you do not specify an npz file, you must specify a memory manager!"
            assert base_name is not None, "If you want to use shared memory, you'll need to supply a base name for each dataset"
            self.gt_data = None
            self.memory_manager = memory_manager
            self.base_name = base_name
            self.length = self.memory_manager.get_shape(
                self.base_name, 'file_name').pop(0)

        self.augmentations = self.init_augmentations()