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, parametersFields inherited from class ai.djl.nn.AbstractBaseBlock
inputNames, inputShapes, outputDataTypes, version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected NDListConverts an array ofNDListinto an NDList usingStackBatchifierand squeezes the first dimension created by it.static GhostBatchNorm.Builderbuilder()Creates a builder to build aGhostBatchNorm.protected NDListforwardInternal(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 anNDListinto the given size of sub-batch.protected NDListsqueezeExtraDimensions(NDList batch) Squeezes first axes ofNDList.Methods inherited from class ai.djl.nn.norm.BatchNorm
batchNorm, batchNorm, batchNorm, batchNorm, beforeInitialize, getOutputShapes, loadMetadata, prepare, saveMetadataMethods inherited from class ai.djl.nn.AbstractBlock
addChildBlock, addChildBlock, addChildBlockSingleton, addParameter, getChildren, getDirectParametersMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:
forwardInternalin 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 anNDListinto the given size of sub-batch.This function unbatchifies the input
NDListinto 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 ofNDListinto an NDList usingStackBatchifierand squeezes the first dimension created by it. This makes the finalNDArraysame size as the splitted one. -
squeezeExtraDimensions
Squeezes first axes ofNDList. -
builder
Creates a builder to build aGhostBatchNorm.- Returns:
- a new builder
-