Beispiel #1
0
    def __init__(self, batch_size, num_threads, path, training, annotations, world, device_id, mean, std, resize, max_size, stride):
        super().__init__(batch_size=batch_size, num_threads=num_threads, device_id = device_id, prefetch_queue_depth=num_threads, seed=42)

        self.path = path
        self.training = training
        self.stride = stride
        self.iter = 0

        self.reader = ops.COCOReader(annotations_file=annotations, file_root=path, num_shards=world,shard_id=torch.cuda.current_device(), 
                                     ltrb=True, ratio=True, shuffle_after_epoch=True, save_img_ids=True)

        self.decode_train = ops.ImageDecoderSlice(device="mixed", output_type=types.RGB)
        self.decode_infer = ops.ImageDecoder(device="mixed", output_type=types.RGB)
        self.bbox_crop = ops.RandomBBoxCrop(device='cpu', ltrb=True, scaling=[0.3, 1.0], thresholds=[0.1,0.3,0.5,0.7,0.9])

        self.bbox_flip = ops.BbFlip(device='cpu', ltrb=True)
        self.img_flip = ops.Flip(device='gpu')
        self.coin_flip = ops.CoinFlip(probability=0.5)

        if isinstance(resize, list): resize = max(resize)
        self.rand_resize = ops.Uniform(range=[resize, float(max_size)])

        self.resize_train = ops.Resize(device='gpu', interp_type=types.DALIInterpType.INTERP_CUBIC, save_attrs=True)
        self.resize_infer = ops.Resize(device='gpu', interp_type=types.DALIInterpType.INTERP_CUBIC, resize_longer=max_size, save_attrs=True)

        padded_size = max_size + ((self.stride - max_size % self.stride) % self.stride)

        self.pad = ops.Paste(device='gpu', fill_value = 0, ratio=1.1, min_canvas_size=padded_size, paste_x=0, paste_y=0)
        self.normalize = ops.CropMirrorNormalize(device='gpu', mean=mean, std=std, crop=padded_size, crop_pos_x=0, crop_pos_y=0)
Beispiel #2
0
      def __init__(self, split, args=None):
          #batch_size, num_threads, data_dir, crop, shuffle=False, device_id=0, size=256, dali_cpu=False):
          self.split = split
          self.bs = args.batch_size if self.split == 'train' else args.val_batch_size
          self.shuffle = self.split == 'train'
          self.data_dir = os.path.join(args.root, split)
          self.crop = args.input_size
          super(HybridPipe, self).__init__(self.bs, args.workers, 0, seed=12)
          self.input = ops.FileReader(file_root=self.data_dir, shard_id=0, num_shards=1, random_shuffle=self.shuffle)
          dali_device = "gpu"
          if split == 'train':
              self.decode = ops.ImageDecoderRandomCrop(device="mixed", output_type=types.RGB,
                      device_memory_padding=211025920, host_memory_padding=140544512,
                      random_aspect_ratio=[0.75, 1.333],
                      random_area=[0.08, 1.0],
                      num_attempts=100)
              #self.res = ops.Resize(device=dali_device, resize_x=args.input_size, resize_y=args.input_size, interp_type=types.INTERP_TRIANGULAR)
              self.res = ops.Resize(device=dali_device, resize_shorter=args.input_size, interp_type=types.INTERP_TRIANGULAR)
          else:
              self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
              self.res = ops.Resize(device=dali_device, resize_shorter=256, interp_type=types.INTERP_TRIANGULAR)

          self.cmnp = ops.CropMirrorNormalize(device="gpu",
                  output_dtype=types.FLOAT,
                  output_layout=types.NCHW,
                  crop=(self.crop, self.crop),
                  image_type=types.RGB,
                  mean=[0.485 * 255,0.456 * 255,0.406 * 255],
                  std=[0.229 * 255,0.224 * 255,0.225 * 255])
          self.coin = ops.CoinFlip(probability=0.5)
Beispiel #3
0
 def __init__(self, batch_size, num_threads, device_id, data_dir, crop_size, resize_size, full_sized=False, square=False):
   self.eii = ExternalInputIterator(data_dir, batch_size, train=False, full=full_sized)
   self.eii_iterator = iter(self.eii)
   super(CaffeValPipe, self).__init__(batch_size, num_threads, device_id)
   self.input = ops.ExternalSource()
   self.input_label = ops.ExternalSource()
   self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
   self.full_sized = full_sized
   resize_not_needed = (not square) and (not full_sized)
   self.resize_needed = not resize_not_needed
   if self.resize_needed:
     print(f"Resize will happen for VAL dataset, full_sized={full_sized}, square={square}")
     if square:
       self.res = ops.Resize(device='gpu', resize_x=resize_size, resize_y=resize_size, interp_type=types.INTERP_TRIANGULAR)
     else:
       self.res = ops.Resize(device='gpu', resize_shorter=resize_size, interp_type=types.INTERP_TRIANGULAR)
   else:
     print(f"No resize will happen for VAL dataset, full_sized={full_sized}, square={square}")
   self.cmnp = ops.CropMirrorNormalize(device="gpu",
                                       output_dtype=types.FLOAT,
                                       output_layout=types.NCHW,
                                       crop=(crop_size, crop_size),
                                       image_type=types.RGB,
                                       mean=[0.485 * 255,0.456 * 255,0.406 * 255],
                                       std=[0.229 * 255,0.224 * 255,0.225 * 255])
