def zoom_fn(self, img, lbl): scale = self.random_augmentation(0.15, fn.random.uniform(range=(0.7, 1.0)), 1.0) d, h, w = [scale * x for x in self.patch_size] if self.dim == 2: d = self.patch_size[0] img, lbl = fn.crop(img, crop_h=h, crop_w=w, crop_d=d), fn.crop(lbl, crop_h=h, crop_w=w, crop_d=d) img = fn.resize(img, interp_type=types.DALIInterpType.INTERP_CUBIC, size=self.crop_shape_float) lbl = fn.resize(lbl, interp_type=types.DALIInterpType.INTERP_NN, size=self.crop_shape_float) return img, lbl
def zoom_fn(self, img, lbl): resized_shape = self.crop_shape * self.random_augmentation( 0.15, fn.uniform(range=(0.7, 1.0)), 1.0) img, lbl = fn.crop(img, crop=resized_shape), fn.crop(lbl, crop=resized_shape) img = fn.resize(img, interp_type=types.DALIInterpType.INTERP_CUBIC, size=self.crop_shape_float) lbl = fn.resize(lbl, interp_type=types.DALIInterpType.INTERP_NN, size=self.crop_shape_float) return img, lbl
def create_decoder_crop_pipeline(data_path, device): jpegs, _ = fn.readers.file(file_root=data_path, shard_id=0, num_shards=1, name="Reader") crop_pos_x = fn.random.uniform(range=[0.1, 0.9]) crop_pos_y = fn.random.uniform(range=[0.1, 0.9]) w = 242 h = 230 images_crop_1 = fn.decoders.image_crop(jpegs, device=device, output_type=types.RGB, hw_decoder_load=0.7, crop=(w, h), crop_pos_x=crop_pos_x, crop_pos_y=crop_pos_y) images = fn.decoders.image(jpegs, device=device, hw_decoder_load=0.7, output_type=types.RGB) images_crop_2 = fn.crop(images, crop=(w, h), crop_pos_x=crop_pos_x, crop_pos_y=crop_pos_y) return images_crop_1, images_crop_2
def get_pipe(): def get_data(): out = [ np.zeros(input_shape, dtype=np.uint8) for _ in range(batch_size) ] return out data = fn.external_source(source=get_data, device=device) return fn.crop(data, crop_h=10, crop_w=20)
def create_dali_pipeline(batch_size, num_threads, device_id, data_dir): files = [] with open(join(data_dir, "file_list.txt"), "r") as f: files = [line.rstrip() for line in f if line is not ''] shuffle(files) img_files = [] seg_files = [] for prefix in files: img_files.append(join(data_dir, "leftImg8bit/train", prefix + "_leftImg8bit.png")) seg_files.append(join(data_dir, "gtFine/train", prefix + "_gtFine_labelIds.png")) pipeline = Pipeline(batch_size, num_threads, device_id, seed=12 + device_id) with pipeline: imgs, _ = fn.file_reader(files=img_files, shard_id=0, num_shards=1, random_shuffle=False, pad_last_batch=True) segs, _ = fn.file_reader(files=seg_files, shard_id=0, num_shards=1, random_shuffle=False, pad_last_batch=True) dali_device = 'gpu' decoder_device = 'mixed' # device_memory_padding = 211025920 if decoder_device == 'mixed' else 0 # host_memory_padding = 140544512 if decoder_device == 'mixed' else 0 device_memory_padding = 0 host_memory_padding = 0 imgs = fn.image_decoder(imgs, device=decoder_device, output_type=types.RGB, device_memory_padding=device_memory_padding, host_memory_padding=host_memory_padding, hybrid_huffman_threshold=250000) segs = fn.image_decoder(segs, device=decoder_device, output_type=types.GRAY, device_memory_padding=device_memory_padding, host_memory_padding=host_memory_padding, hybrid_huffman_threshold=250000) imgs = fn.crop_mirror_normalize(imgs, device=dali_device, crop=(512, 512), dtype=types.FLOAT, mean=[0.485 * 255, 0.456 * 255, 0.406 * 255], std=[0.229 * 255, 0.224 * 255, 0.225 * 255], output_layout="CHW") segs = fn.crop(segs, device=dali_device, dtype=types.UINT8, crop=(512, 512)) pipeline.set_outputs(imgs, segs) return pipeline
def create_video_reader_pipeline(sequence_length, files, crop_size): images = fn.readers.video(device="gpu", filenames=files, sequence_length=sequence_length, normalized=False, random_shuffle=True, image_type=types.RGB, dtype=types.UINT8, initial_fill=16, pad_last_batch=True, name="Reader") images = fn.crop(images, crop=crop_size, dtype=types.FLOAT, crop_pos_x=fn.random.uniform(range=(0.0, 1.0)), crop_pos_y=fn.random.uniform(range=(0.0, 1.0))) images = fn.transpose(images, perm=[3, 0, 1, 2]) return images
def create_video_reader_pipeline(batch_size, sequence_length, num_threads, device_id, files, crop_size): pipeline = Pipeline(batch_size, num_threads, device_id, seed=12) with pipeline: images = fn.video_reader(device="gpu", filenames=files, sequence_length=sequence_length, normalized=False, random_shuffle=True, image_type=types.RGB, dtype=types.UINT8, initial_fill=16, pad_last_batch=True, name="Reader") images = fn.crop(images, crop=crop_size, dtype=types.FLOAT, crop_pos_x=fn.uniform(range=(0.0, 1.0)), crop_pos_y=fn.uniform(range=(0.0, 1.0))) images = fn.transpose(images, perm=[3, 0, 1, 2]) pipeline.set_outputs(images) return pipeline
def crop_fn(self, img, lbl): img = fn.crop(img, crop=self.patch_size) lbl = fn.crop(lbl, crop=self.patch_size) return img, lbl
def crop_fn(self, img, lbl): img = fn.crop(img, crop=self.patch_size, out_of_bounds_policy="pad") lbl = fn.crop(lbl, crop=self.patch_size, out_of_bounds_policy="pad") return img, lbl
def crop(self, data): return fn.crop(data, crop=self.patch_size, out_of_bounds_policy="pad")