NVIDIA DALI
1.10.0 -629c575
Version select:
  • Home

Getting Started

  • Installation
    • Prerequisites
    • DALI in NGC Containers
    • pip - Official Releases
      • nvidia-dali
      • nvidia-dali-tf-plugin
    • pip - Nightly and Weekly Releases
      • Nightly Builds
      • Weekly Builds
    • pip - Legacy Releases
    • Open Cognitive Environment (Open-CE)
  • Platform Support
  • Getting Started Tutorial
    • Overview
    • Pipeline
      • Defining the Pipeline
      • Building the Pipeline
      • Running the Pipeline
    • Adding Augmentations
      • Random Shuffle
      • Augmentations
      • Tensors as Arguments and Random Number Generation
      • Placement of argument inputs
    • Adding GPU Acceleration
      • Copying Tensors to GPU
        • Important Notice
      • Hybrid Decoding

Python API Documentation

  • Pipeline
    • Data Processing Graphs
      • Processing Graph Structure
    • Current Pipeline
    • Pipeline Decorator
    • DataNode
    • Pipeline Debug Mode (experimental)
  • 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
      • BatchInfo
      • TensorLayout
      • PipelineAPIType
  • Mathematical Expressions
    • Type Promotion Rules
    • Supported Arithmetic Operations
    • Mathematical Functions
      • Exponents and logarithms
      • Trigonometric Functions
      • Hyperbolic Functions
  • Indexing and Slicing
    • Indexing
    • Indexing from the end
    • Indexing with run-time values
    • Slicing
    • Multidimensional selection
    • Strided slices
    • Adding dimensions
    • Layout specifiers
  • Operation Reference
    • nvidia.dali.fn
    • nvidia.dali.fn.decoders
    • nvidia.dali.fn.experimental
    • nvidia.dali.fn.experimental.readers
    • nvidia.dali.fn.noise
    • nvidia.dali.fn.random
    • nvidia.dali.fn.readers
    • nvidia.dali.fn.reductions
    • nvidia.dali.fn.segmentation
    • nvidia.dali.fn.transforms
    • nvidia.dali.plugin.numba.fn.experimental
    • nvidia.dali.plugin.pytorch.fn
  • Operator Objects (Legacy)
    • Mapping to Functional API
    • Modules
      • nvidia.dali.ops
      • nvidia.dali.ops.decoders
      • nvidia.dali.ops.experimental
      • nvidia.dali.ops.experimental.readers
      • nvidia.dali.ops.noise
      • nvidia.dali.ops.random
      • nvidia.dali.ops.readers
      • nvidia.dali.ops.reductions
      • nvidia.dali.ops.segmentation
      • nvidia.dali.ops.transforms
      • nvidia.dali.plugin.numba.experimental
      • nvidia.dali.plugin.pytorch
  • DL Framework Plugins
    • 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
        • Experimental
      • Tensorflow Framework
        • Using Tensorflow DALI plugin: DALI and tf.data
        • Using Tensorflow DALI plugin: DALI tf.data.Dataset with multiple GPUs
        • Inputs to DALI Dataset with External Source
        • 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