Beispiel #4
0
    def __init__(self, data_paths, num_shards, batch_size, num_threads,
                 device_id, prefetch, fp16, random_shuffle, nhwc,
                 dont_use_mmap, decoder_type, decoder_cache_params,
                 reader_queue_depth, shard_id):
        super(CommonPipeline, self).__init__(batch_size,
                                             num_threads,
                                             device_id,
                                             random_shuffle,
                                             prefetch_queue_depth=prefetch)
        if decoder_type == 'roi':
            print('Using nvJPEG with ROI decoding')
            self.decode_gpu = ops.ImageDecoderRandomCrop(device="mixed",
                                                         output_type=types.RGB)
            self.res = ops.Resize(device="gpu", resize_x=224, resize_y=224)
        elif decoder_type == 'roi_split':
            print('Using nvJPEG with ROI decoding and split CPU/GPU stages')
            self.decode_gpu = ops.ImageDecoderRandomCrop(device="mixed",
                                                         output_type=types.RGB,
                                                         split_stages=True)
            self.res = ops.Resize(device="gpu", resize_x=224, resize_y=224)
        elif decoder_type == 'cached':
            assert decoder_cache_params['cache_enabled'] == True
            cache_size = decoder_cache_params['cache_size']
            cache_threshold = decoder_cache_params['cache_threshold']
            cache_type = decoder_cache_params['cache_type']
            print(
                'Using nvJPEG with cache (size : {} threshold: {}, type: {})'.
                format(cache_size, cache_threshold, cache_type))
            self.decode_gpu = ops.ImageDecoder(device="mixed",
                                               output_type=types.RGB,
                                               cache_size=cache_size,
                                               cache_threshold=cache_threshold,
                                               cache_type=cache_type,
                                               cache_debug=False)
            self.res = ops.RandomResizedCrop(device="gpu", size=(224, 224))
        elif decoder_type == 'split':
            print('Using nvJPEG with split CPU/GPU stages')
            self.decode_gpu = ops.ImageDecoder(device="mixed",
                                               output_type=types.RGB,
                                               split_stages=True)
            self.res = ops.RandomResizedCrop(device="gpu", size=(224, 224))
        else:
            print('Using nvJPEG')
            self.decode_gpu = ops.ImageDecoder(device="mixed",
                                               output_type=types.RGB)
            self.res = ops.RandomResizedCrop(device="gpu", size=(224, 224))

        layout = types.NHWC if nhwc else types.NCHW
        out_type = types.FLOAT16 if fp16 else types.FLOAT

        self.cmnp = ops.CropMirrorNormalize(
            device="gpu",
            dtype=out_type,
            output_layout=layout,
            crop=(224, 224),
            mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
            std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
        self.coin = ops.random.CoinFlip(probability=0.5)
Beispiel #5
0
    def __init__(self, batch_size, num_threads, path, training, annotations, world, device_id, mean, std, resize,
                 max_size, stride, rotate_augment=False,
                 augment_brightness=0.0,
                 augment_contrast=0.0, augment_hue=0.0,
                 augment_saturation=0.0):
        super().__init__(batch_size=batch_size, num_threads=num_threads, device_id=device_id,
                         prefetch_queue_depth=num_threads, seed=42)
        self.path = path
        self.training = training
        self.stride = stride
        self.iter = 0

        self.rotate_augment = rotate_augment
        self.augment_brightness = augment_brightness
        self.augment_contrast = augment_contrast
        self.augment_hue = augment_hue
        self.augment_saturation = augment_saturation

        self.reader = ops.COCOReader(annotations_file=annotations, file_root=path, num_shards=world,
                                     shard_id=torch.cuda.current_device(),
                                     ltrb=True, ratio=True, shuffle_after_epoch=True, save_img_ids=True)

        self.decode_train = ops.ImageDecoderSlice(device="mixed", output_type=types.RGB)
        self.decode_infer = ops.ImageDecoder(device="mixed", output_type=types.RGB)
        self.bbox_crop = ops.RandomBBoxCrop(device='cpu', ltrb=True, scaling=[0.3, 1.0],
                                            thresholds=[0.1, 0.3, 0.5, 0.7, 0.9])

        self.bbox_flip = ops.BbFlip(device='cpu', ltrb=True)
        self.img_flip = ops.Flip(device='gpu')
        self.coin_flip = ops.CoinFlip(probability=0.5)
        self.bc = ops.BrightnessContrast(device='gpu')
        self.hsv = ops.Hsv(device='gpu')

        # Random number generation for augmentation
        self.brightness_dist = ops.NormalDistribution(mean=1.0, stddev=augment_brightness)
        self.contrast_dist = ops.NormalDistribution(mean=1.0, stddev=augment_contrast)
        self.hue_dist = ops.NormalDistribution(mean=0.0, stddev=augment_hue)
        self.saturation_dist = ops.NormalDistribution(mean=1.0, stddev=augment_saturation)

        if rotate_augment:
            raise RuntimeWarning("--augment-rotate current has no effect when using the DALI data loader.")

        if isinstance(resize, list): resize = max(resize)
        self.rand_resize = ops.Uniform(range=[resize, float(max_size)])

        self.resize_train = ops.Resize(device='gpu', interp_type=types.DALIInterpType.INTERP_CUBIC, save_attrs=True)
        self.resize_infer = ops.Resize(device='gpu', interp_type=types.DALIInterpType.INTERP_CUBIC,
                                       resize_longer=max_size, save_attrs=True)

        padded_size = max_size + ((self.stride - max_size % self.stride) % self.stride)

        self.pad = ops.Paste(device='gpu', fill_value=0, ratio=1.1, min_canvas_size=padded_size, paste_x=0, paste_y=0)
        self.normalize = ops.CropMirrorNormalize(device='gpu', mean=mean, std=std, crop=(padded_size, padded_size),
                                                 crop_pos_x=0, crop_pos_y=0)
Beispiel #6
0
    def __init__(self,
                 batch_size,
                 num_threads,
                 device_id,
                 csv_path,
                 data_path,
                 valid=False,
                 nfold=0):
        super(DALIPipeline, self).__init__(batch_size, num_threads, device_id)
        self.data_path = data_path
        self.csv_file = csv_path
        self.valid = valid
        self.data = pd.read_csv(self.csv_file)

        if nfold > 0:
            self.data = self.data.sort_values(by=['image', 'label'])
            self.data = self.data.sample(frac=1,
                                         random_state=0).reset_index(drop=True)
            len_fold = int(len(self.data) / nfold)
            if valid:
                self.data = self.data[len_fold *
                                      (nfold - 1):].reset_index(drop=True)
            else:
                self.data = self.data[:len_fold *
                                      (nfold - 1)].reset_index(drop=True)
        self.data.to_csv('data/dali.txt', header=False, index=False, sep=' ')

        self.input = ops.FileReader(file_root=data_path,
                                    file_list='data/dali.txt')
        self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
        self.random_resize = ops.Resize(device="gpu",
                                        image_type=types.RGB,
                                        interp_type=types.INTERP_LINEAR)
        self.resize = ops.Resize(device="gpu",
                                 image_type=types.RGB,
                                 interp_type=types.INTERP_LINEAR,
                                 resize_x=227.,
                                 resize_y=227.)
        self.cmn = ops.CropMirrorNormalize(device="gpu",
                                           output_dtype=types.FLOAT,
                                           crop=(227, 227),
                                           image_type=types.RGB,
                                           mean=[128., 128., 128.],
                                           std=[1., 1., 1.])
        self.normalize = ops.NormalizePermute(device="gpu",
                                              height=227,
                                              width=227,
                                              image_type=types.RGB,
                                              mean=[128., 128., 128.],
                                              std=[1., 1., 1.])
        self.uniform = ops.Uniform(range=(0.0, 1.0))
        self.resize_rng = ops.Uniform(range=(256, 480))
    def __init__(self, device_id, shard_id, num_shards, size, crop, options):
        super(ValPipeline, self).__init__(options.batchsize,
                                          options.dataloader_workers,
                                          device_id,
                                          seed=12 + device_id)
        self.input = ops.FileReader(file_root=options.val_dir,
                                    shard_id=shard_id,
                                    num_shards=num_shards,
                                    random_shuffle=False,
                                    pad_last_batch=True)

        self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
        self.res = ops.Resize(device="gpu",
                              resize_shorter=size,
                              interp_type=types.INTERP_TRIANGULAR)
        dtype = types.FLOAT16 if options.fp16 else types.FLOAT
        layout = types.NCHW
        img_mean, img_std = get_mean_std(options)
        self.cmnp = ops.CropMirrorNormalize(device="gpu",
                                            output_dtype=dtype,
                                            output_layout=layout,
                                            crop=(crop, crop),
                                            image_type=types.RGB,
                                            mean=img_mean,
                                            std=img_std,
                                            pad_output=False)
Beispiel #8
0
def build_train_and_test_transforms():
    """Returns torchvision OR nvidia-dali transforms.

    :returns: train_transforms, test_transforms
    :rtype: list, list

    """
    resize_shape = (args.image_size_override, args.image_size_override)

    if 'dali' in args.task:
        # Lazy import DALI dependencies because debug cpu nodes might not have DALI.
        import nvidia.dali.ops as ops
        import nvidia.dali.types as types
        from datasets.dali_imagefolder import ColorJitter, RandomHorizontalFlip, RandomGrayScale

        train_transform = [
            ops.RandomResizedCrop(device="gpu" if args.cuda else "cpu",
                                  size=resize_shape,
                                  random_area=(0.08, 1.0),
                                  random_aspect_ratio=(3. / 4, 4. / 3)),
            RandomHorizontalFlip(prob=0.2, cuda=args.cuda),
            ColorJitter(brightness=0.8 * args.color_jitter_strength,
                        contrast=0.8 * args.color_jitter_strength,
                        saturation=0.2 * args.color_jitter_strength,
                        hue=0.2 * args.color_jitter_strength,
                        prob=0.8,
                        cuda=args.cuda),
            RandomGrayScale(prob=0.2, cuda=args.cuda)
            # TODO: Gaussian-blur
        ]
        test_transform = [
            ops.Resize(resize_x=resize_shape[0],
                       resize_y=resize_shape[1],
                       device="gpu" if args.cuda else "cpu",
                       image_type=types.RGB,
                       interp_type=types.INTERP_LINEAR)
        ]
    else:
        from datasets.utils import GaussianBlur

        train_transform = [
            # transforms.CenterCrop(first_center_crop_size),
            transforms.RandomResizedCrop(
                (args.image_size_override, args.image_size_override)),
            transforms.RandomHorizontalFlip(p=0.5),
            transforms.RandomApply([
                transforms.ColorJitter(
                    brightness=0.8 * args.color_jitter_strength,
                    contrast=0.8 * args.color_jitter_strength,
                    saturation=0.8 * args.color_jitter_strength,
                    hue=0.2 * args.color_jitter_strength)
            ],
                                   p=0.8),
            transforms.RandomGrayscale(p=0.2),
            GaussianBlur(kernel_size=int(0.1 * args.image_size_override),
                         p=0.5)
        ]
        test_transform = [transforms.Resize(resize_shape)]

    return train_transform, test_transform
Beispiel #9
0
 def __init__(self, batch_size, num_threads, device_id = 0, seed = 0):
     super(TestPipeline, self).__init__(batch_size, num_threads, device_id, seed)
     self.input = ops.COCOReader(
         file_root = file_root,
         annotations_file = annotations_file,
         shard_id = 0, 
         num_shards = 1, 
         ratio=False, 
         save_img_ids=True)
     self.decode = ops.ImageDecoder(device = "cpu", output_type = types.RGB)
     self.resize = ops.Resize(
         device = "cpu",
         image_type = types.RGB,
         interp_type = types.INTERP_LINEAR)
     self.cmn = ops.CropMirrorNormalize(
         device = "cpu",
         output_dtype = types.FLOAT,
         crop = (224, 224),
         image_type = types.RGB,
         mean = [128., 128., 128.],
         std = [1., 1., 1.])
     self.res_uniform = ops.Uniform(range = (256.,480.))
     self.uniform = ops.Uniform(range = (0.0, 1.0))
     self.cast = ops.Cast(
         device = "cpu",
         dtype = types.FLOAT16)
Beispiel #10
0
        def __init__(self, batch_size, num_threads, device_id, data_dir,
                     crop, size, dali_cpu=False):
            super(DALIValPipe, self).__init__(
                batch_size, num_threads, device_id, seed=12 + device_id
            )
            self.input = ops.FileReader(
                file_root=data_dir, shard_id=device_id,
                num_shards=1, random_shuffle=True
            )
            #let user decide which pipeline works him bets for RN version he runs
            if dali_cpu:
                dali_device = "cpu"
                self.decode = ops.HostDecoder(
                    device=dali_device, output_type=types.RGB)
            else:
                dali_device = "gpu"
                # This padding sets the size of the internal nvJPEG buffers to be
                # able to handle all images from full-sized ImageNet
                # without additional reallocations
                self.decode = ops.nvJPEGDecoder(
                    device="mixed", output_type=types.RGB,
                    device_memory_padding=211025920, host_memory_padding=140544512
                )

            self.res = ops.Resize(
                device=dali_device, resize_shorter=size)
            self.cmnp = ops.CropMirrorNormalize(
                device="gpu",
                output_dtype=types.FLOAT,
                output_layout=types.NCHW,
                crop=(crop, crop),
                image_type=types.RGB,
                mean=[0.485 * 255,0.456 * 255,0.406 * 255],
                std=[0.229 * 255,0.224 * 255,0.225 * 255])
            print('DALI "{0}" variant'.format(dali_device))
Beispiel #11
0
    def __init__(self, batch_size, num_threads, device_id, data_dir, crop,
                 size):
        super(HybridValPipe, self).__init__(batch_size,
                                            num_threads,
                                            device_id,
                                            seed=12 + device_id)
        if torch.distributed.is_initialized():
            local_rank = torch.distributed.get_rank()
            world_size = torch.distributed.get_world_size()
        else:
            local_rank = 0
            world_size = 1

        self.input = ops.FileReader(file_root=data_dir,
                                    shard_id=local_rank,
                                    num_shards=world_size,
                                    random_shuffle=False)

        self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB)
        self.res = ops.Resize(device="gpu", resize_shorter=size)
        self.cmnp = ops.CropMirrorNormalize(
            device="gpu",
            output_dtype=types.FLOAT,
            output_layout=types.NCHW,
            crop=(crop, crop),
            image_type=types.RGB,
            mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
            std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
Beispiel #12
0
class HybridPipe(Pipeline):
    def __init__(self,
                 batch_size,
                 num_threads,
                 device_id,
                 pipelined=True,
                 async=True):
        super(HybridPipe, self).__init__(batch_size,
                                         num_threads,
                                         device_id,
                                         exec_pipelined=pipelined,
                                         exec_async=async)
        self.input = ops.ExternalSource()
        self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB)
        self.resize = ops.Resize(device="gpu",
                                 image_type=types.RGB,
                                 interp_type=types.INTERP_LINEAR)
        self.cmnp = ops.CropMirrorNormalize(device="gpu",
                                            output_dtype=types.FLOAT16,
                                            crop=(224, 224),
                                            image_type=types.RGB,
                                            mean=[128., 128., 128.],
                                            std=[1., 1., 1.])
        self.uniform = ops.Uniform(range=(0., 1.))
        self.resize_uniform = ops.Uniform(range=(256., 480.))
        self.mirror = ops.CoinFlip(probability=0.5)
        self.iter = 0
