NVIDIA DALI
0.30.0 -ab7489a
Version select:
  • Documentation home

User Guide

  • Installation
    • DALI and NGC
    • Installing prebuilt DALI packages
      • Prerequisites
      • Installation
        • DALI TensorFlow plugin (nvidia-dali-tf-plugin)
    • Pre-built packages in Watson Machine Learing Community Edition
    • Nightly and weekly release channels
      • Nightly builds
      • Weekly builds
  • Compiling DALI from source
    • Compiling DALI from source (using Docker builder) - recommended
      • Prerequisites
      • Building Python wheel and (optionally) Docker image
    • Compiling DALI from source (bare metal)
      • Prerequisites
      • Build DALI
        • Install Python bindings
      • Verify the build (optional)
        • Obtain test data
        • Set test data path
        • Run tests
      • Building DALI using Clang (experimental)
      • Optional CMake build parameters
    • Cross-compiling DALI C++ API for aarch64 Linux (Docker)
      • Setup
      • Build the aarch64 Linux Build Container
      • Compile
    • Cross-compiling DALI C++ API for aarch64 QNX (Docker)
      • Setup
      • Build the aarch64 Build Container
      • Compile
  • Platform support matrix
  • Getting started
    • Overview
    • Optimal configuration
    • Pipeline
      • Defining the pipeline
      • Building the pipeline
      • Running the pipeline
    • Adding augmentations
      • Random shuffle
      • Augmentations
      • Tensors as arguments and Random Number Generation
    • GPU acceleration
      • Copying tensors to GPU
        • Important notice
      • Hybrid decoding
  • Tutorials
    • General
      • Data Loading
        • ExternalSource Operator
        • Data Loading: LMDB Database
        • Data loading: MXNet recordIO
        • Data Loading: TensorFlow TFRecord
        • COCO Reader
      • DALI expressions and arithmetic operations
        • DALI Expressions and Arithmetic Operators
        • DALI Binary Arithmetic Operators - Type Promotions
        • Custom Augmentations with Arithmetic Operations
        • Conditional-Like Execution and Masking
      • Multiple GPU support
        • Overview
        • Run Pipeline on Selected GPU
        • Sharding
      • Erase Operator
      • Normalize Operator
        • Introduction
        • Using the Normalize Operator
        • Adjusting Output Dynamic Range
        • Externally Provided Parameters
        • Batch Normalization
      • Tensor Joining
        • Concatenation
        • Stacking
      • Reduction Operators
    • Custom Operations
      • Create a custom operator
        • Operator definition
        • CPU operator implementation
        • GPU operator implementation
        • Building the plugin
        • Importing the plugin
      • Python Operators
        • Defining an operation
        • Defining a pipeline
        • Running the pipeline and visualizing the results
        • Variety of Python Operators
        • Limitations of Python operators
      • Processing GPU data with Python Operators
        • CuPy operations
        • Defining a pipeline
        • Running the pipeline and visualizing the results
        • Advanced: device synchronization in DLTensorPythonFunction
    • Audio Processing
      • Audio Decoder in DALI
        • Step-by-step guide
        • Verification
      • Audio spectrogram
        • Background
        • Reference implementation
        • Calculating the spectrogram using DALI
        • Mel spectrogram
        • Mel-frequency cepstral coefficients (MFCCs)
    • Image Processing
      • Augmentation Gallery
      • BrightnessContrast Operator Example
        • Brighness and contrast adjustment
        • Step-by-step guide
      • Color Space Conversion
        • Defining the pipeline
        • Building and running the pipeline
        • Visualizing the results
      • Image Decoder examples (CPU)
        • Common code
        • Image Decoder (CPU)
        • Image Decoder (CPU) with random cropping window size and anchor
        • Image Decoder with fixed cropping window size and external anchor
        • Image Decoder (CPU) with external window size and anchor
      • Image Decoder (Hybrid)
        • Image Decoder (Hybrid) with random cropping window size and anchor
        • Image Decoder (Hybrid) with fixed cropping window size and external anchor
        • Image Decoder (Hybrid) with external window size and anchor
      • HSV Operator Example
        • Introduction
        • Step-by-step guide
      • Using HSV to implement RandomGrayscale operator
        • Using functional API
      • Interpolation methods
        • Downscaling
        • Upscaling
      • Resize operator
        • Output size parameters
        • Scaling modes
        • Region of Interest (RoI) processing
        • Fused flip
        • Input and output types
        • Subpixel scale
      • WarpAffine
        • Introduction
        • Usage example
        • Example output
      • 3D Transforms
        • Warp operators
        • Usage example
        • Example output
    • Math
      • Geometric Transforms
        • Affine Transform
        • Transform Catalogue
        • Case Study: Transforming Keypoints
        • Adding Transforms to the Pipeline
        • Combining Transforms
        • Keypoint Cropping
        • Transform Gallery
    • Sequence Processing
      • Simple Video pipeline reading from multiple files
        • Goal
        • Setting up
        • Running the pipeline
        • Visualizing the results
      • Video pipeline reading labelled videos from a directory
        • Goal
        • Setting up
        • Running the pipeline
        • Visualizing the results
      • Video pipeline demonstrating applying labels based on timestamps or frame numbers
        • Goal
        • Defining the pipeline
        • Visualizing the results
      • Simple Sequence pipeline reading from multiple files
      • Optical Flow example
        • Using Dali
    • Use Cases
      • Example VideoReader usage: Video Super-Resolution
        • Dataloaders
        • Data loader performance
        • Requirements
        • FlowNet2-SD implementation and pre-trained model
        • Data
        • Training
        • Results on Myanmar validation set
        • Reference
      • ImageNet training in PyTorch
        • Requirements
        • Training
        • Usage
      • Single Shot MultiBox Detector training in PyTorch
        • Requirements
        • Usage
      • ResNet-N with TensorFlow and DALI
        • Requirements
      • PaddlePaddle Use-Cases
        • ResNet training in PaddlePaddle
        • Single Shot MultiBox Detector training in PaddlePaddle
        • Temporal Shift Module inference in PaddlePaddle
      • MXNet with DALI - ResNet 50 example
        • Overview
        • ResNet 50 pipeline
        • Training with MXNet
      • COCO Reader with Augmentations
    • Advanced
      • Serialization
        • Overview
        • Serialization
  • Framework integration
    • MXNet
      • MXNet Plugin API reference
      • MXNet Framework
        • Gluon example with DALI
        • ExternalSource operator
        • Using MXNet DALI plugin: using various readers
    • PyTorch
      • PyTorch Plugin API reference
      • Pytorch Framework
        • Using DALI in PyTorch
        • ExternalSource operator
        • Using PyTorch DALI plugin: using various readers
        • Using DALI in PyTorch Lightning
    • TensorFlow
      • TensorFlow Plugin API reference
      • Tensorflow Framework
        • Using Tensorflow DALI plugin: DALI and tf.data
        • Using Tensorflow DALI plugin: DALI tf.data.Dataset with multiple GPUs
        • Using Tensorflow DALI plugin with sparse tensors
        • Using Tensorflow DALI plugin: simple example
        • Using Tensorflow DALI plugin: using various readers
    • PaddlePaddle
      • PaddlePaddle Plugin API reference
      • PaddlePaddle Framework
        • Using DALI in PaddlePaddle
        • ExternalSource operator
        • Using Paddle DALI plugin: using various readers
  • Python API
    • Pipeline
      • Pipeline class
        • Data processing graphs
        • Current pipeline
      • DataNode
    • Types
      • TensorList
        • TensorListCPU
        • TensorListGPU
      • Tensor
        • TensorCPU
        • TensorGPU
      • Data Layouts
        • Tensor Layout String format
        • Interpreting Tensor Layout Strings
      • Constant wrapper
        • Constant
      • Enums
        • DALIDataType
        • DALIIterpType
        • DALIImageType
        • SampleInfo
        • TensorLayout
        • PipelineAPIType
    • Functional API
      • Quick start
      • Interoperability with operator objects
      • Functions
    • Mathematical expressions
      • Type promotion rules
      • Supported arithmetic operations
      • Mathematical funcions
  • Supported operations
    • Reading this guide
    • Support Table
    • Operators Documentation
      • nvidia.dali.ops
      • nvidia.dali.ops.random
      • nvidia.dali.ops.reductions
      • nvidia.dali.ops.segmentation
      • nvidia.dali.ops.transforms
      • nvidia.dali.plugin.pytorch
    • Mathematical expressions
  • Advanced Topics
    • Thread Affinity
    • Memory Consumption
    • Operator Buffer Presizing
    • Prefetching Queue Depth
    • Running DALI pipeline
    • Sharding
    • C++ API
  • Release Notes
