def load_segmentation(source_image_filename, mask_image_filename): ''' Load Segmentation data. Parameters ---------- source_image_filename : string filename of the source image mask_image_filename : string filename of the corresponding mask image in binary format Notes ----- In Segmentation model we have to feed the model with a simple image and the labels will be given by the mask (binary) of the same image in which the segmentation parts are highlight No checks are performed on the compatibility between source image and corresponding mask file. The only checks are given on the image size (channels are excluded) ''' src_image = Image(source_image_filename) mask_image = Image(mask_image_filename) if src_image.shape[:2] != mask_image.shape[:2]: raise ValueError( 'Incorrect shapes found. The source image and the corresponding mask have different sizes' ) return (src_image, mask_image)
def read (self): ''' Get a frame as Image object Returns ------- im : Image obj The loaded image ''' im = Image() return im.from_frame(self._queue.get())
def load_super_resolution(hr_image_filename, patch_size=(48, 48), scale=4): ''' Load Super resolution data. Parameters ---------- hr_image_filename : string Filename of the high resolution image patch_size : tuple (default=(48, 48)) Dimension to cut scale : int (default=4) Downsampling scale factor Returns ------- data : Image obj Loaded Image object label : Image obj Generated Image label Notes ----- .. note:: In SR models the labels are given by the HR image while the input data are obtained from the same image after a downsampling/resizing. The upsample scale factor learned by the SR model will be the same used inside this function. ''' hr_image = Image(hr_image_filename) w, h, _ = hr_image.shape patch_x, patch_y = patch_size dx = np.random.uniform(low=0, high=w - patch_x - 1) dy = np.random.uniform(low=0, high=h - patch_y - 1) hr_image = hr_image.crop(dsize=(dx, dy), size=patch_size) random_flip = np.random.uniform(low=0, high=1.) if random_flip >= .66: hr_image = hr_image.transpose() hr_image = hr_image.flip() elif random_flip >= .33: hr_image = hr_image.flip() else: pass label = hr_image data = hr_image.resize(scale_factor=(scale, scale)) return (data, label)
def main(): done = True args = parse_args() data_cfg = data_config(args.data_cfg) args.netcfg = data_cfg.get('cfg', default=args.netcfg) args.weights = data_cfg.get('weights', default=args.weights) args.namesfile = data_cfg.get('names', default=args.namesfile) if not args.netcfg or not args.weights: raise ValueError('Network config AND network weights must be given') names = get_labels(args.namesfile, args.classes) net = Network(batch=32) net.load(args.netcfg, args.weights) net_w, net_h, _ = net.input_shape if not args.input: args.input = input('Enter Image Path: ') done = False if not args.input else True # set the output filename args.outfile = args.outfile if args.outfile else splitext( args.input)[0] + '_detected' while done: # load image from file input_image = Image(filename=args.input) # pad-resize image if it is necessary input_image = input_image.letterbox(net_dim=( net_w, net_h)) if input_image.shape[:2] != net.shape else input_image _ = net.predict(X=input_image) # insert boxes evaluation and draw-detection and show image input_image.show(window_name=args.outfile, ms=0, fullscreen=args.fullscreen) if args.save: input_image.save(filename=args.outfile) args.input = input('Enter Image Path: ') done = False if not args.input else True
def read(self): ''' Get a frame as Image object ''' im = Image() return im.from_frame(self._queue.get())