in src/sm_augmentation_train-script.py [0:0]
def create_dali_pipeline(data_dir, crop, size, shard_id, num_shards, dali_cpu, is_training, aug_load_factor):
images, labels = fn.readers.file(file_root=data_dir,
shard_id=shard_id,
num_shards=num_shards,
random_shuffle=is_training,
pad_last_batch=True,
name="Reader")
"""
For jpeg images, “mixed” backend uses the nvJPEG library. If hardware is available, operator will use dedicated
hardware decoder. For jpeg images, “cpu” backend uses libjpeg-turbo. Other image formats are decoded with OpenCV
or other specific libraries, such as libtiff.
"""
dali_device = 'cpu' if dali_cpu else 'gpu'
decoder_device = 'cpu' if dali_cpu else 'mixed'
images = fn.decoders.image(images,
device=decoder_device,
output_type=types.RGB,
memory_stats=True)
if is_training:
# Repeating Augmentation to influence bottleneck
for x in range(aug_load_factor):
images = fn.flip(images, device=dali_device, horizontal=1, vertical=1)
images = fn.rotate(images, angle=5, device=dali_device)
images = fn.random_resized_crop(images, size=size, device=dali_device)
images = fn.crop_mirror_normalize(images,
dtype=types.FLOAT,
output_layout="CHW",
crop=(crop, crop),
mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
images = images.gpu()
labels = labels.gpu()
return images, labels