public class Utils
extends java.lang.Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static org.nd4j.linalg.api.ndarray.INDArray |
appendClasses(org.nd4j.linalg.api.ndarray.INDArray result,
weka.core.Instances input)
Appends the input Instances classes to the INDArray.
|
static double |
computeScore(org.deeplearning4j.nn.graph.ComputationGraph model,
org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
Compute the model score on a given iterator.
|
static weka.core.Instances |
convertToInstances(org.nd4j.linalg.api.ndarray.INDArray result,
weka.core.Instances input,
java.util.Map<java.lang.String,java.lang.Long> attributesPerLayer)
Converts the newly transformed instances to an Instances object.
|
static weka.core.Attribute |
copyNominalAttribute(weka.core.Attribute oldAttribute)
Copies the attribute name and values of a given nominal attribute.
|
static org.deeplearning4j.nn.conf.inputs.InputType.InputTypeConvolutional |
decodeCNNShape(int[] shape)
Decode a CNN Input shape.
|
static org.deeplearning4j.nn.conf.inputs.InputType.InputTypeConvolutional |
decodeCNNShape(long[] shape)
Decode a CNN Input shape.
|
static java.lang.String |
defaultFileLocation()
The default location for a file parameter.
|
static java.lang.String |
getAttributeName(java.util.Map<java.lang.String,java.lang.Long> attributesPerLayer,
int i)
Helper function for getting the new layer name when using the Dl4jMlpFilter
The attributes are named after the layer they originated from, so this function
counts throught the attributes per layer, comparing it with the given index
to determine a) which layer the activation came from and b) which number activation
this is.
|
static <T> T |
getFieldValue(java.lang.Object obj,
java.lang.String fieldName)
Access private field of a given object.
|
static org.nd4j.linalg.dataset.DataSet |
getNext(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
Fix for issue with JVM crashing
https://github.com/eclipse/deeplearning4j/issues/8976#issuecomment-639946904
It is recommended to use this helper function in WekaDeeplearning4j rather than using iter.next() directly.
|
static org.nd4j.linalg.dataset.DataSet |
getNext(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter,
int num)
Fix for issue with JVM crashing
https://github.com/eclipse/deeplearning4j/issues/8976#issuecomment-639946904
It is recommended to use this helper function in WekaDeeplearning4j rather than using iter.next() directly.
|
static org.nd4j.linalg.dataset.DataSet |
instancesToConvDataSet(weka.core.Instances insts,
int height,
int width,
int channels)
Converts a set of training instances to a DataSet prepared for the convolution operation using
the height, width and number of channels.
|
static org.nd4j.linalg.dataset.DataSet |
instancesToDataSet(weka.core.Instances insts)
Converts a set of training instances to a DataSet.
|
static <T> T |
invokeMethod(java.lang.Object obj,
java.lang.String methodName,
java.lang.Object... args)
Invoke a method on a given object.
|
static boolean |
isChannelsLast(org.nd4j.linalg.api.ndarray.INDArray activations)
Shape will either be something like [1, 56, 56, 128] or [1, 128, 56, 56]
If it's the former then return true.
|
static weka.core.Instances |
ndArrayToInstances(org.nd4j.linalg.api.ndarray.INDArray ndArray,
weka.core.Instances inputFormat,
java.util.Map<java.lang.String,java.lang.Long> attributesPerLayer)
Convert an arbitrary NDArray to Weka instances.
|
static boolean |
needsReshaping(org.nd4j.linalg.api.ndarray.INDArray activationAtLayer)
Determines if the activations need reshaping.
|
static boolean |
notDefaultFileLocation(java.io.File file)
Checks if the given file isn't the default file location (i.e., the user has selected a file).
|
static boolean |
pathExists(java.lang.String path)
Checks whether the path exists - a little tidier than the code it wraps.
|
static float |
poolNDArray(org.nd4j.linalg.api.ndarray.INDArray array,
PoolingType poolingType)
Applies the pooling function to the given feature map.
|
static org.nd4j.linalg.api.ndarray.INDArray |
reshapeActivations(org.nd4j.linalg.api.ndarray.INDArray activationAtLayer,
PoolingType poolingType)
Reshape the activations, either by pooling or simply multiplying the extra dimensions together.
|
static void |
runWithLocalClassloader(java.lang.Class clz,
VoidCallable block)
Run some code-block using the local class loader from a given class.
|
static <T> void |
setFieldValue(java.lang.Object obj,
java.lang.String fieldName,
T value)
Set private field of a given object.
|
public static org.nd4j.linalg.dataset.DataSet instancesToDataSet(weka.core.Instances insts)
insts
- the instances to convertpublic static org.nd4j.linalg.dataset.DataSet instancesToConvDataSet(weka.core.Instances insts, int height, int width, int channels)
height
- image heightwidth
- image widthchannels
- number of image channelsinsts
- the instances to convertpublic static double computeScore(org.deeplearning4j.nn.graph.ComputationGraph model, org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
model
- Modeliter
- Iteratorpublic static weka.core.Attribute copyNominalAttribute(weka.core.Attribute oldAttribute)
oldAttribute
- attribute to copypublic static java.lang.String getAttributeName(java.util.Map<java.lang.String,java.lang.Long> attributesPerLayer, int i)
attributesPerLayer
- Hashmap defining how many attributes there are per layeri
- Index of layer we're currently looking at.public static weka.core.Instances ndArrayToInstances(org.nd4j.linalg.api.ndarray.INDArray ndArray, weka.core.Instances inputFormat, java.util.Map<java.lang.String,java.lang.Long> attributesPerLayer) throws weka.core.WekaException
ndArray
- Input arrayinputFormat
- Format to use for the instancesattributesPerLayer
- Hashmap of layer names and how many attributes there are per layerweka.core.WekaException
- Invalid inputpublic static <T> T getFieldValue(java.lang.Object obj, java.lang.String fieldName)
T
- Return typeobj
- Object to be accessedfieldName
- Field namefieldName
public static <T> void setFieldValue(java.lang.Object obj, java.lang.String fieldName, T value)
T
- Field typeobj
- Object to be accessedfieldName
- Field namevalue
- Field value to be setpublic static <T> T invokeMethod(java.lang.Object obj, java.lang.String methodName, java.lang.Object... args)
T
- Return typeobj
- Object to be referencedmethodName
- Method name which is to be invokedargs
- Method argumentspublic static void runWithLocalClassloader(java.lang.Class clz, VoidCallable block)
clz
- Class to use the classloader fromblock
- Code block to runpublic static boolean needsReshaping(org.nd4j.linalg.api.ndarray.INDArray activationAtLayer)
activationAtLayer
- Activations in questionpublic static float poolNDArray(org.nd4j.linalg.api.ndarray.INDArray array, PoolingType poolingType)
array
- feature map to poolpoolingType
- pooling function to applypublic static boolean isChannelsLast(org.nd4j.linalg.api.ndarray.INDArray activations)
activations
- public static org.nd4j.linalg.api.ndarray.INDArray reshapeActivations(org.nd4j.linalg.api.ndarray.INDArray activationAtLayer, PoolingType poolingType)
activationAtLayer
- 4d activations e.g., [batch_size, 512, 64, 64]poolingType
- Pooling type to use to lower the dimensionalitypublic static org.nd4j.linalg.api.ndarray.INDArray appendClasses(org.nd4j.linalg.api.ndarray.INDArray result, weka.core.Instances input)
result
- activationsinput
- original Instancespublic static weka.core.Instances convertToInstances(org.nd4j.linalg.api.ndarray.INDArray result, weka.core.Instances input, java.util.Map<java.lang.String,java.lang.Long> attributesPerLayer) throws java.lang.Exception
result
- activations generated from feature layersinput
- original input InstancesattributesPerLayer
- Hashmap stating the feature layers and how many attributes each hasjava.lang.Exception
- File exceptionpublic static org.nd4j.linalg.dataset.DataSet getNext(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
iter
- DatasetIterator to get images frompublic static org.nd4j.linalg.dataset.DataSet getNext(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter, int num)
iter
- DatasetIterator to get images fromnum
- Batch size to getpublic static boolean pathExists(java.lang.String path)
path
- Path to checkpublic static boolean notDefaultFileLocation(java.io.File file)
file
- File to checkpublic static java.lang.String defaultFileLocation()
public static org.deeplearning4j.nn.conf.inputs.InputType.InputTypeConvolutional decodeCNNShape(int[] shape)
shape
- Shape to decodepublic static org.deeplearning4j.nn.conf.inputs.InputType.InputTypeConvolutional decodeCNNShape(long[] shape)
shape
- Shape to decode