Examples and Tutorials

  • Data Loading
    • External Source Operator - basic usage
      • Define the Data Source
      • Defining the Pipeline
      • Using the Pipeline
        • Interacting with the GPU Input
    • Parallel External Source
      • Accepted source
      • Principle of Operation
      • Example Pipeline and source
        • Adjusting to Callable Object
        • Pipeline Definition
        • Testing the Pipelines
      • Going Parallel
        • Starting Python Workers
      • Running the Pipeline with Python Workers
        • Spawn and Serialization of Functions
        • Customizing Serialization
    • Parallel External Source - Fork
      • Steps to Start with Fork
      • Example Pipeline and source
        • Callable Object
        • Pipeline Definition
        • Displaying the Results
      • Starting Python Workers
        • Running the Pipelines
    • Data Loading: LMDB Database
      • Overview
      • Caffe LMDB Format
      • Caffe 2 LMDB Format
    • Data loading: MXNet recordIO
      • Overview
      • Creating an Index
      • Defining and Running the Pipeline
    • Data Loading: TensorFlow TFRecord
      • Overview
      • Creating index
      • Defining and Running the Pipeline
    • Data Loading: Webdataset
      • Overview
      • Using readers.webdataset operator
      • Creating an index
      • Defining and running the pipeline
    • COCO Reader
    • Numpy Reader
      • Overview
      • Test data
      • Usage
        • Glob filter
        • Text file with a list of file paths
        • List of file paths
        • Higher dimensionality
      • Region-of-interest (ROI) API
        • ROI start and end, in absolute coordinates
        • ROI start and end, in relative coordinates
        • Specifying a subset of the array’s axes
        • Out of bounds access
      • GPUDirect Storage Support
  • Operations
    • General Purpose
      • 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
      • Reduction Operators
      • Tensor Joining
        • Concatenation
        • Stacking
      • Reinterpreting Tensors
        • Fixed Output Shape
        • Reshape with Wildcards
        • Removing and Adding Unit Dimensions
        • Rearranging Dimensions
        • Adding and Removing Dimensions
        • Relative Shape
        • Reinterpreting Data Type
      • Normalize Operator
        • Introduction
        • Using the Normalize Operator
        • Adjusting Output Dynamic Range
        • Externally Provided Parameters
        • Batch Normalization
      • Geometric Transforms
        • Affine Transform
        • Transform Catalogue
        • Case Study: Transforming Keypoints
        • Adding Transforms to the Pipeline
        • Combining Transforms
        • Keypoint Cropping
        • Transform Gallery
      • Erase Operator
    • Image Processing
      • Augmentation Gallery
      • BrightnessContrast 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 Example
        • Introduction
        • Step-by-Step Guide
      • Using HSV to implement RandomGrayscale operation
      • 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
    • 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)
    • Video Processing
      • Simple Video Pipeline Reading From Multiple Files
        • Goal
        • Visualizing the Results
      • Video Pipeline Reading Labelled Videos from a Directory
        • Setting Up
        • Running the Pipeline
        • Visualizing the Results
      • Video Pipeline Demonstrating Applying Labels Based on Timestamps or Frame Numbers
        • Defining the Pipeline
        • Visualizing the Results
      • Reading Video Frames Stored as Images
        • Preparing the Data
        • Frame Sequence Reader
      • Optical Flow
        • Using Dali
  • Use Cases
    • 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
      • Training in Keras Fit/Compile mode
      • Predicting in Keras Fit/Compile mode
      • Training in CTL (Custom Training Loop) mode
      • Predicting in CTL (Custom Training Loop) mode
      • Other useful options
        • Requirements
    • You Only Look Once v4 with TensorFlow and DALI
      • Requirements
      • Usage
        • Training
        • Inference
        • Evaluation
    • EfficientDet with TensorFlow and DALI
      • Preparing data files from COCO dataset
      • Training in Keras Fit/Compile mode
      • Evaluation in Keras Fit/Compile mode
      • Usage
        • Requirements
    • PaddlePaddle Use-Cases
      • ResNet Training in PaddlePaddle
        • Training
        • Usage
      • Single Shot MultiBox Detector Training in PaddlePaddle
        • Requirements
        • Usage
      • Temporal Shift Module Inference in PaddlePaddle
        • Requirements
        • Usage
    • MXNet with DALI - ResNet 50 example
      • Overview
      • ResNet 50 Pipeline
        • The Training Pipeline
        • Using the MXNet Plugin
      • Training with MXNet
    • COCO Reader with Augmentations
    • WebDataset integration using External Source
      • Introduction
        • Data Representation
        • Sharding
      • Sample Implementation
        • Keyword Arguments:
      • Usage presentation
      • Checking consistency
  • Other
    • Multiple GPU Support
      • Overview
      • Run Pipeline on Selected GPU
      • Sharding
    • Custom Operations
      • Create a Custom Operator in C++
        • Prerequisites
        • 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 the DLTensorPythonFunction
      • Numba Function - Running a Compiled C Callback Function
        • Define the shape function swapping the width and height
        • Define the processing function that fills the output sample based on the input sample
        • Define the Pipeline
    • Serialization
      • Overview
      • Serialization
    • Operator Objects (Legacy)
      • Overview
        • Defining the Pipeline
        • Building the Pipeline
        • Running the Pipeline
      • Adding Augmentations
        • Random Shuffle
        • Augmentations
        • Tensors as Arguments and Random Number Generation
      • Adding GPU Acceleration
        • Copying Tensors to GPU
        • Hybrid Decoding

