Why normalize?

Neural networks work best when the data they’re fed is normalized, constrained to a range between -1 and 1. There are several reasons for that. One is that nets are trained using gradient descent, and their activation functions usually having an active range somewhere between -1 and 1. Even when using an activation function that doesn’t saturate quickly, it is still good practice to constrain your values to this range to improve performance.

Available preprocessors


NormalizerMinMaxScaler

[source]

Pre processor for DataSets that normalizes feature values (and optionally label values) to lie between a minimumand maximum value (by default between 0 and 1)

NormalizerMinMaxScaler
  1. public NormalizerMinMaxScaler(double minRange, double maxRange)

Preprocessor can take a range as minRange and maxRange

  • param minRange
  • param maxRange
load
  1. public void load(File... statistics) throws IOException

Load the given min and max

  • param statistics the statistics to load
  • throws IOException
save
  1. public void save(File... files) throws IOException

Save the current min and max

  • param files the statistics to save
  • throws IOException
  • deprecated use {- link NormalizerSerializer instead}

Normalizer

[source]

Base interface for all normalizers


ImageFlatteningDataSetPreProcessor

[source]

A DataSetPreProcessor used to flatten a 4d CNN features array to a flattened 2d format (for use in networks suchas a DenseLayer/multi-layer perceptron)


MinMaxStrategy

[source]

statistics of the upper and lower bounds of the population

MinMaxStrategy
  1. public MinMaxStrategy(double minRange, double maxRange)
  • param minRange the target range lower bound
  • param maxRange the target range upper bound
preProcess
  1. public void preProcess(INDArray array, INDArray maskArray, MinMaxStats stats)

Normalize a data array

  • param array the data to normalize
  • param stats statistics of the data population
revert
  1. public void revert(INDArray array, INDArray maskArray, MinMaxStats stats)

Denormalize a data array

  • param array the data to denormalize
  • param stats statistics of the data population

ImagePreProcessingScaler

[source]

Created by susaneraly on 6/23/16.A preprocessor specifically for images that applies min max scalingCan take a range, so pixel values can be scaled from 0->255 to minRange->maxRangedefault minRange = 0 and maxRange = 1;If pixel values are not 8 bits, you can specify the number of bits as the third argument in the constructorFor values that are already floating point, specify the number of bits as 1

ImagePreProcessingScaler
  1. public ImagePreProcessingScaler(double a, double b, int maxBits)

Preprocessor can take a range as minRange and maxRange

  • param a, default = 0
  • param b, default = 1
  • param maxBits in the image, default = 8
fit
  1. public void fit(DataSet dataSet)

