def load_idl_tf(idlfile, H, jitter): """Take the idlfile and net configuration and create a generator that outputs a jittered version of a random image from the annolist that is mean corrected.""" annolist = al.parse(idlfile) annos = [] for anno in annolist: anno.imageName = os.path.join( os.path.dirname(os.path.realpath(idlfile)), anno.imageName) annos.append(anno) random.seed(0) if H['data']['truncate_data']: annos = annos[:10] for epoch in itertools.count(): random.shuffle(annos) for origin_anno in annos: tiles = preprocess_image(deepcopy(origin_anno), H) for I, anno in tiles: if jitter: jitter_scale_min = 0.9 jitter_scale_max = 1.1 jitter_offset = 16 I, anno = annotation_jitter(I, anno, target_width=H["image_width"], target_height=H["image_height"], jitter_scale_min=jitter_scale_min, jitter_scale_max=jitter_scale_max, jitter_offset=jitter_offset) boxes, flags = annotation_to_h5(H, anno) yield {"image": I, "boxes": boxes, "flags": flags}
def _load_idl_tf(idlfile, hypes, jitter=False, random_shuffel=True): """Take the idlfile and net configuration and create a generator that outputs a jittered version of a random image from the annolist that is mean corrected.""" annolist = AnnoLib.parse(idlfile) annos = [] for anno in annolist: anno.imageName = os.path.join( os.path.dirname(os.path.realpath(idlfile)), anno.imageName) annos.append(anno) random.seed(0) if hypes['data']['truncate_data']: annos = annos[:10] for epoch in itertools.count(): if random_shuffel: random.shuffle(annos) for anno in annos: im = imread(anno.imageName) if im.shape[2] == 4: im = im[:, :, :3] if im.shape[0] != hypes["image_height"] or \ im.shape[1] != hypes["image_width"]: if epoch == 0: anno = _rescale_boxes(im.shape, anno, hypes["image_height"], hypes["image_width"]) im = imresize(im, (hypes["image_height"], hypes["image_width"]), interp='cubic') if jitter: jitter_scale_min = 0.9 jitter_scale_max = 1.1 jitter_offset = 16 im, anno = annotation_jitter( im, anno, target_width=hypes["image_width"], target_height=hypes["image_height"], jitter_scale_min=jitter_scale_min, jitter_scale_max=jitter_scale_max, jitter_offset=jitter_offset) boxes, flags = annotation_to_h5(hypes, anno, hypes["grid_width"], hypes["grid_height"], hypes["rnn_len"]) boxes = boxes.reshape( [hypes["grid_height"], hypes["grid_width"], 4]) flags = flags.reshape(hypes["grid_height"], hypes["grid_width"]) yield { "image": im, "boxes": boxes, "flags": flags, "rects": anno.rects, "anno": anno }
def load_idl_tf(idlfile, H, jitter): """Take the idlfile and net configuration and create a generator that outputs a jittered version of a random image from the annolist that is mean corrected.""" annolist = al.parse(idlfile) annos = [] for anno in annolist: anno.imageName = os.path.join( os.path.dirname(os.path.realpath(idlfile)), anno.imageName) annos.append(anno) random.seed(0) if H['data']['truncate_data']: annos = annos[:10] for epoch in itertools.count(): random.shuffle(annos) for anno in annos: I = imread(anno.imageName) #Skip Greyscale images if len(I.shape) < 3: continue if I.shape[2] == 4: I = I[:, :, :3] if I.shape[0] != H["image_height"] or I.shape[1] != H["image_width"]: if epoch == 0: anno = rescale_boxes(I.shape, anno, H["image_height"], H["image_width"]) I = imresize(I, (H["image_height"], H["image_width"]), interp='cubic') if jitter: jitter_scale_min=0.9 jitter_scale_max=1.1 jitter_offset=16 I, anno = annotation_jitter(I, anno, target_width=H["image_width"], target_height=H["image_height"], jitter_scale_min=jitter_scale_min, jitter_scale_max=jitter_scale_max, jitter_offset=jitter_offset) boxes, flags = annotation_to_h5(H, anno, H["grid_width"], H["grid_height"], H["rnn_len"]) yield {"image": I, "boxes": boxes, "flags": flags}
def _load_kitti_txt(kitti_txt, hypes, jitter=False, random_shuffel=True): """Take the txt file and net configuration and create a generator that outputs a jittered version of a random image from the annolist that is mean corrected.""" base_path = os.path.realpath(os.path.dirname(kitti_txt)) files = [line.rstrip() for line in open(kitti_txt)] if hypes['data']['truncate_data']: files = files[:10] random.seed(0) for epoch in itertools.count(): if random_shuffel: random.shuffle(files) for file in files: image_file, gt_image_file = file.split(" ") image_file = os.path.join(base_path, image_file) assert os.path.exists(image_file), \ "File does not exist: %s" % image_file gt_image_file = os.path.join(base_path, gt_image_file) assert os.path.exists(gt_image_file), \ "File does not exist: %s" % gt_image_file rect_list = read_kitti_anno(gt_image_file) anno = fake_anno(rect_list) im = scp.misc.imread(image_file) if im.shape[2] == 4: im = im[:, :, :3] if im.shape[0] != hypes["image_height"] or \ im.shape[1] != hypes["image_width"]: if epoch == 0: anno = _rescale_boxes(im.shape, anno, hypes["image_height"], hypes["image_width"]) im = imresize(im, (hypes["image_height"], hypes["image_width"]), interp='cubic') if jitter: jitter_scale_min = 0.9 jitter_scale_max = 1.1 jitter_offset = 16 im, anno = annotation_jitter( im, anno, target_width=hypes["image_width"], target_height=hypes["image_height"], jitter_scale_min=jitter_scale_min, jitter_scale_max=jitter_scale_max, jitter_offset=jitter_offset) pos_list = [rect for rect in anno.rects if rect.classID == 1] pos_anno = fake_anno(pos_list) boxes, confs = annotation_to_h5(hypes, pos_anno, hypes["grid_width"], hypes["grid_height"], hypes["rnn_len"]) mask_list = [rect for rect in anno.rects if rect.classID == -1] mask = _generate_mask(hypes, mask_list) boxes = boxes.reshape( [hypes["grid_height"], hypes["grid_width"], 4]) confs = confs.reshape(hypes["grid_height"], hypes["grid_width"]) yield { "image": im, "boxes": boxes, "confs": confs, "rects": pos_list, "mask": mask }
jitter_scale_max = 1.1 jitter_offset = 16 im, anno = annotation_jitter( im, anno, target_width=hypes["image_width"], target_height=hypes["image_height"], jitter_scale_min=jitter_scale_min, jitter_scale_max=jitter_scale_max, jitter_offset=jitter_offset) #if the rectangles are not the dont care, then iterate and get the list pos_list = [rect for rect in anno.rects if rect.classID == 1] pos_anno = fake_anno(pos_list) #annotate to hdf5 file boxes, confs = annotation_to_h5(hypes, pos_anno, hypes["grid_width"], hypes["grid_height"], hypes["rnn_len"]) #generate the mask mask_list = [rect for rect in anno.rects if rect.classID == -1] mask = _generate_mask(hypes, mask_list) #reshape the boxes boxes = boxes.reshape([hypes["grid_height"], hypes["grid_width"], 4]) confs = confs.reshape(hypes["grid_height"], hypes["grid_width"]) #output the result as object yield {"image": im, "boxes": boxes, "confs": confs, "rects": pos_list, "mask": mask}
def _load_daimler_txt(daimler_txt, hypes, jitter=False, random_shuffel=True): base_path = os.path.realpath(os.path.dirname(daimler_txt)) gt_image_path = 'labelData/train/tsinghuaDaimlerDataset' image_path = 'leftImg8bit/train/tsinghuaDaimlerDataset' files = [line.rstrip() for line in open(daimler_txt)] if hypes['data']['truncate_data']: files = files[:10] random.seed(0) for epoch in itertools.count(): if random_shuffel: random.shuffle(files) for file in files: image_file, gt_image_file = file.split(" ") #image_file = os.path.join(base_path, image_path , image_file) image_file = os.path.join(image_file) assert os.path.exists(image_file), \ "File does not exist: %s" % image_file gt_image_file = os.path.join(base_path, gt_image_path, gt_image_file) assert os.path.exists(gt_image_file), \ "File does not exist: %s" % gt_image_file rect_list = read_daimler_anno(gt_image_file, detect_truck=hypes['detect_truck']) anno = AnnoLib.Annotation() anno.rects = rect_list im = scipy.misc.imread(image_file) if im.shape[2] == 4: im = im[:, :, :3] if im.shape[0] != hypes["image_height"] or \ im.shape[1] != hypes["image_width"]: if True: anno = _rescale_boxes(im.shape, anno, hypes["image_height"], hypes["image_width"]) im = scipy.misc.imresize( im, (hypes["image_height"], hypes["image_width"]), interp='cubic') if jitter: jitter_scale_min = 0.9 jitter_scale_max = 1.1 jitter_offset = 16 im, anno = annotation_jitter( im, anno, target_width=hypes["image_width"], target_height=hypes["image_height"], jitter_scale_min=jitter_scale_min, jitter_scale_max=jitter_scale_max, jitter_offset=jitter_offset) pos_list = [rect for rect in anno.rects if rect.classID == 1] pos_anno = fake_anno(pos_list) boxes, confs = annotation_to_h5(hypes, pos_anno, hypes["grid_width"], hypes["grid_height"], hypes["rnn_len"]) mask_list = [rect for rect in anno.rects if rect.classID == -1] mask = _generate_mask(hypes, mask_list) boxes = boxes.reshape( [hypes["grid_height"], hypes["grid_width"], 4]) confs = confs.reshape(hypes["grid_height"], hypes["grid_width"]) yield { "image": im, "boxes": boxes, "confs": confs, "rects": pos_list, "mask": mask }
def _load_kitti_txt(kitti_txt, hypes, jitter=False, random_shuffel=True): """Take the txt file and net configuration and create a generator that outputs a jittered version of a random image from the annolist that is mean corrected.""" base_path = os.path.realpath(os.path.dirname(kitti_txt)) files = [line.rstrip() for line in open(kitti_txt)] if hypes['data']['truncate_data']: files = files[:10] random.seed(0) for epoch in itertools.count(): if random_shuffel: random.shuffle(files) for file in files: image_file, gt_image_file = file.split(" ") image_file_split = image_file.split('/') index = image_file_split[-1].split('.')[0] calib_file = os.path.join(base_path, image_file_split[0], 'calib', index + '.txt') assert os.path.exists(calib_file), \ "File does not exist: %s" % calib_file image_file = os.path.join(base_path, image_file) assert os.path.exists(image_file), \ "File does not exist: %s" % image_file gt_image_file = os.path.join(base_path, gt_image_file) assert os.path.exists(gt_image_file), \ "File does not exist: %s" % gt_image_file rect_list = read_kitti_anno(gt_image_file, calib_file, detect_truck=hypes['detect_truck']) anno = AnnoLib.Annotation() anno.rects = rect_list im = scp.misc.imread(image_file) if im.shape[2] == 4: im = im[:, :, :3] if jitter: im, anno = _flip(im, anno) im, anno = _jitter(im, anno) im = _noise(_enhance(im)) # _vis(im, anno, index) anno = _rescale_boxes(im.shape, anno, hypes["image_height"], hypes["image_width"]) im = imresize(im, (hypes["image_height"], hypes["image_width"]), interp='cubic') pos_list = [rect for rect in anno.rects if rect.classID == 1] pos_anno = fake_anno(pos_list) # boxes: [1, grid_height*grid_width, 11, max_len, 1] # for each cell, this array contains the ground truth boxes around it (within focus area, defined by center distance) # confs: [1, grid_height*grid_width, 1, max_len, 1] # record the valid boxes, since max_len is greater than the number of ground truth boxes boxes, confs, calib, calib_pinv, xy_scale = annotation_to_h5( hypes, pos_anno, hypes["grid_width"], hypes["grid_height"], hypes["rnn_len"]) # masks are zero in "Don't care" area mask_list = [rect for rect in anno.rects if rect.classID == -1] mask = _generate_mask(hypes, mask_list) boxes = boxes.reshape( [hypes["grid_height"], hypes["grid_width"], 11]) confs = confs.reshape(hypes["grid_height"], hypes["grid_width"]) calib = calib.reshape(hypes["grid_height"], hypes["grid_width"], 3, 4) xy_scale = xy_scale.reshape(hypes["grid_height"], hypes["grid_width"], 2) calib_pinv = calib_pinv.reshape(hypes['grid_height'], hypes['grid_width'], 4, 3) yield { "image": im, "boxes": boxes, "confs": confs, "calib": calib, "calib_pinv": calib_pinv, "xy_scale": xy_scale, "rects": pos_list, "mask": mask }
def _load_kitti_txt(kitti_txt, hypes, jitter=False, random_shuffel=True): """Take the txt file and net configuration and create a generator that outputs a jittered version of a random image from the annolist that is mean corrected.""" base_path = os.path.realpath(os.path.dirname(kitti_txt)) files = [line.rstrip() for line in open(kitti_txt)] if hypes['data']['truncate_data']: files = files[:10] random.seed(0) for epoch in itertools.count(): if random_shuffel: random.shuffle(files) for file in files: image_file, gt_image_file = file.split(" ") image_file = os.path.join(base_path, image_file) assert os.path.exists(image_file), \ "File does not exist: %s" % image_file gt_image_file = os.path.join(base_path, gt_image_file) assert os.path.exists(gt_image_file), \ "File does not exist: %s" % gt_image_file rect_list = read_kitti_anno(gt_image_file, detect_truck=hypes['detect_truck']) anno = AnnoLib.Annotation() anno.rects = rect_list im = scp.misc.imread(image_file) # Noise has to be created after loading image if hypes.get('noise', False) and random.random() < 0.5: im = create_noisy(im, mode=hypes['noise']) if im.shape[2] == 4: im = im[:, :, :3] if im.shape[0] != hypes["image_height"] or \ im.shape[1] != hypes["image_width"]: if True: anno = _rescale_boxes(im.shape, anno, hypes["image_height"], hypes["image_width"]) im = imresize(im, (hypes["image_height"], hypes["image_width"]), interp='cubic') # If flip flag is set, flip image around y axis if hypes.get('flip', False) and random.random() < 0.5: im, anno = _flip_image(im, anno) if jitter: jitter_scale_min = hypes.get('jitter_scale_min', 0.9) jitter_scale_max = hypes.get('jitter_scale_max', 1.1) assert jitter_scale_min < jitter_scale_max jitter_offset = hypes.get('jitter_offset', 16) im, anno = annotation_jitter( im, anno, target_width=hypes["image_width"], target_height=hypes["image_height"], jitter_scale_min=jitter_scale_min, jitter_scale_max=jitter_scale_max, jitter_offset=jitter_offset) pos_list = [rect for rect in anno.rects if rect.classID == 1] pos_anno = fake_anno(pos_list) boxes, confs = annotation_to_h5(hypes, pos_anno, hypes["grid_width"], hypes["grid_height"], hypes["rnn_len"]) mask_list = [rect for rect in anno.rects if rect.classID == -1] mask = _generate_mask(hypes, mask_list) boxes = boxes.reshape( [hypes["grid_height"], hypes["grid_width"], 4]) confs = confs.reshape(hypes["grid_height"], hypes["grid_width"]) yield { "image": im, "boxes": boxes, "confs": confs, "rects": pos_list, "mask": mask }