org.apache.mxnet.module

SequentialModule

Related Doc: package module

class SequentialModule extends BaseModule

A SequentialModule is a container module that can chain multiple modules together. Note building a computation graph with this kind of imperative container is less flexible and less efficient than the symbolic graph. So this should be only used as a handy utility.

Linear Supertypes
BaseModule, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. SequentialModule
  2. BaseModule
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SequentialModule()

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  4. def add(module: BaseModule, kwargs: (String, Boolean)*): SequentialModule

    Add a module to the chain.

    Add a module to the chain. An example of addinging two modules to a chain: val seqMod = new SequentialModule() seqMod.add(mod1).add(mod2)

    module

    The new module to add.

    kwargs

    All the keyword arguments are saved as meta information for the added module. The currently known meta includes

    • "take_labels": indicating whether the module expect to take labels when doing computation. Note any module in the chain can take labels (not necessarily only the top most one), and they all take the same labels passed from the original data batch for the SequentialModule.
    returns

    This function returns this to allow us to easily chain a series of add calls.

  5. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  6. def backward(outGrads: Array[NDArray] = null): Unit

    Backward computation.

    Backward computation.

    outGrads

    Gradient on the outputs to be propagated back. This parameter is only needed when bind is called on outputs that are not a loss function.

    Definition Classes
    SequentialModuleBaseModule
  7. def bind(dataShapes: IndexedSeq[DataDesc], labelShapes: Option[IndexedSeq[DataDesc]] = None, forTraining: Boolean = true, inputsNeedGrad: Boolean = false, forceRebind: Boolean = false, sharedModule: Option[BaseModule] = None, gradReq: String = "write"): Unit

    Bind the symbols to construct executors.

    Bind the symbols to construct executors. This is necessary before one can perform computation with the module.

    dataShapes

    Typically is dataIter.provideData.

    labelShapes

    Typically is data_iter.provide_label.

    forTraining

    Default is true. Whether the executors should be bind for training.

    inputsNeedGrad

    Default is false. Whether the gradients to the input data need to be computed. Typically this is not needed. But this might be needed when implementing composition of modules.

    forceRebind

    Default is false. This function does nothing if the executors are already binded. But with this true, the executors will be forced to rebind.

    sharedModule

    Default is None. This is used in bucketing. When not None, the shared module essentially corresponds to a different bucket -- a module with different symbol but with the same sets of parameters (e.g. unrolled RNNs with different lengths).

    gradReq

    Requirement for gradient accumulation (globally). Can be 'write', 'add', or 'null' (default to 'write').

    Definition Classes
    SequentialModuleBaseModule
  8. def bind(forTraining: Boolean, inputsNeedGrad: Boolean, forceRebind: Boolean, dataShape: DataDesc*): Unit

    Bind the symbols to construct executors.

    Bind the symbols to construct executors. This is necessary before one can perform computation with the module.

    forTraining

    Default is True. Whether the executors should be bind for training.

    inputsNeedGrad

    Default is False. Whether the gradients to the input data need to be computed. Typically this is not needed. But this might be needed when implementing composition of modules.

    forceRebind

    Default is False. This function does nothing if the executors are already binded. But with this True, the executors will be forced to rebind.

    dataShape

    Typically is DataIter.provideData.

    Definition Classes
    BaseModule
    Annotations
    @varargs()
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def dataNames: IndexedSeq[String]

    returns

    A list of names for data required by this module.

    Definition Classes
    SequentialModuleBaseModule
  11. def dataShapes: IndexedSeq[DataDesc]

    Get data shapes.

    Get data shapes.

    returns

    The data shapes of the first module is the data shape of a SequentialModule.

    Definition Classes
    SequentialModuleBaseModule
  12. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  14. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  15. def fit(trainData: DataIter, evalData: Option[DataIter] = None, numEpoch: Int = 1, fitParams: FitParams = new FitParams): Unit

    Train the module parameters.

    Train the module parameters.

    trainData
    evalData

    If not None, will be used as validation set and evaluate the performance after each epoch.

    numEpoch

    Number of epochs to run training.

    fitParams

    Extra parameters for training.

    Definition Classes
    BaseModule
  16. def forward(dataBatch: DataBatch, isTrain: Option[Boolean] = None): Unit

    Forward computation.

    Forward computation.

    dataBatch

    input data

    isTrain

    Default is None, which means isTrain takes the value of forTraining.

    Definition Classes
    SequentialModuleBaseModule
  17. def forward(dataBatch: DataBatch, isTrain: Boolean): Unit

    Forward computation.

    Forward computation.

    dataBatch

    a batch of data.

    isTrain

    Whether it is for training or not.

    Definition Classes
    BaseModule
  18. def forwardBackward(dataBatch: DataBatch): Unit

    Definition Classes
    BaseModule
  19. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  20. def getInputGrads(): IndexedSeq[IndexedSeq[NDArray]]

    Get the gradients to the inputs, computed in the previous backward computation.

    Get the gradients to the inputs, computed in the previous backward computation.

    returns

    In the case when data-parallelism is used, the grads will be collected from multiple devices. The results will look like [ [grad1_dev1, grad1_dev2], [grad2_dev1, grad2_dev2] ], those NDArray might live on different devices.

    Definition Classes
    SequentialModuleBaseModule
  21. def getInputGradsMerged(): IndexedSeq[NDArray]

    Get the gradients to the inputs, computed in the previous backward computation.

    Get the gradients to the inputs, computed in the previous backward computation.

    returns

    In the case when data-parallelism is used, the grads will be merged from multiple devices, as they look like from a single executor. The results will look like [grad1, grad2]

    Definition Classes
    SequentialModuleBaseModule
  22. def getOutputs(): IndexedSeq[IndexedSeq[NDArray]]

    Get outputs of the previous forward computation.

    Get outputs of the previous forward computation.

    returns

    In the case when data-parallelism is used, the outputs will be collected from multiple devices. The results will look like [ [out1_dev1, out1_dev2], [out2_dev1, out2_dev2] ], those NDArray might live on different devices.

    Definition Classes
    SequentialModuleBaseModule
  23. def getOutputsMerged(): IndexedSeq[NDArray]

    Get outputs of the previous forward computation.

    Get outputs of the previous forward computation.

    returns

    In the case when data-parallelism is used, the outputs will be merged from multiple devices, as they look like from a single executor. The results will look like [out1, out2]

    Definition Classes
    SequentialModuleBaseModule
  24. def getParams: (Map[String, NDArray], Map[String, NDArray])

    Get current parameters.

    Get current parameters.

    returns

    (argParams, auxParams), each a Map of name to parameters (in NDArray) mapping.

    Definition Classes
    SequentialModuleBaseModule
  25. def getSymbol: Symbol

    Definition Classes
    BaseModule
  26. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  27. def initOptimizer(kvstore: String = "local", optimizer: Optimizer = new SGD(), resetOptimizer: Boolean = true, forceInit: Boolean = false): Unit

    Install and initialize optimizers.

    Install and initialize optimizers.

    kvstore
    optimizer
    resetOptimizer

    Default True, indicating whether we should set rescaleGrad & idx2name for optimizer according to executorGroup

    forceInit

    Default False, indicating whether we should force re-initializing the optimizer in the case an optimizer is already installed.

    Definition Classes
    SequentialModuleBaseModule
  28. def initParams(initializer: Initializer = new Uniform(0.01f), argParams: Map[String, NDArray] = null, auxParams: Map[String, NDArray] = null, allowMissing: Boolean = false, forceInit: Boolean = false, allowExtra: Boolean = false): Unit

    Initialize the parameters and auxiliary states.

    Initialize the parameters and auxiliary states.

    initializer

    Called to initialize parameters if needed.

    argParams

    If not None, should be a dictionary of existing arg_params. Initialization will be copied from that.

    auxParams

    If not None, should be a dictionary of existing aux_params. Initialization will be copied from that.

    allowMissing

    If true, params could contain missing values, and the initializer will be called to fill those missing params.

    forceInit

    If true, will force re-initialize even if already initialized.

    allowExtra

    Whether allow extra parameters that are not needed by symbol. If this is True, no error will be thrown when argParams or auxParams contain extra parameters that is not needed by the executor.

    Definition Classes
    SequentialModuleBaseModule
  29. def installMonitor(monitor: Monitor): Unit

    Definition Classes
    SequentialModuleBaseModule
  30. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  31. def labelShapes: IndexedSeq[DataDesc]

    Get label shapes.

    Get label shapes.

    returns

    The return value could be null if the module does not need labels, or if the module is not binded for training (in this case, label information is not available).

    Definition Classes
    SequentialModuleBaseModule
  32. def loadParams(fname: String): Unit

    Load model parameters from file.

    Load model parameters from file.

    fname

    Path to input param file.

    Definition Classes
    BaseModule
    Annotations
    @throws( classOf[IOException] )
    Exceptions thrown

    IOException if param file is invalid

  33. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  34. final def notify(): Unit

    Definition Classes
    AnyRef
  35. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  36. def outputDesc: IndexedSeq[DataDesc]

    Get output shapes.

    Get output shapes.

    returns

    The output shapes of the last module is the output shape of a SequentialModule.

  37. def outputNames: IndexedSeq[String]

    returns

    A list of names for the outputs of this module.

    Definition Classes
    SequentialModuleBaseModule
  38. def outputShapes: IndexedSeq[(String, Shape)]

    Get output shapes.

    Get output shapes.

    returns

    The output shapes of the last module is the output shape of a SequentialModule.

    Definition Classes
    SequentialModuleBaseModule
  39. def predict(evalData: DataIter, numBatch: Int = 1, reset: Boolean = true): IndexedSeq[NDArray]

    Run prediction and collect the outputs.

    Run prediction and collect the outputs.

    evalData

    dataIter to do the Inference

    numBatch

    Default is -1, indicating running all the batches in the data iterator.

    reset

    Default is True, indicating whether we should reset the data iter before start doing prediction.

    returns

    The return value will be a list [out1, out2, out3]. The concatenation process will be like

    outputBatches = [
      [a1, a2, a3], // batch a
      [b1, b2, b3]  // batch b
    ]
    result = [
      NDArray, // [a1, b1]
      NDArray, // [a2, b2]
      NDArray, // [a3, b3]
    ]

    Where each element is concatenation of the outputs for all the mini-batches.

    Definition Classes
    BaseModule
  40. def predict(batch: DataBatch): IndexedSeq[NDArray]

    Definition Classes
    BaseModule
  41. def predictEveryBatch(evalData: DataIter, numBatch: Int = 1, reset: Boolean = true): IndexedSeq[IndexedSeq[NDArray]]

    Run prediction and collect the outputs.

    Run prediction and collect the outputs.

    evalData
    numBatch

    Default is -1, indicating running all the batches in the data iterator.

    reset

    Default is True, indicating whether we should reset the data iter before start doing prediction.

    returns

    The return value will be a nested list like [ [out1_batch1, out2_batch1, ...], [out1_batch2, out2_batch2, ...] ] This mode is useful because in some cases (e.g. bucketing), the module does not necessarily produce the same number of outputs.

    Definition Classes
    BaseModule
  42. def saveParams(fname: String): Unit

    Save model parameters to file.

    Save model parameters to file.

    fname

    Path to output param file.

    Definition Classes
    BaseModule
  43. def score(evalData: DataIter, evalMetric: EvalMetric, numBatch: Int = Integer.MAX_VALUE, batchEndCallback: Option[BatchEndCallback] = None, scoreEndCallback: Option[BatchEndCallback] = None, reset: Boolean = true, epoch: Int = 0): EvalMetric

    Run prediction on eval_data and evaluate the performance according to eval_metric.

    Run prediction on eval_data and evaluate the performance according to eval_metric.

    evalData

    : DataIter

    evalMetric

    : EvalMetric

    numBatch

    Number of batches to run. Default is Integer.MAX_VALUE, indicating run until the DataIter finishes.

    batchEndCallback

    Could also be a list of functions.

    reset

    Default True, indicating whether we should reset eval_data before starting evaluating.

    epoch

    Default 0. For compatibility, this will be passed to callbacks (if any). During training, this will correspond to the training epoch number.

    Definition Classes
    BaseModule
  44. def setParams(argParams: Map[String, NDArray], auxParams: Map[String, NDArray], allowMissing: Boolean = false, forceInit: Boolean = true, allowExtra: Boolean = false): Unit

    Assign parameter and aux state values.

    Assign parameter and aux state values. argParams : dict Dictionary of name to value (NDArray) mapping. auxParams : dict Dictionary of name to value (NDArray) mapping. allowMissing : bool If true, params could contain missing values, and the initializer will be called to fill those missing params. forceInit : bool If true, will force re-initialize even if already initialized. allowExtra : bool Whether allow extra parameters that are not needed by symbol. If this is True, no error will be thrown when argParams or auxParams contain extra parameters that is not needed by the executor.

    Definition Classes
    BaseModule
  45. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  46. def toString(): String

    Definition Classes
    AnyRef → Any
  47. def update(): Unit

    Definition Classes
    SequentialModuleBaseModule
  48. def updateMetric(evalMetric: EvalMetric, labels: IndexedSeq[NDArray]): Unit

    Evaluate and accumulate evaluation metric on outputs of the last forward computation.

    Evaluate and accumulate evaluation metric on outputs of the last forward computation.

    evalMetric
    labels

    Definition Classes
    SequentialModuleBaseModule
  49. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  50. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  51. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from BaseModule

Inherited from AnyRef

Inherited from Any

Ungrouped