Fit a dataset (only computebased on the statistics from this dataset0

  • param dataSet the dataset to compute on
fit
  1. public void fit(DataSetIterator iterator)

Iterates over a datasetaccumulating statistics for normalization

  • param iterator the iterator to use forcollecting statistics.
transform
  1. public void transform(DataSet toPreProcess)

Transform the data

  • param toPreProcess the dataset to transform

CompositeMultiDataSetPreProcessor

[source]

A simple Composite MultiDataSetPreProcessor - allows you to apply multiple MultiDataSetPreProcessors sequentiallyon the one MultiDataSet, in the order they are passed to the constructor

CompositeMultiDataSetPreProcessor
  1. public CompositeMultiDataSetPreProcessor(MultiDataSetPreProcessor... preProcessors)
  • param preProcessors Preprocessors to apply. They will be applied in this order

MultiNormalizerMinMaxScaler

[source]

Pre processor for MultiDataSet that normalizes feature values (and optionally label values) to lie between a minimumand maximum value (by default between 0 and 1)

MultiNormalizerMinMaxScaler
  1. public MultiNormalizerMinMaxScaler(double minRange, double maxRange)

Preprocessor can take a range as minRange and maxRange

  • param minRange the target range lower bound
  • param maxRange the target range upper bound

MultiDataNormalization

[source]

An interface for multi dataset normalizers.Data normalizers compute some sort of statisticsover a MultiDataSet and scale the data in some way.


ImageMultiPreProcessingScaler

[source]

A preprocessor specifically for images that applies min max scaling to one or more of the feature arraysin a MultiDataSet.Can take a range, so pixel values can be scaled from 0->255 to minRange->maxRangedefault minRange = 0 and maxRange = 1;If pixel values are not 8 bits, you can specify the number of bits as the third argument in the constructorFor values that are already floating point, specify the number of bits as 1

ImageMultiPreProcessingScaler
  1. public ImageMultiPreProcessingScaler(double a, double b, int maxBits, int[] featureIndices)

Preprocessor can take a range as minRange and maxRange

  • param a, default = 0
  • param b, default = 1
  • param maxBits in the image, default = 8
  • param featureIndices Indices of feature arrays to process. If only one feature array is present,this should always be 0

NormalizerStandardize

[source]

Created by susaneraly, Ede Meijervariance and meanPre processor for DataSet that normalizes feature values (and optionally label values) to have 0 mean and a standarddeviation of 1

load
  1. public void load(File... files) throws IOException

Load the means and standard deviations from the file system

  • param files the files to load from. Needs 4 files if normalizing labels, otherwise 2.
save
  1. public void save(File... files) throws IOException
  • param files the files to save to. Needs 4 files if normalizing labels, otherwise 2.
  • deprecated use {- link NormalizerSerializer} insteadSave the current means and standard deviations to the file system

StandardizeStrategy

[source]

of the means and standard deviations of the population

preProcess
  1. public void preProcess(INDArray array, INDArray maskArray, DistributionStats stats)

Normalize a data array

  • param array the data to normalize
  • param stats statistics of the data population
revert
  1. public void revert(INDArray array, INDArray maskArray, DistributionStats stats)

Denormalize a data array

  • param array the data to denormalize
  • param stats statistics of the data population

NormalizerStrategy

[source]

Interface for strategies that can normalize and denormalize data arrays based on statistics of the population


MultiNormalizerHybrid

[source]

Pre processor for MultiDataSet that can be configured to use different normalization strategies for different inputsand outputs, or none at all. Can be used for example when one input should be normalized, but a different one shouldbe untouched because it’s the input for an embedding layer. Alternatively, one might want to mix standardization andmin-max scaling for different inputs and outputs.

By default, no normalization is applied. There are methods to configure the desired normalization strategy for inputsand outputs either globally or on an individual input/output level. Specific input/output strategies will overrideglobal ones.

MultiNormalizerHybrid
  1. public MultiNormalizerHybrid standardizeAllInputs()

Apply standardization to all inputs, except the ones individually configured

  • return the normalizer
minMaxScaleAllInputs
  1. public MultiNormalizerHybrid minMaxScaleAllInputs()

Apply min-max scaling to all inputs, except the ones individually configured

  • return the normalizer
minMaxScaleAllInputs
  1. public MultiNormalizerHybrid minMaxScaleAllInputs(double rangeFrom, double rangeTo)

Apply min-max scaling to all inputs, except the ones individually configured

  • param rangeFrom lower bound of the target range
  • param rangeTo upper bound of the target range
  • return the normalizer
standardizeInput
  1. public MultiNormalizerHybrid standardizeInput(int input)

Apply standardization to a specific input, overriding the global input strategy if any

  • param input the index of the input
  • return the normalizer
minMaxScaleInput
  1. public MultiNormalizerHybrid minMaxScaleInput(int input)

Apply min-max scaling to a specific input, overriding the global input strategy if any

  • param input the index of the input
  • return the normalizer
minMaxScaleInput
  1. public MultiNormalizerHybrid minMaxScaleInput(int input, double rangeFrom, double rangeTo)

Apply min-max scaling to a specific input, overriding the global input strategy if any

  • param input the index of the input
  • param rangeFrom lower bound of the target range
  • param rangeTo upper bound of the target range
  • return the normalizer
standardizeAllOutputs
  1. public MultiNormalizerHybrid standardizeAllOutputs()

Apply standardization to all outputs, except the ones individually configured

  • return the normalizer
minMaxScaleAllOutputs
  1. public MultiNormalizerHybrid minMaxScaleAllOutputs()

Apply min-max scaling to all outputs, except the ones individually configured

  • return the normalizer
minMaxScaleAllOutputs
  1. public MultiNormalizerHybrid minMaxScaleAllOutputs(double rangeFrom, double rangeTo)

Apply min-max scaling to all outputs, except the ones individually configured

  • param rangeFrom lower bound of the target range
  • param rangeTo upper bound of the target range
  • return the normalizer
standardizeOutput
  1. public MultiNormalizerHybrid standardizeOutput(int output)

Apply standardization to a specific output, overriding the global output strategy if any

  • param output the index of the input
  • return the normalizer
minMaxScaleOutput
  1. public MultiNormalizerHybrid minMaxScaleOutput(int output)

Apply min-max scaling to a specific output, overriding the global output strategy if any

  • param output the index of the input
  • return the normalizer
minMaxScaleOutput
  1. public MultiNormalizerHybrid minMaxScaleOutput(int output, double rangeFrom, double rangeTo)

Apply min-max scaling to a specific output, overriding the global output strategy if any

  • param output the index of the input
  • param rangeFrom lower bound of the target range
  • param rangeTo upper bound of the target range
  • return the normalizer
getInputStats
  1. public NormalizerStats getInputStats(int input)

Get normalization statistics for a given input.

  • param input the index of the input
  • return implementation of NormalizerStats corresponding to the normalization strategy selected
getOutputStats
  1. public NormalizerStats getOutputStats(int output)

Get normalization statistics for a given output.

  • param output the index of the output
  • return implementation of NormalizerStats corresponding to the normalization strategy selected
fit
  1. public void fit(@NonNull MultiDataSet dataSet)

Get the map of normalization statistics per input

  • return map of input indices pointing to NormalizerStats instances
fit
  1. public void fit(@NonNull MultiDataSetIterator iterator)

Iterates over a datasetaccumulating statistics for normalization

  • param iterator the iterator to use for collecting statistics
transform
  1. public void transform(@NonNull MultiDataSet data)

Transform the dataset

  • param data the dataset to pre process
revert
  1. public void revert(@NonNull MultiDataSet data)

Undo (revert) the normalization applied by this DataNormalization instance (arrays are modified in-place)

  • param data MultiDataSet to revert the normalization on
revertFeatures
  1. public void revertFeatures(@NonNull INDArray[] features)

Undo (revert) the normalization applied by this DataNormalization instance to the entire inputs array

  • param features The normalized array of inputs
revertFeatures
  1. public void revertFeatures(@NonNull INDArray[] features, INDArray[] maskArrays)

Undo (revert) the normalization applied by this DataNormalization instance to the entire inputs array

  • param features The normalized array of inputs
  • param maskArrays Optional mask arrays belonging to the inputs
revertFeatures
  1. public void revertFeatures(@NonNull INDArray[] features, INDArray[] maskArrays, int input)

Undo (revert) the normalization applied by this DataNormalization instance to the features of a particular input

  • param features The normalized array of inputs
  • param maskArrays Optional mask arrays belonging to the inputs
  • param input the index of the input to revert normalization on
revertLabels
  1. public void revertLabels(@NonNull INDArray[] labels)

Undo (revert) the normalization applied by this DataNormalization instance to the entire outputs array

  • param labels The normalized array of outputs
revertLabels
  1. public void revertLabels(@NonNull INDArray[] labels, INDArray[] maskArrays)

Undo (revert) the normalization applied by this DataNormalization instance to the entire outputs array

  • param labels The normalized array of outputs
  • param maskArrays Optional mask arrays belonging to the outputs
revertLabels
  1. public void revertLabels(@NonNull INDArray[] labels, INDArray[] maskArrays, int output)

Undo (revert) the normalization applied by this DataNormalization instance to the labels of a particular output

  • param labels The normalized array of outputs
  • param maskArrays Optional mask arrays belonging to the outputs
  • param output the index of the output to revert normalization on

CompositeDataSetPreProcessor

[source]

A simple Composite DataSetPreProcessor - allows you to apply multiple DataSetPreProcessors sequentiallyon the one DataSet, in the order they are passed to the constructor

CompositeDataSetPreProcessor
  1. public CompositeDataSetPreProcessor(DataSetPreProcessor... preProcessors)
  • param preProcessors Preprocessors to apply. They will be applied in this order

MultiNormalizerStandardize

[source]

Pre processor for MultiDataSet that normalizes feature values (and optionally label values) to have 0 mean anda standard deviation of 1

load
  1. public void load(@NonNull List<File> featureFiles, @NonNull List<File> labelFiles) throws IOException

Load means and standard deviations from the file system

  • param featureFiles source files for features, requires 2 files per input, alternating mean and stddev files
  • param labelFiles source files for labels, requires 2 files per output, alternating mean and stddev files
save
  1. public void save(@NonNull List<File> featureFiles, @NonNull List<File> labelFiles) throws IOException
  • param featureFiles target files for features, requires 2 files per input, alternating mean and stddev files
  • param labelFiles target files for labels, requires 2 files per output, alternating mean and stddev files
  • deprecated use {- link MultiStandardizeSerializerStrategy} insteadSave the current means and standard deviations to the file system

VGG16ImagePreProcessor

[source]

This is a preprocessor specifically for VGG16.It subtracts the mean RGB value, computed on the training set, from each pixel as reported in:https://arxiv.org/pdf/1409.1556.pdf

fit
  1. public void fit(DataSet dataSet)

Fit a dataset (only computebased on the statistics from this dataset0

  • param dataSet the dataset to compute on
fit
  1. public void fit(DataSetIterator iterator)

Iterates over a datasetaccumulating statistics for normalization

  • param iterator the iterator to use forcollecting statistics.
transform
  1. public void transform(DataSet toPreProcess)

Transform the data

  • param toPreProcess the dataset to transform

DataNormalization

[source]

An interface for data normalizers.Data normalizers compute some sort of statisticsover a dataset and scale the data in some way.