def __init__( self, transform_generator=None, batch_size=1, group_method='ratio', # one of 'none', 'random', 'ratio' shuffle_groups=True, image_min_side=800, image_max_side=1333, transform_parameters=None, compute_shapes=guess_shapes, compute_anchor_targets=anchor_targets_bbox, config=None): self.transform_generator = transform_generator self.batch_size = int(batch_size) self.group_method = group_method self.shuffle_groups = shuffle_groups self.image_min_side = image_min_side self.image_max_side = image_max_side self.transform_parameters = transform_parameters or TransformParameters( ) self.compute_shapes = compute_shapes self.compute_anchor_targets = compute_anchor_targets self.config = config # Define groups self.group_images() # Shuffle when initializing if self.shuffle_groups: self.on_epoch_end()
def __init__( self, transform_generator=None, batch_size=1, group_method='ratio', # one of 'none', 'random', 'ratio' shuffle_groups=True, image_min_side=800, image_max_side=1333, transform_parameters=None, compute_shapes=guess_shapes, compute_anchor_targets=anchor_targets_bbox, config=None): self.transform_generator = transform_generator self.batch_size = int(batch_size) self.group_method = group_method self.shuffle_groups = shuffle_groups self.image_min_side = image_min_side self.image_max_side = image_max_side self.transform_parameters = transform_parameters or TransformParameters( ) self.compute_shapes = compute_shapes self.compute_anchor_targets = compute_anchor_targets self.config = config self.group_index = 0 self.lock = threading.Lock() self.group_images()
def __init__(self, csv_data_file, csv_class_file, base_dir=None, transform_generator=None, batch_size=2, group_method='none', # one of 'none', 'random', 'ratio' shuffle_groups=True, image_min_side=480, image_max_side=640, transform_parameters=None, compute_anchor_targets=anchor_targets_bbox, compute_shapes=guess_shapes, preprocess_image=preprocess_image, config=None ): """ Initialize a CSV data generator. Args for csv csv_data_file: Path to the CSV annotations file. csv_class_file: Path to the CSV classes file. base_dir: Directory w.r.t. where the files are to be searched (defaults to the directory containing the csv_data_file). Args for generator transform_generator : A generator used to randomly transform images and annotations. batch_size : The size of the batches to generate. group_method : Determines how images are grouped together (defaults to 'ratio', one of ('none', 'random', 'ratio')). shuffle_groups : If True, shuffles the groups each epoch. image_min_side : After resizing the minimum side of an image is equal to image_min_side. image_max_side : If after resizing the maximum side is larger than image_max_side, scales down further so that the max side is equal to image_max_side. transform_parameters : The transform parameters used for data augmentation. compute_anchor_targets : Function handler for computing the targets of anchors for an image and its annotations. compute_shapes : Function handler for computing the shapes of the pyramid for a given input. preprocess_image : Function handler for preprocessing an image (scaling / normalizing) for passing through a network. """ self.image_names = [] self.image_data = {} self.base_dir = base_dir self.layout_2_group_table = {} # take base_dir from annotations file if not explicitly specified. if self.base_dir is None: self.base_dir = os.path.dirname(csv_data_file) # parse the provided class file try: with _open_for_csv(csv_class_file) as file: self.classes = _read_classes(csv.reader(file, delimiter=',')) except ValueError as e: raise_from(ValueError('invalid CSV class file: {}: {}'.format(csv_class_file, e)), None) self.labels = {} for key, value in self.classes.items(): self.labels[value] = key # csv with img_path, x1, y1, x2, y2, class_name try: with _open_for_csv(csv_data_file) as file: self.image_data = _read_annotations(csv.reader(file, delimiter=','), self.classes) except ValueError as e: raise_from(ValueError('invalid CSV annotations file: {}: {}'.format(csv_data_file, e)), None) self.image_names = list(self.image_data.keys()) self.transform_generator = transform_generator self.batch_size = int(batch_size) self.group_method = group_method self.shuffle_groups = shuffle_groups self.image_min_side = image_min_side self.image_max_side = image_max_side self.transform_parameters = transform_parameters or TransformParameters() self.compute_anchor_targets = compute_anchor_targets self.compute_shapes = compute_shapes self.preprocess_image = preprocess_image if config is not None: self.config = read_config_file(config) else: self.config = None self.group_index = 0 self.lock = threading.Lock() self.group_images() self.layout_lookup()
from keras_retinanet.utils.transform import random_transform from keras_retinanet.utils.image import apply_transform, TransformParameters, adjust_transform_for_image, read_image_bgr from matplotlib.image import imsave if __name__ == "__main__": img = read_image_bgr('./TestFile/foo.jpg') transform = random_transform(flip_x_chance=1, flip_y_chance=0) print(transform) transform_parameters = TransformParameters() transform = adjust_transform_for_image( transform, img, transform_parameters.relative_translation) img_transformed = apply_transform(transform, img, transform_parameters) imsave('./TestFile/foo_transformed.jpg', img_transformed) exit(0)