Package ai.djl.nn.norm
Class GhostBatchNorm
java.lang.Object
ai.djl.nn.AbstractBaseBlock
ai.djl.nn.AbstractBlock
ai.djl.nn.norm.BatchNorm
ai.djl.nn.norm.GhostBatchNorm
- All Implemented Interfaces:
Block
GhostBatchNorm
is similar to BatchNorm
except that it splits a batch into a
smaller sub-batches aka ghost batches, and normalize them individually to have a mean of
0 and variance of 1 and finally concatenate them again to a single batch. Each of the
mini-batches contains a virtualBatchSize samples.- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class ai.djl.nn.norm.BatchNorm
BatchNorm.BaseBuilder<T extends BatchNorm.BaseBuilder<T>>
-
Field Summary
Fields inherited from class ai.djl.nn.AbstractBlock
children, parameters
Fields inherited from class ai.djl.nn.AbstractBaseBlock
inputNames, inputShapes, outputDataTypes, version
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected NDList
Converts an array ofNDList
into an NDList usingStackBatchifier
and squeezes the first dimension created by it.static GhostBatchNorm.Builder
builder()
Creates a builder to build aGhostBatchNorm
.protected NDList
forwardInternal
(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<String, Object> params) A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)
after initialization.protected NDList[]
Splits anNDList
into the given size of sub-batch.protected NDList
squeezeExtraDimensions
(NDList batch) Squeezes first axes ofNDList
.Methods inherited from class ai.djl.nn.norm.BatchNorm
batchNorm, batchNorm, batchNorm, batchNorm, beforeInitialize, getOutputShapes, loadMetadata, prepare, saveMetadata
Methods inherited from class ai.djl.nn.AbstractBlock
addChildBlock, addChildBlock, addChildBlockSingleton, addParameter, getChildren, getDirectParameters
Methods inherited from class ai.djl.nn.AbstractBaseBlock
cast, clear, describeInput, forward, forward, forwardInternal, getInputShapes, getOutputDataTypes, getParameters, initialize, initializeChildBlocks, isInitialized, loadParameters, readInputShapes, saveInputShapes, saveParameters, setInitializer, setInitializer, setInitializer, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ai.djl.nn.Block
forward, freezeParameters, freezeParameters, getOutputShapes
-
Constructor Details
-
GhostBatchNorm
-
-
Method Details
-
forwardInternal
protected NDList forwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<String, Object> params) A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)
after initialization.- Overrides:
forwardInternal
in classBatchNorm
- Parameters:
parameterStore
- the parameter storeinputs
- the input NDListtraining
- true for a training forward passparams
- optional parameters- Returns:
- the output of the forward pass
-
split
Splits anNDList
into the given size of sub-batch.This function unbatchifies the input
NDList
into mini-batches, each with the size of virtualBatchSize. If the batch size is divisible by the virtual batch size, all returned sub-batches will be the same size. If the batch size is not divisible by virtual batch size, all returned sub-batches will be the same size, except the last one. -
batchify
Converts an array ofNDList
into an NDList usingStackBatchifier
and squeezes the first dimension created by it. This makes the finalNDArray
same size as the splitted one. -
squeezeExtraDimensions
Squeezes first axes ofNDList
. -
builder
Creates a builder to build aGhostBatchNorm
.- Returns:
- a new builder
-