This code snipped shows how the Data Conditioner module is typically used. Note that error handling is left out for clarity.
Initialize DataConditioner parameters with default values.
In order to initialize the Data Conditioner module, it is first required to initialize the Data Conditioner parameters
dwDataConditionerParams()
permits to set the following parameters:
Modify parameters as required by the network or by the application.
Once the Data Conditioner parameters have been defined, the Data Conditioner object can be initialized. There are two ways to accomplish this:
In this case, the user is required to provide the network input blob dimensions, which can be acquired from dwDNN
module via dwDNN_getInputSize()
once the network is loaded. The batch size in networkInputBlobSize can be modified to allow for a batch of images to be prepared in parallel.
This initialization function requires dwDNNTensorProperties
, which can also be acquired from dwDNN
module via dwDNN_getInputTensorProperties()
. maxNumImages
determines how many images can be prepared in parallel.
ctx
is assumed to be a previously initialized dwContextHandle_t
.
Allocate CUDA memory to store the output of DataConditioner module.
Perform operations on a given image and store the result in dataConditionerOutput
. All operations are performed asynchronously with the host code. There are two possible ways to execute data preparation: with raw pointers and with dwDNNTensorHandle_t
.
With raw pointers:
With dwDNNTensorHandle_t
:
inputImages contains pointers to the images of the batch that shall be prepared. The number of images in inputImages is given through numImages and shall not exceed the (possibly modified) batch size of the network. The regionOfInterest
parameter defines a specific region in all images to which the desired transformations as well as network inference shall be applied. The region of interest is identified by the coordinates of the top left corner, and the width and the height of the rectangle. If full images are of interest, then the top left corner must be set as (0,0), width and height according to the images at hand. The internal resizing of roi to match the network input size is defined in such a way that no image content is lost, but undefined border values might be created. addressMode shall be used to set the fill-up strategy for the undefined border values. Two modes are allowed cudaAddressModeBorder and cudaAddressModeClamp.
In a nutshell, dwDataConditioner_prepareData()
or dwDataConditioner_prepareDataRaw()
crops and resizes the defined ROI from each input image in order to match the network input size, applies the desired transformations, and returns the transformed image batch in dataConditionerOutput
, which can be used as input to dwDNN_infer() (see DNN module Inference).
Assuming that the network used in runInference
returns coordinates relative to the output of the network, the interpreted output of the network is transformed back from the network input coordinate frame to the input image space.
where the point to be transformed back is passed through inputX and inputY and is returned in outputX and outputY. The same regionOfInterest
passed to dwDataConditioner_prepareData()
shall be used.
Finally, free previously allocated memory.
For more information see: