def data_generator(annotation_lines, batch_size, input_shape, anchors, num_classes, random=False): '''data generator for fit_generator''' n = len(annotation_lines) i = 0 while True: image_data = [] box_data = [] for b in range(batch_size): if i == 0: np.random.shuffle(annotation_lines) # box contains (x1,y1,x2,y2,class_label) image, box = get_random_data(annotation_lines[i], input_shape, random=random) image_data.append(image) box_data.append(box) i = (i + 1) % n image_data = np.array(image_data) # Collects boxes for a whole batch box_data = np.array(box_data) # box needs to be converted to model output format # y_true shape = (batch_size, 14, 14, 3, 55) for first detection layer # y_true is an array of true_outputs of 3 detection layers y_true = preprocess_true_boxes(box_data, input_shape, anchors, num_classes) yield [image_data, *y_true], np.zeros(batch_size)
def data_generator(annotation_lines, batch_size, input_shape, anchors, num_classes): """ Data generator for fit_generator function :param annotation_lines: :param batch_size: :param input_shape: :param anchors: :param num_classes: :return: """ n = len(annotation_lines) i = 0 while True: image_data = [] box_data = [] for b in range(batch_size): if i == 0: np.random.shuffle(annotation_lines) image, box = get_random_data(annotation_lines[i], input_shape, random=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 = preprocess_true_boxes(box_data, input_shape, anchors, num_classes) yield [image_data, *y_true], np.zeros(batch_size)
def bottleneck_generator(annotation_lines, batch_size, input_shape, anchors, num_classes, bottlenecks): n = len(annotation_lines) i = 0 while True: box_data = [] b0=np.zeros((batch_size,bottlenecks[0].shape[1],bottlenecks[0].shape[2],bottlenecks[0].shape[3])) b1=np.zeros((batch_size,bottlenecks[1].shape[1],bottlenecks[1].shape[2],bottlenecks[1].shape[3])) b2=np.zeros((batch_size,bottlenecks[2].shape[1],bottlenecks[2].shape[2],bottlenecks[2].shape[3])) for b in range(batch_size): _, box = get_random_data(annotation_lines[i], input_shape, random=False, proc_img=False) box_data.append(box) b0[b]=bottlenecks[0][i] b1[b]=bottlenecks[1][i] b2[b]=bottlenecks[2][i] i = (i+1) % n box_data = np.array(box_data) y_true = preprocess_true_boxes(box_data, input_shape, anchors, num_classes) yield [b0, b1, b2, *y_true], np.zeros(batch_size)
def data_generator(annotation_lines, batch_size, input_shape, anchors, num_classes, random=True, verbose=False): '''data generator for fit_generator''' n = len(annotation_lines) i = 0 while True: image_data = [] box_data = [] for b in range(batch_size): if i==0 and random: np.random.shuffle(annotation_lines) image, box = get_random_data(annotation_lines[i], input_shape, random=random) image_data.append(image) box_data.append(box) i = (i+1) % n image_data = np.array(image_data) if verbose: print("Progress: ",i,"/",n) box_data = np.array(box_data) y_true = preprocess_true_boxes(box_data, input_shape, anchors, num_classes) yield [image_data, *y_true], np.zeros(batch_size)
def data_generator(annotation, batch_size, input_shape, anchors, n_classes): '''data generator for fit_generator''' n = len(annotation) i = 0 while True: image_data = [] box_data = [] for b in range(batch_size): if i == 0: np.random.shuffle(annotation) image, box = get_random_data(annotation[i], input_shape, random=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 = preprocess_true_boxes(box_data, input_shape, anchors, n_classes) yield [image_data, *y_true], np.zeros(batch_size) # produce a sequence of values