Beispiel #13
0
 def __init__(self, batch_size, num_threads, device_id, data_dir, crop, dali_cpu=False):
     super(HybridTrainPipe, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id)
     self.input = ops.FileReader(file_root=data_dir, shard_id=args.local_rank, num_shards=args.world_size, random_shuffle=True)
     #let user decide which pipeline works him bets for RN version he runs
     dali_device = 'cpu' if dali_cpu else 'gpu'
     decoder_device = 'cpu' if dali_cpu else 'mixed'
     # This padding sets the size of the internal nvJPEG buffers to be able to handle all images from full-sized ImageNet
     # without additional reallocations
     device_memory_padding = 211025920 if decoder_device == 'mixed' else 0
     host_memory_padding = 140544512 if decoder_device == 'mixed' else 0
     self.decode = ops.ImageDecoderRandomCrop(device=decoder_device, output_type=types.RGB,
                                              device_memory_padding=device_memory_padding,
                                              host_memory_padding=host_memory_padding,
                                              random_aspect_ratio=[0.8, 1.25],
                                              random_area=[0.1, 1.0],
                                              num_attempts=100)
     self.res = ops.Resize(device=dali_device, resize_x=crop, resize_y=crop, interp_type=types.INTERP_TRIANGULAR)
     self.cmnp = ops.CropMirrorNormalize(device="gpu",
                                         output_dtype=types.FLOAT,
                                         output_layout=types.NCHW,
                                         crop=(crop, crop),
                                         image_type=types.RGB,
                                         mean=[0.485 * 255,0.456 * 255,0.406 * 255],
                                         std=[0.229 * 255,0.224 * 255,0.225 * 255])
     self.coin = ops.CoinFlip(probability=0.5)
