def __init__(self, args): super(TFRecordDetectionPipeline, self).__init__(args.batch_size, args.num_workers, 0, 0) self.input = ops.TFRecordReader( path=os.path.join(test_dummy_data_path, 'small_coco.tfrecord'), index_path=os.path.join(test_dummy_data_path, 'small_coco_index.idx'), features={ 'image/encoded': tfrec.FixedLenFeature((), tfrec.string, ""), 'image/object/class/label': tfrec.VarLenFeature([1], tfrec.int64, 0), 'image/object/bbox': tfrec.VarLenFeature([4], tfrec.float32, 0.0), }, shard_id=0, num_shards=1, random_shuffle=False) self.decode_gpu = ops.ImageDecoder(device="mixed", output_type=types.RGB) self.cast = ops.Cast(dtype=types.INT32) self.box_encoder = ops.BoxEncoder(device="cpu", criteria=0.5, anchors=coco_anchors())
def __init__(self, batch_size, file_root, annotations_file, default_boxes, seed, device_id=0, num_threads=4): super(COCOPipeline, self).__init__(batch_size=batch_size, device_id=device_id, num_threads=num_threads, seed=seed) self.input = ops.COCOReader(file_root=file_root, annotations_file=annotations_file, ratio=True, ltrb=True, random_shuffle=True) self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB) # Augumentation techniques self.crop = ops.RandomBBoxCrop(device="cpu", aspect_ratio=[0.5, 2.0], thresholds=[0.1, 0.3, 0.5, 0.7, 0.9], scaling=[0.8, 1.0], ltrb=True) self.slice = ops.Slice(device="gpu") self.twist = ops.ColorTwist(device="gpu") self.resize = ops.Resize(device="gpu", resize_x=300, resize_y=300) self.normalize = ops.CropMirrorNormalize( device="gpu", crop=(300, 300), mean=[0.485 * 255., 0.456 * 255., 0.406 * 255.], std=[0.229 * 255., 0.224 * 255., 0.225 * 255.]) # Random variables self.rng1 = ops.Uniform(range=[0.5, 1.5]) self.rng2 = ops.Uniform(range=[0.875, 1.125]) self.rng3 = ops.Uniform(range=[-0.5, 0.5]) self.flip = ops.Flip(device="gpu") self.bbflip = ops.BbFlip(device="cpu", ltrb=True) self.flip_coin = ops.CoinFlip(probability=0.5) self.box_encoder = ops.BoxEncoder(device="cpu", criteria=0.5, anchors=default_boxes.as_ltrb_list())
def __init__(self, args, data_path=test_data_path): super(COCODetectionPipeline, self).__init__(args.batch_size, args.num_workers, 0, 0) self.input = ops.readers.COCO( file_root=os.path.join(data_path, 'images'), annotations_file=os.path.join(data_path, 'instances.json'), shard_id=0, num_shards=1, ratio=True, ltrb=True, random_shuffle=False) self.decode_gpu = ops.decoders.Image(device="mixed", output_type=types.RGB) self.box_encoder = ops.BoxEncoder(device="cpu", criteria=0.5, anchors=coco_anchors())
def __init__(self, args, device_id, file_root, annotations_file): super(DetectionPipeline, self).__init__(args.batch_size, args.num_workers, device_id, args.prefetch, args.seed) # Reading COCO dataset self.input = ops.COCOReader(file_root=file_root, annotations_file=annotations_file, shard_id=device_id, num_shards=args.num_gpus, ratio=True, ltrb=True, random_shuffle=True) self.decode_cpu = ops.HostDecoder(device="cpu", output_type=types.RGB) self.decode_crop = ops.HostDecoderSlice(device="cpu", output_type=types.RGB) self.decode_gpu = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB) self.decode_gpu_crop = ops.nvJPEGDecoderSlice(device="mixed", output_type=types.RGB) self.ssd_crop = ops.SSDRandomCrop(device="cpu", num_attempts=1, seed=args.seed) self.random_bbox_crop = ops.RandomBBoxCrop( device="cpu", aspect_ratio=[0.5, 2.0], thresholds=[0, 0.1, 0.3, 0.5, 0.7, 0.9], scaling=[0.3, 1.0], ltrb=True, seed=args.seed) self.slice_cpu = ops.Slice(device="cpu") self.slice_gpu = ops.Slice(device="gpu") self.resize_cpu = ops.Resize( device="cpu", resize_x=300, resize_y=300, min_filter=types.DALIInterpType.INTERP_TRIANGULAR) self.resize_gpu = ops.Resize( device="gpu", resize_x=300, resize_y=300, min_filter=types.DALIInterpType.INTERP_TRIANGULAR) mean = [0.485 * 255, 0.456 * 255, 0.406 * 255] std = [0.229 * 255, 0.224 * 255, 0.225 * 255] crop_size = (300, 300) self.normalize_cpu = ops.CropMirrorNormalize(device="cpu", crop=crop_size, mean=mean, std=std, mirror=0, output_dtype=types.FLOAT) self.normalize_gpu = ops.CropMirrorNormalize(device="gpu", crop=crop_size, mean=mean, std=std, mirror=0, output_dtype=types.FLOAT) self.twist_cpu = ops.ColorTwist(device="cpu") self.twist_gpu = ops.ColorTwist(device="gpu") self.flip_cpu = ops.Flip(device="cpu") self.bbox_flip_cpu = ops.BbFlip(device="cpu", ltrb=True) self.flip_gpu = ops.Flip(device="gpu") self.bbox_flip_gpu = ops.BbFlip(device="gpu", ltrb=True) default_boxes = coco_anchors() self.box_encoder_cpu = ops.BoxEncoder(device="cpu", criteria=0.5, anchors=default_boxes) self.box_encoder_gpu = ops.BoxEncoder(device="gpu", criteria=0.5, anchors=default_boxes) self.box_encoder_cpu_offsets = ops.BoxEncoder( device="cpu", criteria=0.5, offset=True, scale=2, stds=[0.1, 0.1, 0.2, 0.2], anchors=default_boxes) self.box_encoder_gpu_offsets = ops.BoxEncoder( device="gpu", criteria=0.5, offset=True, scale=2, stds=[0.1, 0.1, 0.2, 0.2], anchors=default_boxes) # Random variables self.rng1 = ops.Uniform(range=[0.5, 1.5]) self.rng2 = ops.Uniform(range=[0.875, 1.125]) self.rng3 = ops.Uniform(range=[-0.5, 0.5])
def __init__(self, default_boxes, args, seed): super(COCOPipeline, self).__init__(batch_size=args.batch_size, device_id=args.local_rank, num_threads=args.num_workers, seed=seed) try: shard_id = torch.distributed.get_rank() num_shards = torch.distributed.get_world_size() except RuntimeError: shard_id = 0 num_shards = 1 self.input = ops.COCOReader(file_root=args.train_coco_root, annotations_file=args.train_annotate, skip_empty=True, shard_id=shard_id, num_shards=num_shards, ratio=True, ltrb=True, random_shuffle=False, shuffle_after_epoch=True) self.decode = ops.ImageDecoder(device="cpu", output_type=types.RGB) # Augumentation techniques self.crop = ops.RandomBBoxCrop(device="cpu", aspect_ratio=[0.5, 2.0], thresholds=[0, 0.1, 0.3, 0.5, 0.7, 0.9], scaling=[0.3, 1.0], ltrb=True, allow_no_crop=True, num_attempts=1) self.slice = ops.Slice(device="cpu") self.hsv = ops.Hsv( device="gpu", dtype=types.FLOAT) # use float to avoid clipping and # quantizing the intermediate result self.bc = ops.BrightnessContrast( device="gpu", contrast_center=128, # input is in float, but in 0..255 range dtype=types.UINT8) self.resize = ops.Resize( device="cpu", resize_x=300, resize_y=300, min_filter=types.DALIInterpType.INTERP_TRIANGULAR) dtype = types.FLOAT16 if args.fp16 else types.FLOAT self.normalize = ops.CropMirrorNormalize( device="gpu", crop=(300, 300), mean=[0.485 * 255, 0.456 * 255, 0.406 * 255], std=[0.229 * 255, 0.224 * 255, 0.225 * 255], mirror=0, dtype=dtype, output_layout=types.NCHW, pad_output=False) # Random variables self.rng1 = ops.Uniform(range=[0.5, 1.5]) self.rng2 = ops.Uniform(range=[0.875, 1.125]) self.rng3 = ops.Uniform(range=[-0.5, 0.5]) self.flip = ops.Flip(device="cpu") self.bbflip = ops.BbFlip(device="cpu", ltrb=True) self.flip_coin = ops.CoinFlip(probability=0.5) self.box_encoder = ops.BoxEncoder(device="cpu", criteria=0.5, anchors=default_boxes.as_ltrb_list())
def __init__(self, args, device_id, file_root, annotations_file): super(DetectionPipeline, self).__init__(batch_size=args.batch_size, num_threads=args.num_workers, device_id=device_id, prefetch_queue_depth=args.prefetch, seed=args.seed) # Reading COCO dataset self.input = ops.readers.COCO(file_root=file_root, annotations_file=annotations_file, shard_id=device_id, num_shards=args.num_gpus, ratio=True, ltrb=True, random_shuffle=True) self.decode_cpu = ops.decoders.Image(device="cpu", output_type=types.RGB) self.decode_crop = ops.decoders.ImageSlice(device="cpu", output_type=types.RGB) self.decode_gpu = ops.decoders.Image(device="mixed", output_type=types.RGB, hw_decoder_load=0) self.decode_gpu_crop = ops.decoders.ImageSlice(device="mixed", output_type=types.RGB, hw_decoder_load=0) self.ssd_crop = ops.SSDRandomCrop(device="cpu", num_attempts=1, seed=args.seed) self.random_bbox_crop = ops.RandomBBoxCrop( device="cpu", aspect_ratio=[0.5, 2.0], thresholds=[0, 0.1, 0.3, 0.5, 0.7, 0.9], scaling=[0.3, 1.0], bbox_layout="xyXY", seed=args.seed) self.slice_cpu = ops.Slice(device="cpu") self.slice_gpu = ops.Slice(device="gpu") self.resize_cpu = ops.Resize( device="cpu", resize_x=300, resize_y=300, min_filter=types.DALIInterpType.INTERP_TRIANGULAR) self.resize_gpu = ops.Resize( device="gpu", resize_x=300, resize_y=300, min_filter=types.DALIInterpType.INTERP_TRIANGULAR) mean = [0.485 * 255, 0.456 * 255, 0.406 * 255] std = [0.229 * 255, 0.224 * 255, 0.225 * 255] crop_size = (300, 300) self.normalize_cpu = ops.CropMirrorNormalize(device="cpu", crop=crop_size, mean=mean, std=std, mirror=0, dtype=types.FLOAT) self.normalize_gpu = ops.CropMirrorNormalize(device="gpu", crop=crop_size, mean=mean, std=std, mirror=0, dtype=types.FLOAT) self.twist_cpu = ops.ColorTwist(device="cpu") self.twist_gpu = ops.ColorTwist(device="gpu") self.hsv_cpu = ops.Hsv(device="cpu", dtype=types.FLOAT) self.hsv_gpu = ops.Hsv(device="gpu", dtype=types.FLOAT) self.bc_cpu = ops.BrightnessContrast(device="cpu", dtype=types.UINT8, contrast_center=128) self.bc_gpu = ops.BrightnessContrast(device="gpu", dtype=types.UINT8, contrast_center=128) self.flip_cpu = ops.Flip(device="cpu") self.bbox_flip_cpu = ops.BbFlip(device="cpu", ltrb=True) self.flip_gpu = ops.Flip(device="gpu") self.bbox_flip_gpu = ops.BbFlip(device="gpu", ltrb=True) default_boxes = coco_anchors() self.box_encoder_cpu = ops.BoxEncoder(device="cpu", criteria=0.5, anchors=default_boxes) self.box_encoder_gpu = ops.BoxEncoder(device="gpu", criteria=0.5, anchors=default_boxes) self.box_encoder_cpu_offsets = ops.BoxEncoder( device="cpu", criteria=0.5, offset=True, scale=2, stds=[0.1, 0.1, 0.2, 0.2], anchors=default_boxes) self.box_encoder_gpu_offsets = ops.BoxEncoder( device="gpu", criteria=0.5, offset=True, scale=2, stds=[0.1, 0.1, 0.2, 0.2], anchors=default_boxes) # Random variables self.saturation_rng = ops.random.Uniform(range=[0.8, 1.2]) self.contrast_rng = ops.random.Uniform(range=[0.5, 1.5]) self.brighness_rng = ops.random.Uniform(range=[0.875, 1.125]) self.hue_rng = ops.random.Uniform(range=[-45, 45])
def __init__(self, batch_size, device_id, file_root, meta_files_path, annotations_file, num_gpus, anchors_ltrb_list, output_fp16=False, output_nhwc=False, pad_output=False, num_threads=1, seed=15, dali_cache=-1, dali_async=True, use_nvjpeg=False): super(COCOPipeline, self).__init__(batch_size=batch_size, device_id=device_id, num_threads=num_threads, seed=seed, exec_pipelined=dali_async, exec_async=dali_async) self.use_nvjpeg = use_nvjpeg try: shard_id = torch.distributed.get_rank() # Note: <= 19.05 was a RuntimeError, 19.06 is now throwing AssertionError except (RuntimeError, AssertionError): shard_id = 0 if meta_files_path == None: self.c_input = ops.COCOReader( file_root=file_root, annotations_file=annotations_file, shard_id=shard_id, num_shards=num_gpus, ratio=True, ltrb=True, skip_empty=True, random_shuffle=(dali_cache > 0), stick_to_shard=(dali_cache > 0), lazy_init=True, shuffle_after_epoch=(dali_cache <= 0)) else: self.c_input = ops.COCOReader( file_root=file_root, meta_files_path=meta_files_path, shard_id=shard_id, num_shards=num_gpus, random_shuffle=(dali_cache > 0), stick_to_shard=(dali_cache > 0), lazy_init=True, shuffle_after_epoch=(dali_cache <= 0)) self.c_crop = ops.RandomBBoxCrop( device="cpu", aspect_ratio=[0.5, 2.0], thresholds=[0, 0.1, 0.3, 0.5, 0.7, 0.9], scaling=[0.3, 1.0], ltrb=True, allow_no_crop=True, num_attempts=1) decoder_device = 'mixed' if use_nvjpeg else 'cpu' # fused decode and slice. This is "region-of-interest" (roi) decoding self.m_decode = ops.ImageDecoderSlice(device=decoder_device, output_type=types.RGB) self.g_slice = None # special case for using dali decode caching: the caching decoder can't # be fused with slicing (because we need to slice the decoded image # differently every epoch), so we need to unfuse decode and slice: if dali_cache > 0 and use_nvjpeg: self.m_decode = ops.ImageDecoder(device='mixed', output_type=types.RGB, cache_size=dali_cache * 1024, cache_type="threshold", cache_threshold=10000) self.g_slice = ops.Slice(device="gpu") # Augumentation techniques (in addition to random crop) self.g_twist = ops.ColorTwist(device="gpu") self.g_resize = ops.Resize( device="gpu", resize_x=300, resize_y=300, min_filter=types.DALIInterpType.INTERP_TRIANGULAR) output_dtype = types.FLOAT16 if output_fp16 else types.FLOAT output_layout = types.NHWC if output_nhwc else types.NCHW mean_val = list(np.array([0.485, 0.456, 0.406]) * 255.) std_val = list(np.array([0.229, 0.224, 0.225]) * 255.) self.g_normalize = ops.CropMirrorNormalize(device="gpu", crop=(300, 300), mean=mean_val, std=std_val, output_dtype=output_dtype, output_layout=output_layout, pad_output=pad_output) # Random variables self.c_rng1 = ops.Uniform(range=[0.5, 1.5]) self.c_rng2 = ops.Uniform(range=[0.875, 1.125]) self.c_rng3 = ops.Uniform(range=[-0.5, 0.5]) flip_probability = 0.5 self.c_flip_coin = ops.CoinFlip( probability=flip_probability) # coin_rnd self.c_bbflip = ops.BbFlip(device="cpu", ltrb=True) self.g_box_encoder = ops.BoxEncoder(device="gpu", criteria=0.5, anchors=anchors_ltrb_list, offset=True, stds=[0.1, 0.1, 0.2, 0.2], scale=300) self.g_cast = ops.Cast(device="gpu", dtype=types.FLOAT)
def __init__(self, default_boxes, root, annFile, batch_size, mean, std, local_rank, num_workers, seed): super(COCOPipeline, self).__init__(batch_size=batch_size, device_id=local_rank, num_threads=num_workers, seed=seed) # try: # shard_id = torch.distributed.get_rank() # num_shards = torch.distributed.get_world_size() # except RuntimeError: shard_id = 0 num_shards = 1 self.input = ops.COCOReader(file_root=root, annotations_file=annFile, skip_empty=True, shard_id=shard_id, num_shards=num_shards, ratio=True, ltrb=True, random_shuffle=False, shuffle_after_epoch=True) self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB) # Augumentation techniques # expand 1~2 self.paste_ratio = ops.Uniform(range=[1, 2]) self.paste_pos = ops.Uniform(range=[0, 1]) self.paste = ops.Paste(device="gpu", fill_value=tuple(mean)) self.bbpaste = ops.BBoxPaste(device="cpu", ltrb=True) # random crop self.crop = ops.RandomBBoxCrop(device="cpu", aspect_ratio=[0.5, 2.0], thresholds=[0.1, 0.3, 0.5, 0.7, 0.9], scaling=[0.3, 1.0], ltrb=True, allow_no_crop=True, num_attempts=50) self.slice = ops.Slice(device="gpu") self.twist = ops.ColorTwist(device="gpu") self.resize = ops.Resize( device="gpu", resize_x=320, resize_y=320, min_filter=types.DALIInterpType.INTERP_TRIANGULAR) self.normalize = ops.CropMirrorNormalize(device="gpu", crop=(320, 320), mean=mean, std=std, mirror=0, output_dtype=types.FLOAT, output_layout=types.NCHW, pad_output=False) # Random variables self.rng1 = ops.Uniform(range=[0.5, 1.5]) self.rng2 = ops.Uniform(range=[0.875, 1.125]) self.rng3 = ops.Uniform(range=[-0.5, 0.5]) self.flip = ops.Flip(device="gpu") self.bbflip = ops.BbFlip(device="cpu", ltrb=True) self.flip_coin = ops.CoinFlip(probability=0.5) self.box_encoder = ops.BoxEncoder(device="cpu", criteria=0.5, anchors=default_boxes.as_ltrb_list())