def __init__(self, device): super(ConstantPipeline, self).__init__(10, 3, device_id = 0, exec_async=True, exec_pipelined=True) self.const1 = ops.Constant(device = device, fdata = (1.25,2.5,3)) self.const2 = ops.Constant(device = device, idata = (1,2,3,4), shape=(2,1,2)) self.const3 = ops.Constant(device = device, idata = (-1,1,2,3,4), dtype=types.UINT8) self.const4 = ops.Constant(device = device, fdata = (0.25,1.25,2.25,3.25,4.25), dtype=types.FLOAT16) self.const5 = ops.Constant(device = device, fdata = 5.5, shape=(100,100)) self.const6 = ops.Constant(device = device, idata = -4, shape=(10,20)) self.const7 = ops.Constant(device = device, idata = [0, 1, 0], dtype=types.BOOL)
def __init__(self, size, fill_value): self.rz_img = ops.Resize(device="gpu", resize_longer=size) self.rz_ann = ops.Resize(device="gpu", resize_longer=size, interp_type=types.DALIInterpType.INTERP_NN) self.cp_img = ops.Crop(device="gpu", fill_values=fill_value, out_of_bounds_policy='pad') self.cp_ann = ops.Crop(device="gpu", fill_values=0, out_of_bounds_policy='pad') self.size = ops.Constant(fdata=size) self.pos = ops.Uniform(range=[0, 1]) self.scale = ops.Uniform(range=[0.667, 1.5]) self.shape = ops.Shapes(device="gpu")
def ConstantNode(device, value, dtype, shape, layout, **kwargs): data = value if _is_mxnet_array(value): # mxnet ndarray is not directly compatible with numpy.ndarray, but provides conversion value = value.asnumpy() if _is_numpy_array(value): import numpy as np # 64-bit types are not supported - downgrade the input if value.dtype == np.float64: value = value.astype(np.float32) if value.dtype == np.int64: value = value.astype(np.int32) if value.dtype == np.uint64: value = value.astype(np.uint32) if _is_numpy_array(value) or _is_torch_tensor(value): # torch tensor and numpy array have very similar API actual_type = to_dali_type(value.dtype) if dtype is None: dtype = actual_type if shape is not None: value = value.reshape(shape) else: shape = list(value.shape) # torch uses torch.Size instead of list data = value.flatten().tolist() else: def _type_from_value_or_list(v): if not isinstance(v, (list, tuple)): v = [v] has_floats = False has_ints = False has_bools = False for x in v: if isinstance(x, float): has_floats = True elif isinstance(x, bool): has_bools = True elif isinstance(x, int): has_ints = True else: raise TypeError("Unexpected type: " + str(type(x))) if has_floats: return DALIDataType.FLOAT if has_ints: return DALIDataType.INT32 if has_bools: return DALIDataType.BOOL # empty list defaults to float return DALIDataType.FLOAT actual_type = _type_from_value_or_list(value) if dtype is None: dtype = actual_type import nvidia.dali.ops as ops def _convert(x, type): if isinstance(x, (list, tuple)): return [type(y) for y in x] return type(x) isint = actual_type in _int_like_types idata = _convert(data, int) if isint else None fdata = None if isint else data if device is None: device = "cpu" # 'name' argument is pased to call, not the constructor constructor_args = kwargs call_args = {} name = constructor_args.get("name") if name is not None: call_args["name"] = name del constructor_args["name"] op = ops.Constant(device=device, fdata=fdata, idata=idata, shape=shape, dtype=dtype, layout=layout, **constructor_args) return op(**call_args)
def __init__(self, directory, supervised: bool = True, sequence_length: int = 11, batch_size: int = 1, num_workers: int = 1, gpu_id: int = 0, shuffle: bool = True, crop_size: tuple = (256, 256), resize: tuple = None, brightness: float = 0.25, contrast: float = 0.1, mean: list = [0.5, 0.5, 0.5], std: list = [0.5, 0.5, 0.5], conv_mode='3d', image_shape=(256, 256), validate: bool = False): super().__init__(batch_size, num_workers, gpu_id, prefetch_queue_depth=1) self.input = ops.VideoReader(additional_decode_surfaces=1, channels=3, device="gpu", dtype=types.FLOAT, enable_frame_num=False, enable_timestamps=False, file_root=directory, image_type=types.RGB, initial_fill=1, lazy_init=False, normalized=True, num_shards=1, pad_last_batch=False, prefetch_queue_depth=1, random_shuffle=shuffle, sequence_length=sequence_length, skip_vfr_check=True, step=-1, shard_id=0, stick_to_shard=False, stride=1) self.uniform = ops.Uniform(range=(0.0, 1.0)) self.cmn = ops.CropMirrorNormalize(device='gpu', crop=crop_size, mean=mean, std=std, output_layout=types.NFHWC) self.coin = ops.CoinFlip(probability=0.5) self.brightness_val = ops.Uniform( range=[1 - brightness, 1 + brightness]) self.contrast_val = ops.Uniform(range=[1 - contrast, 1 + contrast]) self.supervised = supervised self.half = ops.Constant(fdata=0.5) self.zero = ops.Constant(idata=0) self.cast_to_long = ops.Cast(device='gpu', dtype=types.INT64) if crop_size is not None: H, W = crop_size else: # default H, W = image_shape # print('CONV MODE!!! {}'.format(conv_mode)) if conv_mode == '3d': self.transpose = ops.Transpose(device="gpu", perm=[3, 0, 1, 2]) self.reshape = None elif conv_mode == '2d': self.transpose = ops.Transpose(device='gpu', perm=[0, 3, 1, 2]) self.reshape = ops.Reshape(device='gpu', shape=[-1, H, W]) self.validate = validate
def __init__(self, **kwargs): super(TestPipeline, self).__init__(**kwargs) self.constant = ops.Constant(dtype=dali_type, idata=[1, 1], shape=[2])
def ConstantNode(device, value, dtype, shape, layout, **kwargs): data = value if _is_compatible_array_type(value): value = _preprocess_constant_array_type(value) # At this point value is a numpy array or a torch tensor. They have very similar API actual_type = to_dali_type(value.dtype) if dtype is None: dtype = actual_type if shape is not None: value = value.reshape(shape) else: shape = list(value.shape) # torch uses torch.Size instead of list data = value.flatten().tolist() else: def _type_from_value_or_list(v): if not isinstance(v, (list, tuple)): v = [v] has_floats = False has_ints = False has_bools = False for x in v: if isinstance(x, float): has_floats = True elif isinstance(x, bool): has_bools = True elif isinstance(x, int): has_ints = True else: raise TypeError("Unexpected type: " + str(type(x))) if has_floats: return DALIDataType.FLOAT if has_ints: return DALIDataType.INT32 if has_bools: return DALIDataType.BOOL # empty list defaults to float return DALIDataType.FLOAT actual_type = _type_from_value_or_list(value) if dtype is None: dtype = actual_type import nvidia.dali.ops as ops def _convert(x, type): if isinstance(x, (list, tuple)): return [type(y) for y in x] return type(x) isint = actual_type in _int_like_types idata = _convert(data, int) if isint else None fdata = None if isint else data if device is None: device = "cpu" # 'name' argument is pased to call, not the constructor constructor_args = kwargs call_args = {} name = constructor_args.get("name") if name is not None: call_args["name"] = name del constructor_args["name"] op = ops.Constant(device=device, fdata=fdata, idata=idata, shape=shape, dtype=dtype, layout=layout, **constructor_args) return op(**call_args)