Beispiel #14
0
 def __init__(self,
              batch_size,
              num_threads,
              device,
              device_id=0,
              shard_id=0,
              num_shards=1,
              seed=0):
     super(TestPipeline, self).__init__(batch_size, num_threads, device_id,
                                        seed)
     self.device = device
     self.input = ops.COCOReader(file_root=file_root,
                                 annotations_file=annotations_file,
                                 shard_id=shard_id,
                                 num_shards=num_shards,
                                 ratio=False,
                                 save_img_ids=True)
     self.decode = ops.ImageDecoder(
         device='mixed' if device is 'gpu' else 'cpu',
         output_type=types.RGB)
     self.resize = ops.Resize(device=device,
                              image_type=types.RGB,
                              resize_x=224,
                              resize_y=224,
                              interp_type=types.INTERP_LINEAR)
     self.cmn = ops.CropMirrorNormalize(device=device,
                                        output_dtype=types.FLOAT,
                                        image_type=types.RGB,
                                        mean=[128., 128., 128.],
                                        std=[1., 1., 1.])
     self.cast = ops.Cast(device=device, dtype=types.INT16)
Beispiel #15
0
 def __init__(self, params, device_id, files, labels):
     super().__init__(params.batch_size,
                      params.num_gpus * 8,
                      device_id,
                      seed=params.seed)
     # file_root有坑,并不是文件夹名字就是label,按照文件夹顺序(1, 10, 11, 2, 20, 21, ...)分别给与0,1,2,3,4...标签
     self.input = ops.FileReader(files=files,
                                 labels=labels,
                                 random_shuffle=True)
     self.decocer = ops.ImageDecoder(device='mixed', output_type=types.RGB)
     self.resize = ops.Resize(device='gpu', resize_shorter=224)
     self.pos_rng_x = ops.random.Uniform(range=(0.0, 1.0))
     self.pos_rng_y = ops.random.Uniform(range=(0.0, 1.0))
     self.crop = ops.Crop(device='gpu', crop_h=224, crop_w=224)
     self.flip = ops.Flip(device='gpu')
     self.coinflip = ops.random.CoinFlip(probability=0.5)
     self.hsv = ops.Hsv(device='gpu')
     self.saturation = ops.random.Uniform(range=(0.8, 1.0))
     self.value = ops.random.Uniform(range=(0.8, 1.0))
     mean = torch.Tensor(params.mean).unsqueeze(0).unsqueeze(0) * 255
     std = torch.Tensor(params.std).unsqueeze(0).unsqueeze(0) * 255
     self.normalize = ops.Normalize(axes=[0, 1],
                                    mean=mean,
                                    stddev=std,
                                    device='gpu',
                                    batch=False)
     self.transpose = ops.Transpose(device='gpu', perm=[2, 0, 1])