Advanced

  • Performance Tuning
    • Thread Affinity
    • Memory Consumption
    • Operator Buffer Presizing
    • Prefetching Queue Depth
  • Sharding
    • Framework iterator configuration
      • Enums
    • Shard calculation
  • Pipeline Run Methods
  • Experimental
    • C++ API
  • Compiling DALI from Source
    • Using Docker builder - recommended
      • Prerequisites
      • Building Python Wheel
    • Bare Metal build
      • Prerequisites
      • Build DALI
        • Install Python Bindings
      • Verify the Build (Optional)
        • Obtain Test Data
        • Set Test Data Path
        • Run Tests
      • Building DALI with Clang (Experimental)
      • Optional CMake Build Parameters
    • Cross-compiling for aarch64 Jetson Linux (Docker)
      • Build the aarch64 Jetson Linux Build Container
      • Compile

Reference

  • Release Notes
  • GitHub
  • Roadmap
NVIDIA DALI
  • »
  • <no title> »
  • Operations »
  • 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 import pipeline_def
import nvidia.dali.fn as fn
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')

augmentations = {}

# input is sampled randomly for output pixel's neighbourhood
augmentations["erase"] = \
    lambda images: fn.erase(images, anchor=[0.3, 0.2], shape=[0.5, 0.6],
                            normalized_anchor=True, normalized_shape=True, axis_names='HW')

augmentations["slice"] = \
    lambda images: fn.slice(images, rel_start=[0.3, 0.2], rel_shape=[0.5, 0.6], axis_names='HW')

# transforms sampling coordinates to produce wavy patterns
augmentations["water"] = \
    lambda images: fn.water(images)

# applies fisheye distortion
augmentations["sphere"] = \
    lambda images: fn.sphere(images)

# rotates the image, enlarging the canvas
augmentations["rotate"] = \
    lambda images: fn.rotate(images, angle=30, interp_type=types.INTERP_LINEAR, fill_value=0)

# applies affine transform
augmentations["warp_affine"] = \
    lambda images: fn.warp_affine(images, 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
augmentations["brightness_contrast"] = \
    lambda images: fn.brightness_contrast(images, brightness=0.5, contrast=1.5)

# twists colors of the image
augmentations["hsv"] = \
    lambda images: fn.hsv(images, hue=45., saturation=0.2)

# places the image on a larger canvas
augmentations["paste"] = \
    lambda images: fn.paste(images, ratio=2., fill_value=(55, 155, 155), paste_x=.1, paste_y=.7)

# param flips the image
augmentations["horizontal flip"] = \
    lambda images: fn.flip(images, vertical=0, horizontal=1)

augmentations["vertical flip"] = \
    lambda images: fn.flip(images, vertical=1, horizontal=0)


@pipeline_def()
def augmentation_gallery_pipe(path):
    encoded, labels = fn.readers.caffe(path = path, random_shuffle = True)
    images = fn.decoders.image(encoded, device = "mixed", output_type = types.RGB)
    return tuple([labels, images] + [aug(images) for aug in augmentations.values()])


[2]:
pipe = augmentation_gallery_pipe(path=db_folder, batch_size=32, num_threads=2, device_id=0, seed=11122)
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(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
Previous Next

© Copyright 2018-2022, NVIDIA Corporation.

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