NVIDIA DALI
  • »
  • Tutorials »
  • Image Processing »
  • Augmentation Gallery
  • View page source

Augmentation GalleryΒΆ

This example showcases different augmentations possible with DALI.

DALI_EXTRA_PATH environment variable should point to the place where data from DALI extra repository is downloaded. Please make sure that the proper release tag is checked out.

[1]:
from nvidia.dali.pipeline import Pipeline
import nvidia.dali.ops as ops
import nvidia.dali.types as types
import numpy as np
from timeit import default_timer as timer
import numpy as np
import matplotlib.pyplot as plt
import math
import os.path

test_data_root = os.environ['DALI_EXTRA_PATH']
db_folder = os.path.join(test_data_root, 'db', 'lmdb')

class HybridPipe(Pipeline):
    def __init__(self, batch_size, num_threads, device_id, pipelined = True, exec_async = True):
        super(HybridPipe, self).__init__(batch_size, num_threads, device_id, seed = 12, exec_pipelined=pipelined, exec_async=exec_async)
        self.input = ops.CaffeReader(path = db_folder, random_shuffle = True)
        self.decode = ops.ImageDecoder(device = "mixed", output_type = types.RGB)
        self.augmentations = {}
        # input is sampled randomly for output pixel's neighbourhood
        self.augmentations["jitter"] = ops.Jitter(device = "gpu")
        # transforms sampling coordinates to produce wavy patterns
        self.augmentations["water"] = ops.Water(device = "gpu")
        # applies fisheye distortion
        self.augmentations["shpere"] = ops.Sphere(device = "gpu")
        # rotates the image, enlarging the canvas
        self.augmentations["rotate"] = ops.Rotate(device = "gpu", angle = 30, interp_type = types.INTERP_LINEAR, fill_value = 0)
        # applies affine transform
        self.augmentations["warpaffine"] = ops.WarpAffine(device = "gpu", matrix = [1.0, 0.8, 0.0, 0.0, 1.2, 0.0],
                                                 interp_type = types.INTERP_LINEAR)
        # manipulates brightness and contrast of the image
        self.augmentations["brightness_contrast"] = ops.BrightnessContrast(device = "gpu", brightness = 0.5, contrast = 1.5)
        # twists colors of the image
        self.augmentations["hsv"] = ops.Hsv(device = "gpu", hue = 45., saturation = 0.2)
        # places the image on a larger canvas
        self.augmentations["paste"] = ops.Paste(device = "gpu", ratio = 2., fill_value = (55, 155, 155),
                                            paste_x = .1, paste_y = .7)
        # param resizes the image so that the shorter edge is exactly 400px long
        self.augmentations["resize"] = ops.Resize(device = "gpu", resize_shorter = 480)
        # param flips the image
        self.augmentations["flip"] = ops.Flip(device = "gpu", vertical = 1, horizontal = 0)
        self.iter = 0

    def define_graph(self):
        self.jpegs, self.labels = self.input()
        images = self.decode(self.jpegs)
        n = len(self.augmentations)
        outputs = [images for _ in range(n+1)]
        aug_list = list(self.augmentations.values())
        # outputs[0] is the original cropped image
        for i in range(n):
            outputs[i+1] = aug_list[i](outputs[i+1])
        return [self.labels] + outputs

    def iter_setup(self):
        pass
[2]:
batch_size = 32

pipe = HybridPipe(batch_size=batch_size, num_threads=2, device_id = 0)
pipe.build()
[3]:
pipe_out = pipe.run()
[4]:
n = 5
from synsets import imagenet_synsets
import matplotlib.gridspec as gridspec
len_outputs = len(pipe_out) - 1
augmentations = ["original"] + list(pipe.augmentations.keys())
fig = plt.figure(figsize = (16,16))
plt.suptitle(imagenet_synsets[pipe_out[0].at(n)[0]], fontsize=16)
columns = 4
rows = int(math.ceil(len_outputs / columns))
gs = gridspec.GridSpec(rows, columns)
for i in range(len_outputs):
    plt.subplot(gs[i])
    plt.axis("off")
    plt.title(augmentations[i])
    pipe_out_cpu = pipe_out[1 + i].as_cpu()
    img_chw = pipe_out_cpu.at(n)
    plt.imshow((img_chw)/255.0)
../../_images/examples_image_processing_augmentation_gallery_4_0.png
Next Previous

© Copyright 2018-2019, NVIDIA Corporation.

Built with Sphinx using a theme provided by Read the Docs.