Beispiel #16
0
 def __init__(self,
              batch_size,
              num_threads,
              device_id,
              data_dir="./",
              dali_cpu=False):
     super(DecodeCropResizePipeline, self).__init__(batch_size,
                                                    num_threads,
                                                    device_id,
                                                    seed=12)
     self.input = ops.FileReader(file_root=data_dir, random_shuffle=True)
     if dali_cpu:
         decoder_device = "cpu"
     else:
         decoder_device = "mixed"
     device_memory_padding = 211025920 if decoder_device == 'mixed' else 0
     host_memory_padding = 140544512 if decoder_device == 'mixed' else 0
     dali_device = "cpu" if dali_cpu else "gpu"
     self.decode = ops.ImageDecoderRandomCrop(
         device=decoder_device,
         output_type=types.RGB,
         device_memory_padding=device_memory_padding,
         host_memory_padding=host_memory_padding,
         random_aspect_ratio=[0.8, 1.25],
         random_area=[0.1, 1.0],
         num_attempts=100)
     self.res = ops.Resize(device=dali_device,
                           resize_x=224,
                           resize_y=224,
                           interp_type=types.INTERP_TRIANGULAR)
Beispiel #17
0
    def __init__(self, device, batch_size, num_threads=1, device_id=0):
        super(MultichannelPipeline, self).__init__(batch_size, num_threads,
                                                   device_id)
        self.device = device

        self.reader = ops.FileReader(file_root=multichannel_tiff_root)

        decoder_device = 'mixed' if self.device == 'gpu' else 'cpu'
        self.decoder = ops.ImageDecoder(device=decoder_device,
                                        output_type=types.ANY_DATA)

        self.resize = ops.Resize(device=self.device,
                                 resize_y=900,
                                 resize_x=300,
                                 min_filter=types.DALIInterpType.INTERP_LINEAR)

        self.crop = ops.Crop(device=self.device,
                             crop_h=220,
                             crop_w=224,
                             crop_pos_x=0.3,
                             crop_pos_y=0.2,
                             image_type=types.ANY_DATA)

        self.transpose = ops.Transpose(device=self.device,
                                       perm=(1, 0, 2),
                                       transpose_layout=False)

        self.cmn = ops.CropMirrorNormalize(device=self.device,
                                           std=255.,
                                           mean=0.,
                                           output_layout="HWC",
                                           output_dtype=types.FLOAT)
