def yolo3_data_generator(annotation_lines, batch_size, input_shape, anchors, num_classes, enhance_augment, rescale_interval, multi_anchor_assign): '''data generator for fit_generator''' n = len(annotation_lines) i = 0 # prepare multiscale config rescale_step = 0 input_shape_list = get_multiscale_list() while True: if rescale_interval > 0: # Do multi-scale training on different input shape rescale_step = (rescale_step + 1) % rescale_interval if rescale_step == 0: input_shape = input_shape_list[random.randint(0, len(input_shape_list)-1)] image_data = [] box_data = [] for b in range(batch_size): if i==0: np.random.shuffle(annotation_lines) image, box = get_ground_truth_data(annotation_lines[i], input_shape, augment=True) image_data.append(image) box_data.append(box) i = (i+1) % n image_data = np.array(image_data) box_data = np.array(box_data) if enhance_augment == 'mosaic': # add random mosaic augment on batch ground truth data image_data, box_data = random_mosaic_augment(image_data, box_data, prob=0.2) y_true = preprocess_true_boxes(box_data, input_shape, anchors, num_classes, multi_anchor_assign) yield [image_data, *y_true], np.zeros(batch_size)
def yolo2_data_generator(annotation_lines, batch_size, input_shape, anchors, num_classes, rescale_interval): '''data generator for fit_generator''' n = len(annotation_lines) i = 0 # prepare multiscale config rescale_step = 0 input_shape_list = get_multiscale_list() while True: if rescale_interval > 0: # Do multi-scale training on different input shape rescale_step = (rescale_step + 1) % rescale_interval if rescale_step == 0: input_shape = input_shape_list[random.randint(0,len(input_shape_list)-1)] image_data = [] box_data = [] for b in range(batch_size): if i==0: np.random.shuffle(annotation_lines) image, box = get_ground_truth_data(annotation_lines[i], input_shape, augment=True) image_data.append(image) box_data.append(box) i = (i+1) % n image_data = np.array(image_data) box_data = np.array(box_data) y_true_data = get_y_true_data(box_data, anchors, input_shape, num_classes) yield [image_data, y_true_data], np.zeros(batch_size)
def __init__(self, annotation_lines, batch_size, input_shape, anchors, num_classes, enhance_augment=None, rescale_interval=-1, shuffle=True): self.annotation_lines = annotation_lines self.batch_size = batch_size self.input_shape = input_shape self.anchors = anchors self.num_classes = num_classes self.enhance_augment = enhance_augment self.indexes = np.arange(len(self.annotation_lines)) self.shuffle = shuffle # prepare multiscale config # TODO: error happens when using Sequence data generator with # multiscale input shape, disable multiscale first if rescale_interval != -1: raise ValueError( "tf.keras.Sequence generator doesn't support multiscale input, pls remove related config" ) #self.rescale_interval = rescale_interval self.rescale_interval = -1 self.rescale_step = 0 self.input_shape_list = get_multiscale_list()
def __init__(self, annotation_lines, batch_size, input_shape, anchors, num_classes, rescale_interval=-1, shuffle=True): self.annotation_lines = annotation_lines self.batch_size = batch_size self.input_shape = input_shape self.anchors = anchors self.num_classes = num_classes self.indexes = np.arange(len(self.annotation_lines)) self.shuffle = shuffle # prepare multiscale config # TODO: error happens when using Sequence data generator with # multiscale input shape, disable multiscale first #self.rescale_interval = rescale_interval self.rescale_interval = -1 self.rescale_step = 0 self.input_shape_list = get_multiscale_list()