IMAGE_TO_NDARRAY

ImageToNDArrayStep is a PipelineStep for converting images to n-dimensional arrays. The exact way that images are converted is highly configurable (formats, channels, output sizes, normalization, etc).

Configs

Descriptions

config

Configuration for how conversion should be performed.

keys

May be null. If non-null, these are the names of images in the Data instance to convert.

outputNames

May be null. If non-null, the input images are renamed to this in the output Data instance after conversion to n-dimensional array.

keepOtherValues

True by default. If true, copy all the other (non-converted/non-image) entries in the input data to the output data.

metadata

False by default. If true, include metadata about the images in the output data. For example, if/how it was cropped, and the original input size.

metadataKey

Sets the key that the metadata will be stored under. Not relevant if metadata == false. Default is @ImageToNDArrayStepMetadata

ImageToNDArrayConfig is configuration for converting an image into n-dimensional array. This configuration is used in config from ImageToNDArrayStep, for example:

inferenceConfiguration.pipeline(SequencePipeline.builder()
                .add(new ImageToNDArrayStep() //add ImageToNDArrayStep() into pipeline to set image to NDArray for input
                        .config(new ImageToNDArrayConfig() //image configuration
                                .width(28)
                                .height(28)
                                .dataType(NDArrayType.FLOAT)
                                .aspectRatioHandling(AspectRatioHandling.CENTER_CROP)
                                .includeMinibatchDim(true)
                                .channelLayout(NDChannelLayout.GRAYSCALE)
                                .format(NDFormat.CHANNELS_FIRST)
                                .normalization(ImageNormalization.builder().type(ImageNormalization.Type.SCALE).build())
                        )
                        .keys("image")
                        .outputNames("input_layer")
                        .keepOtherValues(true)
                        .metadata(false)
                        .metadataKey(ImageToNDArrayStep.DEFAULT_METADATA_KEY))
                .build()

Configs

Descriptions

height

Output array image height. Leave null to convert to the same size as the image height.

width

Output array image width. Leave null to convert to the same size as the image width.

dataType

Data type of the n-dimensional array. Default value is FLOAT.

includeMinibatchDim

If true, the output array will contain an extra dimension for the minibatch number. This will look like (1, Channels, Height, Width) instead of (Channels, Height, Width) for format == CHANNELS_FIRST or (1, Height, Width, Channels) instead of (Height, Width, Channels) for format == CHANNELS_LAST. Default is true.

aspectRatioHandling

An enum to Handle the situation where the input image and output NDArray have different aspect ratios.

CENTER_CROP (crop larger dimension then resize if necessary), PAD (pad smaller dimension then resize if necessary), STRETCH (simply resize, distorting if necessary). Default is CENTER_CROP.

format

The format to be used when converting an Image to an NDArray. Default is CHANNEL_FIRST. Another option is CHANNEL_LAST.

channelLayout

An enum that represents the type (and order) of the color channels for an image after it has been converted to an NDArray. For example, RGB vs. BGR etc, default value is RGB.

normalization

Configuration that specifies the normalization type of an image array values.

listHandling

An enum to specify how to handle a list of input images. Default is NONE.

Last updated