public class Dl4jMlpClassifier
extends weka.classifiers.RandomizableClassifier
implements weka.core.BatchPredictor, weka.core.CapabilitiesHandler, weka.classifiers.IterativeClassifier
Modifier and Type | Field and Description |
---|---|
static int |
FILTER_NONE
filter: No normalization/standardization.
|
static int |
FILTER_NORMALIZE
filter: Normalize training data.
|
static int |
FILTER_STANDARDIZE
filter: Standardize training data.
|
static weka.core.Tag[] |
TAGS_FILTER
The filter to apply to the training data.
|
Constructor and Description |
---|
Dl4jMlpClassifier()
Instantiate the model.
|
Modifier and Type | Method and Description |
---|---|
boolean |
arithmeticUnderflow(org.nd4j.linalg.api.ndarray.INDArray array)
Checks the array (as output from ComputationGraph.outputSingle()) for arithmetic underflow
|
void |
buildClassifier(weka.core.Instances data)
The method used to train the classifier.
|
double[] |
distributionForInstance(weka.core.Instance inst)
The method to use when making a prediction for a test instance.
|
double[][] |
distributionsForInstances(weka.core.Instances insts)
The method to use when making predictions for test instances.
|
void |
done()
Clean up after learning.
|
org.nd4j.linalg.api.ndarray.INDArray |
featurizeForLayer(java.lang.String layerName,
org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter,
PoolingType poolingType)
Uses the DL4J TransferLearningHelper to featurize the instances using activations from the given layer
|
weka.core.Instances |
getActivationsAtLayers(java.lang.String[] layerNames,
weka.core.Instances input)
Overridden method - if no pooling type is given then set it to NONE
Uses the given set of layers to extract features for the given dataset
|
weka.core.Instances |
getActivationsAtLayers(java.lang.String[] layerNames,
weka.core.Instances input,
PoolingType poolingType)
Uses the given set of layers to extract features for the given dataset
|
CacheMode |
getCacheMode() |
weka.core.Capabilities |
getCapabilities()
Returns default capabilities of the classifier.
|
boolean |
getDoNotClearFilesystemCache() |
EarlyStopping |
getEarlyStopping() |
weka.core.SelectedTag |
getFilterType() |
org.deeplearning4j.nn.conf.inputs.InputType.InputTypeConvolutional |
getInputShape(CustomModelSetup customModelSetup) |
AbstractInstanceIterator |
getInstanceIterator() |
TrainingListener |
getIterationListener() |
Layer[] |
getLayers() |
boolean |
getLoadLayerSpecification() |
LogConfiguration |
getLogConfig()
Get the log configuration.
|
org.deeplearning4j.nn.graph.ComputationGraph |
getModel()
Get the
ComputationGraph model |
java.lang.String |
getModelName()
Get the name of the loaded model
|
NeuralNetConfiguration |
getNeuralNetConfiguration() |
int |
getNumEpochs() |
int |
getNumGPUs() |
int |
getParameterAveragingFrequency() |
int |
getPrefetchBufferSize() |
int |
getQueueSize() |
boolean |
getResume()
Returns true if the model is to be finalized (or has been finalized) after training.
|
AbstractZooModel |
getZooModel()
Get the modelzoo model
|
java.lang.String |
globalInfo()
.
|
boolean |
implementsMoreEfficientBatchPrediction()
Performs efficient batch prediction
|
void |
initializeClassifier(weka.core.Instances data)
The method used to initialize the classifier.
|
boolean |
isFilterMode() |
static boolean |
isValidOutputLayer(boolean filterMode,
org.deeplearning4j.nn.conf.layers.Layer layer)
Checks if the layer is a valid output layer
|
static Dl4jMlpClassifier |
loadInferenceModel(java.io.File serializedModelFile,
AbstractZooModel zooModelType)
Load a Dl4jMlpClassifier for use in the Inference Panel - no need to supply Instances or InstanceIterators
|
static Dl4jMlpClassifier |
loadModel(weka.core.Instances data,
java.io.File serializedModelFile,
AbstractZooModel zooModelType,
AbstractInstanceIterator instanceIterator)
Load a Dl4jMlpClassifier for use with the given instances and iterator
|
void |
loadZooModelNoData(int numClasses,
long seed,
int[] newShape)
Load a ComputationGraph without any data - used in the Dl4j Inference panel
|
static void |
main(java.lang.String[] argv)
The main method for running this class.
|
boolean |
next()
Perform another epoch.
|
org.nd4j.linalg.api.ndarray.INDArray |
outputSingle(org.nd4j.linalg.api.ndarray.INDArray image)
Convenience method to allow the Dl4j Inference panel to call outputSingle for a single image
|
void |
setCacheMode(CacheMode cm) |
void |
setDoNotClearFilesystemCache(boolean clear) |
void |
setEarlyStopping(EarlyStopping config) |
void |
setFilterMode(boolean filterMode) |
void |
setFilterType(weka.core.SelectedTag newType) |
void |
setInstanceIterator(AbstractInstanceIterator iterator) |
void |
setIterationListener(TrainingListener l) |
void |
setLayers(Layer... layers) |
void |
setLoadLayerSpecification(boolean loadLayerSpecification) |
void |
setLogConfig(LogConfiguration logConfig)
Set the log configuration.
|
void |
setNeuralNetConfiguration(NeuralNetConfiguration config) |
void |
setNumEpochs(int numEpochs) |
void |
setNumGPUs(int numGPUs) |
void |
setParameterAveragingFrequency(int frequency) |
void |
setPrefetchBufferSize(int prefetchBufferSize) |
void |
setQueueSize(int QueueSize) |
void |
setResume(boolean resume)
If called with argument true, then the next time done() is called the model is effectively
"frozen" and no further iterations can be performed
|
void |
setZooModel(AbstractZooModel zooModel)
Set the modelzoo zooModel
|
static weka.core.Instances[] |
splitTrainVal(weka.core.Instances data,
double p)
Split the dataset into p% train an (100-p)% test set.
|
java.lang.String |
toString()
Returns a string describing the model.
|
static Dl4jMlpClassifier |
tryLoadFromFile(java.io.File serializedModelFile,
AbstractZooModel zooModelType)
Tries to load from a saved model file (if it exists), otherwise loads the given zoo model
|
boolean |
useEarlyStopping()
Use early stopping only if valid split percentage
|
boolean |
useZooModel()
Check if the user has selected to use a zoomodel
|
getOptions, getSeed, listOptions, seedTipText, setOptions, setSeed
batchSizeTipText, classifyInstance, debugTipText, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, getRevision, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
public static final int FILTER_NORMALIZE
public static final int FILTER_STANDARDIZE
public static final int FILTER_NONE
public static final weka.core.Tag[] TAGS_FILTER
public static void main(java.lang.String[] argv)
argv
- the command-line argumentspublic static weka.core.Instances[] splitTrainVal(weka.core.Instances data, double p) throws java.lang.Exception
data
- Input datap
- train percentagejava.lang.Exception
- Filterapplication went wrongpublic LogConfiguration getLogConfig()
@OptionMetadata(displayName="log config", description="The log configuration.", commandLineParamName="logConfig", commandLineParamSynopsis="-logConfig <LogConfiguration>", displayOrder=1) public void setLogConfig(LogConfiguration logConfig)
logConfig
- Log configurationpublic java.lang.String globalInfo()
public weka.core.Capabilities getCapabilities()
getCapabilities
in interface weka.classifiers.Classifier
getCapabilities
in interface weka.core.CapabilitiesHandler
getCapabilities
in class weka.classifiers.AbstractClassifier
public Layer[] getLayers()
@OptionMetadata(displayName="layer specification.", description="The specification of a layer. This option can be used multiple times.", commandLineParamName="layer", commandLineParamSynopsis="-layer <string>", displayOrder=2) public void setLayers(Layer... layers)
public int getNumEpochs()
@OptionMetadata(description="The number of epochs to perform.", displayName="number of epochs", commandLineParamName="numEpochs", commandLineParamSynopsis="-numEpochs <int>", displayOrder=4) public void setNumEpochs(int numEpochs)
@OptionMetadata(description="The instance trainIterator to use.", displayName="instance iterator", commandLineParamName="iterator", commandLineParamSynopsis="-iterator <string>", displayOrder=6) public AbstractInstanceIterator getInstanceIterator()
public void setInstanceIterator(AbstractInstanceIterator iterator)
@OptionMetadata(description="The neural network configuration to use.", displayName="network configuration", commandLineParamName="config", commandLineParamSynopsis="-config <string>", displayOrder=7) public NeuralNetConfiguration getNeuralNetConfiguration()
public void setNeuralNetConfiguration(NeuralNetConfiguration config)
@OptionMetadata(description="The early stopping configuration to use.", displayName="early stopping", commandLineParamName="early-stopping", commandLineParamSynopsis="-early-stopping <string>", displayOrder=7) public EarlyStopping getEarlyStopping()
public void setEarlyStopping(EarlyStopping config)
@OptionMetadata(description="The type of normalization to perform.", displayName="attribute normalization", commandLineParamName="normalization", commandLineParamSynopsis="-normalization <int>", displayOrder=12) public weka.core.SelectedTag getFilterType()
public void setFilterType(weka.core.SelectedTag newType)
public int getQueueSize()
@OptionMetadata(description="The queue size for asynchronous data transfer (default: 0, synchronous transfer).", displayName="data queue size", commandLineParamName="queueSize", commandLineParamSynopsis="-queueSize <int>", displayOrder=30) public void setQueueSize(int QueueSize)
public boolean getResume()
getResume
in interface weka.classifiers.IterativeClassifier
@OptionMetadata(description="Set whether training can be resumed at a later date", displayName="resume", commandLineParamName="resume", commandLineParamSynopsis="-resume", commandLineParamIsFlag=true, displayOrder=31) public void setResume(boolean resume)
setResume
in interface weka.classifiers.IterativeClassifier
resume
- true if the model is to be finalized after performing iterationspublic boolean getLoadLayerSpecification()
@OptionMetadata(description="Set whether you want the GUI to load the layer specification when selecting a zoo model. This does not affect the model\'s function, but simply allows you to view the model\'s layers. You may need to click \'OK\' and open this window again for this setting to come into effect.", displayName="Preview zoo model layer specification in GUI", commandLineParamName="load-layer-spec", commandLineParamSynopsis="-load-layer-spec", commandLineParamIsFlag=true, displayOrder=3) public void setLoadLayerSpecification(boolean loadLayerSpecification)
public boolean getDoNotClearFilesystemCache()
@OptionMetadata(displayName="Preserve filesystem cache", description="If true, the filesystem cache will not be cleared when starting or resuming training of a model. This can save time on data preparation for a given problem, but will cause errors if a dataset different to that in the cache is used", commandLineParamName="preserve-file-cache", commandLineParamSynopsis="-preserve-file-cache", commandLineParamIsFlag=true, displayOrder=32) public void setDoNotClearFilesystemCache(boolean clear)
public int getNumGPUs()
@OptionMetadata(displayName="Number of GPUs", description="Number of available GPUs (ignored if no GPU backend available)", commandLineParamName="numGPUs", commandLineParamSynopsis="-numGPUs <integer>", displayOrder=33) public void setNumGPUs(int numGPUs)
public int getPrefetchBufferSize()
@OptionMetadata(displayName="Size of prefetch buffer for multiple GPUs", description="Size of the prefetch buffer that will be used for background data prefetching (0 = disable prefetch). Ignored if there is only one GPU, or no GPU backend available.", commandLineParamName="prefetchSize", commandLineParamSynopsis="-prefetchSize <integer>", displayOrder=34) public void setPrefetchBufferSize(int prefetchBufferSize)
public int getParameterAveragingFrequency()
@OptionMetadata(displayName="Model parameter averaging frequency", description="How often (in iterations, not epochs) to average model parameters when leveraging multiple GPUs (ignored if there is only one GPU, or no GPU backend available). Set no greater than num instances/num GPUs or no averaging will occur!", commandLineParamName="averagingFrequency", commandLineParamSynopsis="-averagingFrequency <integer>", displayOrder=35) public void setParameterAveragingFrequency(int frequency)
public java.lang.String getModelName()
public void buildClassifier(weka.core.Instances data) throws java.lang.Exception
buildClassifier
in interface weka.classifiers.Classifier
data
- set of instances serving as training datajava.lang.Exception
- if something goes wrong in the training processpublic static boolean isValidOutputLayer(boolean filterMode, org.deeplearning4j.nn.conf.layers.Layer layer)
filterMode
- true if the model is being used for a filterlayer
- output layer of the modelpublic void initializeClassifier(weka.core.Instances data) throws java.lang.Exception
initializeClassifier
in interface weka.classifiers.IterativeClassifier
data
- set of instances serving as training datajava.lang.Exception
- if something goes wrong in the training processpublic org.deeplearning4j.nn.conf.inputs.InputType.InputTypeConvolutional getInputShape(CustomModelSetup customModelSetup)
public void loadZooModelNoData(int numClasses, long seed, int[] newShape)
numClasses
- Number of classes to load withseed
- Random seednewShape
- Input shapepublic org.nd4j.linalg.api.ndarray.INDArray outputSingle(org.nd4j.linalg.api.ndarray.INDArray image)
image
- Image to predict forpublic boolean next() throws java.lang.Exception
next
in interface weka.classifiers.IterativeClassifier
java.lang.Exception
public boolean useEarlyStopping()
public void done()
done
in interface weka.classifiers.IterativeClassifier
public AbstractZooModel getZooModel()
@OptionMetadata(displayName="zooModel", description="The model-architecture to choose from the modelzoo (default = no model).", commandLineParamName="zooModel", commandLineParamSynopsis="-zooModel <string>", displayOrder=11) public void setZooModel(AbstractZooModel zooModel)
zooModel
- The predefined zooModelpublic static Dl4jMlpClassifier tryLoadFromFile(java.io.File serializedModelFile, AbstractZooModel zooModelType) throws weka.core.WekaException
serializedModelFile
- Saved model pathzooModelType
- Type of Zoo Modelweka.core.WekaException
- From errors occurring during loading the model filepublic static Dl4jMlpClassifier loadModel(weka.core.Instances data, java.io.File serializedModelFile, AbstractZooModel zooModelType, AbstractInstanceIterator instanceIterator) throws java.lang.Exception
data
- Instances to prime the model withserializedModelFile
- Saved model filezooModelType
- Type of Zoo ModelinstanceIterator
- Instance iterator to prime the model withjava.lang.Exception
- From errors occurring during loading the model file, or from intializing from the datapublic static Dl4jMlpClassifier loadInferenceModel(java.io.File serializedModelFile, AbstractZooModel zooModelType) throws weka.core.WekaException
serializedModelFile
- Saved model filezooModelType
- Type of Zoo Modelweka.core.WekaException
- From errors occurring during loading the model file, or from intializing from the datapublic TrainingListener getIterationListener()
@OptionMetadata(displayName="set the iteration listener", description="Set the iteration listener.", commandLineParamName="iteration-listener", commandLineParamSynopsis="-iteration-listener <string>", displayOrder=9) public void setIterationListener(TrainingListener l)
public CacheMode getCacheMode()
@OptionMetadata(displayName="set the cache mode", description="Set the cache mode.", commandLineParamName="cache-mode", commandLineParamSynopsis="-cache-mode <string>", displayOrder=13) public void setCacheMode(CacheMode cm)
public boolean isFilterMode()
@ProgrammaticProperty public void setFilterMode(boolean filterMode)
public boolean implementsMoreEfficientBatchPrediction()
implementsMoreEfficientBatchPrediction
in interface weka.core.BatchPredictor
implementsMoreEfficientBatchPrediction
in class weka.classifiers.AbstractClassifier
public double[] distributionForInstance(weka.core.Instance inst) throws java.lang.Exception
distributionForInstance
in interface weka.classifiers.Classifier
distributionForInstance
in class weka.classifiers.AbstractClassifier
inst
- the instance to get a prediction forjava.lang.Exception
- if something goes wrong at prediction timepublic boolean arithmeticUnderflow(org.nd4j.linalg.api.ndarray.INDArray array)
array
- Array to checkpublic double[][] distributionsForInstances(weka.core.Instances insts) throws java.lang.Exception
distributionsForInstances
in interface weka.core.BatchPredictor
distributionsForInstances
in class weka.classifiers.AbstractClassifier
insts
- the instances to get predictions forjava.lang.Exception
- if something goes wrong at prediction timepublic org.deeplearning4j.nn.graph.ComputationGraph getModel()
ComputationGraph
modelpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean useZooModel()
public weka.core.Instances getActivationsAtLayers(java.lang.String[] layerNames, weka.core.Instances input) throws java.lang.Exception
layerNames
- Layerinput
- data to featurizejava.lang.Exception
public org.nd4j.linalg.api.ndarray.INDArray featurizeForLayer(java.lang.String layerName, org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter, PoolingType poolingType) throws java.lang.Exception
layerName
- layer activations to use for instancesiter
- iterator for the instancespoolingType
- pooling type to be used (only necessary if using intermediary layers with 3D activations)java.lang.Exception
public weka.core.Instances getActivationsAtLayers(java.lang.String[] layerNames, weka.core.Instances input, PoolingType poolingType) throws java.lang.Exception
layerNames
- Layerinput
- data to featurizepoolingType
- pooling type to usejava.lang.Exception