Beispiel #18
0
 def __init__(self, device, batch_size, layout, iterator, num_threads=1, device_id=0, tested_operator = None):
     super(MultichannelSynthPipeline, self).__init__(batch_size,
                                                     num_threads,
                                                     device_id)
     self.device = device
     self.layout = layout
     self.iterator = iterator
     self.inputs = ops.ExternalSource()
     self.tested_operator = tested_operator
     if self.tested_operator == 'resize' or not self.tested_operator:
         self.resize = ops.Resize(device = self.device,
                                  resize_y = 900,
                                  resize_x = 300,
                                  min_filter=types.DALIInterpType.INTERP_LINEAR)
     if self.tested_operator == 'crop' or not self.tested_operator:
         self.crop = ops.Crop(device = self.device,
                              crop = (220, 224),
                              crop_pos_x = 0.3,
                              crop_pos_y = 0.2)
     if self.tested_operator == 'transpose' or not self.tested_operator:
         self.transpose = ops.Transpose(device = self.device,
                                        perm = (1, 0, 2),
                                        transpose_layout = False)
     if self.tested_operator == 'normalize' or not self.tested_operator:
         self.cmn = ops.CropMirrorNormalize(device = self.device,
                                            std = 255.,
                                            mean = 0.,
                                            output_layout = "HWC",
                                            dtype = types.FLOAT)
Beispiel #19
0
    def __init__(self, batch_size: int, num_threads: int, device_id: int,
                 sequence_length: int, initial_prefetch_size: int, data: List,
                 shuffle: bool):
        """
        :param batch_size: size of dataset batch
        :param num_threads: number of parallel threads
        :param device_id: "gpu" or "cpu"
        :param sequence_length: number of frames
        :param initial_prefetch_size: count of videos readed preliminarily
        :param data: input video paths
        :param shuffle: suffle samples
        """
        super().__init__(batch_size, num_threads, device_id, seed=16)
        self.input = ops.VideoReader(device="gpu",
                                     filenames=data,
                                     sequence_length=sequence_length,
                                     shard_id=0,
                                     num_shards=1,
                                     random_shuffle=shuffle,
                                     initial_fill=initial_prefetch_size)

        self.extract = ops.ElementExtract(device="gpu",
                                          element_map=list(
                                              range(0, FRAMES_PER_VIDEO)))

        self.resize = ops.Resize(device="gpu",
                                 resize_x=config.IMG_SIZE,
                                 resize_y=config.IMG_SIZE)
Beispiel #20
0
    def __init__(self,
                 imageset_dir,
                 image_size=128,
                 random_shuffle=False,
                 batch_size=64,
                 num_threads=2,
                 device_id=0):
        super(ImagePipeline, self).__init__(batch_size,
                                            num_threads,
                                            device_id,
                                            seed=12)
        eii = ExternalInputIterator(imageset_dir, batch_size, random_shuffle)
        self.iterator = iter(eii)
        self.num_inputs = len(eii.frontal_indices)

        # The source for the inputs and targets
        self.input = ops.ExternalSource()
        self.target = ops.ExternalSource()

        # nvJPEGDecoder below accepts  CPU inputs, but returns GPU outputs (hence device = "mixed")
        self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB)

        # The rest of pre-processing is done on the GPU
        self.res = ops.Resize(device="gpu",
                              resize_x=image_size,
                              resize_y=image_size)
        self.norm = ops.NormalizePermute(device="gpu",
                                         output_dtype=types.FLOAT,
                                         mean=[128., 128., 128.],
                                         std=[128., 128., 128.],
                                         height=image_size,
                                         width=image_size)
Beispiel #21
0
 def __init__(self,
              device,
              batch_size,
              relative,
              use_wildcard,
              num_threads=3,
              device_id=0,
              num_gpus=1):
     super(ReshapePipeline, self).__init__(batch_size,
                                           num_threads,
                                           device_id,
                                           seed=7865,
                                           exec_async=True,
                                           exec_pipelined=True)
     self.device = device
     self.input = ops.readers.Caffe(path=caffe_db_folder,
                                    shard_id=device_id,
                                    num_shards=num_gpus)
     self.decode = ops.ImageDecoder(device="cpu", output_type=types.RGB)
     W = 320
     H = 224
     self.resize = ops.Resize(device="cpu", resize_x=W, resize_y=H)
     WC = -1 if use_wildcard else W * 3
     if relative:
         rel_shape = (-1, 3) if use_wildcard else (1, 3)
         self.reshape = ops.Reshape(device=device,
                                    rel_shape=rel_shape,
                                    layout="ab")
     else:
         self.reshape = ops.Reshape(device=device,
                                    shape=(H, WC),
                                    layout="ab")
Beispiel #22
0
    def __init__(self,
                 root,
                 split,
                 batch_size,
                 device_id,
                 dali_cpu=False,
                 local_rank=0,
                 world_size=1,
                 num_workers=2,
                 augment=False,
                 resize=False,
                 resize_size=314,
                 crop=True,
                 crop_size=314,
                 shuffle=True,
                 flip=True,
                 rotate=False,
                 rotate_angle=10.0):
        super(VOCDali, self).__init__(batch_size,
                                      num_threads=num_workers,
                                      device_id=device_id,
                                      seed=12 + device_id)
        self.iterator = iter(VOCIter(batch_size, split, root, shuffle))
        self.split = split
        assert self.split in ['train', 'val']
        dali_device = "gpu" if not dali_cpu else "cpu"
        self.input = ops.ExternalSource()
        self.input_label = ops.ExternalSource()

        self.is_flip = flip
        self.is_rotate = rotate
        self.is_augment = augment
        self.is_crop = crop
        self.is_resize = resize

        self.decode = ops.ImageDecoder(device='mixed', output_type=types.RGB)
        # self.cast = ops.Cast(device='gpu', dtype=types.INT32)
        self.rng = ops.Uniform(range=(0., 1.))
        self.coin = ops.CoinFlip(probability=0.5)
        # 定义大小
        self.resize = ops.Resize(device="gpu",
                                 resize_x=resize_size,
                                 resize_y=resize_size,
                                 interp_type=types.INTERP_TRIANGULAR)
        # 定义旋转
        self.rotate = ops.Rotate(device="gpu", angle=rotate_angle)
        # 定义翻转
        self.flip = ops.Flip(device="gpu", vertical=1, horizontal=0)
        # 定义剪裁
        self.crop = ops.Crop(device=dali_device,
                             crop_h=crop_size,
                             crop_w=crop_size)
        # 定义正则化
        self.cmnp = ops.CropMirrorNormalize(
            device=dali_device,
            output_dtype=types.FLOAT,
            output_layout=types.NCHW,
            image_type=types.RGB,
            mean=[0.45734706 * 255, 0.43338275 * 255, 0.40058118 * 255],
            std=[0.23965294 * 255, 0.23532275 * 255, 0.2398498 * 255])
    def __init__(self, cfg):
        super(ClsTrainPipe,
              self).__init__(batch_size=cfg.dataset.loader.batch_size,
                             num_threads=cfg.dataset.loader.num_workers,
                             device_id=cfg.device.local_rank)

        self.eii = ClsInputIterator(cfg=cfg, is_train=True)
        self.source = ops.ExternalSource(source=self.eii, num_outputs=2)

        self.decode = ops.ImageDecoderRandomCrop(
            device='mixed',
            output_type=types.RGB,
            random_aspect_ratio=[0.8, 1.25],
            random_area=[0.3, 1.0],
            num_attempts=100)
        self.rotate = ops.Rotate(device='gpu', fill_value=127.5)
        self.res = ops.Resize(device='gpu',
                              resize_x=cfg.dataset.transform.image_size,
                              resize_y=cfg.dataset.transform.image_size,
                              interp_type=types.INTERP_TRIANGULAR)
        self.cmnp = ops.CropMirrorNormalize(
            device='gpu',
            dtype=types.FLOAT,
            output_layout=types.NCHW,
            crop=(cfg.dataset.transform.image_size,
                  cfg.dataset.transform.image_size),
            mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
            std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
        self.coin = ops.CoinFlip(probability=0.5)
        self.angle = ops.Uniform(
            range=(-1 * cfg.dataset.transform.max_rotate_angle,
                   cfg.dataset.transform.max_rotate_angle))
Beispiel #24
0
 def __init__(self,
              batch_size,
              num_threads,
              shard_id,
              image_dir,
              file_list,
              nvjpeg_padding,
              seed=1,
              num_shards=1,
              channel_last=True,
              dtype='half',
              pad_output=False):
     super(ValPipeline, self).__init__(batch_size,
                                       num_threads,
                                       shard_id,
                                       seed=seed)
     self.input = ops.FileReader(file_root=image_dir,
                                 file_list=file_list,
                                 random_shuffle=False,
                                 num_shards=num_shards,
                                 shard_id=shard_id)
     self.decode = ops.ImageDecoder(device="mixed",
                                    output_type=types.RGB,
                                    device_memory_padding=nvjpeg_padding,
                                    host_memory_padding=nvjpeg_padding)
     self.res = ops.Resize(device="gpu", resize_shorter=256)
     self.cmnp = ops.CropMirrorNormalize(
         device="gpu",
         output_dtype=types.FLOAT16 if dtype == "half" else types.FLOAT,
         output_layout=types.NHWC if channel_last else types.NCHW,
         crop=(224, 224),
         image_type=types.RGB,
         mean=_pixel_mean,
         std=_pixel_std,
         pad_output=pad_output)
Beispiel #25
0
 def __init__(self,
              batch_size,
              num_threads,
              device_id,
              image_dir,
              file_list,
              seed=1,
              num_gpu=1):
     super(ValPipeline, self).__init__(batch_size,
                                       num_threads,
                                       device_id,
                                       seed=seed)
     self.input = ops.FileReader(file_root=image_dir,
                                 file_list=file_list,
                                 random_shuffle=False,
                                 num_shards=num_gpu,
                                 shard_id=0)
     self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB)
     self.res = ops.Resize(device="gpu", resize_shorter=256)
     self.cmnp = ops.CropMirrorNormalize(
         device="gpu",
         output_dtype=types.FLOAT,
         output_layout=types.NCHW,
         crop=(224, 224),
         image_type=types.RGB,
         mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
         std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
 def __init__(self, iterator, batch_size, num_threads, device_id):
     super().__init__(batch_size, num_threads, device_id, seed=12)
     self.iterator = iterator
     self.input = ops.ExternalSource()
     self.input_label = ops.ExternalSource()
     self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
     self.res = ops.Resize(device="gpu", resize_x=224, resize_y=224, interp_type=types.INTERP_TRIANGULAR)
 def __init__(self, batch_size, num_threads, device_id, data_dir, crop, size):
     super(HybridValPipe, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id)
     # self.input = ops.FileReader(file_root=data_dir, shard_id=args.local_rank, num_shards=args.world_size, random_shuffle=False)
     index_path = []
     for path in os.listdir("/home/guojia/idx_files/val"):
         index_path.append(os.path.join("/home/guojia/idx_files/val", path))
     index_path = sorted(index_path)
     self.input = ops.TFRecordReader(path=data_dir, index_path=index_path, shard_id=args.local_rank,
                                     num_shards=args.world_size, random_shuffle=True,
                                     features={
                                         'image/height': tfrec.FixedLenFeature([1], tfrec.int64, -1),
                                         'image/width': tfrec.FixedLenFeature([1], tfrec.int64, -1),
                                         'image/colorspace': tfrec.FixedLenFeature([], tfrec.string, ''),
                                         'image/channels': tfrec.FixedLenFeature([], tfrec.int64, -1),
                                         'image/class/label': tfrec.FixedLenFeature([1], tfrec.int64, -1),
                                         'image/class/synset': tfrec.FixedLenFeature([], tfrec.string, ''),
                                         'image/format': tfrec.FixedLenFeature((), tfrec.string, ""),
                                         'image/filename': tfrec.FixedLenFeature((), tfrec.string, ""),
                                         'image/encoded': tfrec.FixedLenFeature((), tfrec.string, "")
                                     })
     self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
     self.res = ops.Resize(device="gpu", resize_shorter=size, interp_type=types.INTERP_TRIANGULAR)
     self.cmnp = ops.CropMirrorNormalize(device="gpu",
                                         output_dtype=types.FLOAT,
                                         output_layout=types.NCHW,
                                         crop=(crop, crop),
                                         image_type=types.RGB,
                                         mean=[0.485 * 255,0.456 * 255,0.406 * 255],
                                         std=[0.229 * 255,0.224 * 255,0.225 * 255])
Beispiel #28
0
    def __init__(self, args, batch_size, num_threads, device_id, rec_path, idx_path,
                 shard_id, num_shards, crop_shape, nvjpeg_padding, prefetch_queue=3, resize_shp=None,
                 output_layout=types.NCHW, pad_output=True, dtype='float16', dali_cpu=False,
                 nvjpeg_width_hint=5980, nvjpeg_height_hint=6430):
        super(HybridValPipe, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id, prefetch_queue_depth=prefetch_queue)
        self.input = ops.MXNetReader(path=[rec_path], index_path=[idx_path],
                                     random_shuffle=False, shard_id=shard_id, num_shards=num_shards,
                                     dont_use_mmap=args.dali_dont_use_mmap)

        if dali_cpu:
            dali_device = "cpu"
            decoder_device = "cpu"
        else:
            dali_device = "gpu"
            decoder_device = "mixed"

        dali_kwargs_fallback = {}
        if Version(dali.__version__) >= Version("1.2.0"):
            dali_kwargs_fallback = {
                "preallocate_width_hint": nvjpeg_width_hint,
                "preallocate_height_hint": nvjpeg_height_hint
            }

        self.decode = ops.ImageDecoder(device=decoder_device, output_type=types.RGB,
                                       device_memory_padding=nvjpeg_padding,
                                       host_memory_padding=nvjpeg_padding,
                                       **dali_kwargs_fallback)
        self.resize = ops.Resize(device=dali_device, resize_shorter=resize_shp) if resize_shp else None
        self.cmnp = ops.CropMirrorNormalize(device="gpu",
                                            output_dtype=types.FLOAT16 if dtype == 'float16' else types.FLOAT,
                                            output_layout=output_layout, crop=crop_shape, pad_output=pad_output,
                                            image_type=types.RGB, mean=args.rgb_mean, std=args.rgb_std)
 def __init__(self,
              batch_size,
              num_threads,
              device_id,
              data_dir,
              crop,
              size,
              local_rank=0,
              world_size=1):
     super(HybridValPipe, self).__init__(batch_size,
                                         num_threads,
                                         device_id,
                                         seed=12 + device_id)
     self.input = ops.FileReader(file_root=data_dir,
                                 shard_id=local_rank,
                                 num_shards=world_size,
                                 random_shuffle=False)
     self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
     self.res = ops.Resize(device="gpu",
                           resize_shorter=size,
                           interp_type=types.INTERP_TRIANGULAR)
     self.cmnp = ops.CropMirrorNormalize(
         device="gpu",
         output_dtype=types.FLOAT,
         output_layout=types.NCHW,
         crop=(crop, crop),
         image_type=types.RGB,
         mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
         std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
    def __init__(self,
                 batch_size,
                 num_threads,
                 device_id,
                 record_dir,
                 crop,
                 size,
                 num_gpus,
                 dali_cpu=False):
        super(HybridValPipe, self).__init__(batch_size,
                                            num_threads,
                                            device_id,
                                            seed=12 + device_id)
        self.input = ops.MXNetReader(path=[join(record_dir, "val.rec")],
                                     index_path=[join(record_dir, "val.idx")],
                                     random_shuffle=False,
                                     shard_id=device_id,
                                     num_shards=num_gpus)

        self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
        self.res = ops.Resize(device="gpu",
                              resize_shorter=size,
                              interp_type=types.INTERP_CUBIC)
        self.cmnp = ops.CropMirrorNormalize(
            device="gpu",
            output_dtype=types.FLOAT,
            output_layout=types.NCHW,
            crop=(crop, crop),
            image_type=types.RGB,
            mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
            std=[0.229 * 255, 0.224 * 255, 0.225 * 255])