Last active
January 17, 2019 17:16
-
-
Save geokats/167b18603d4be7b5ff8f9007bfdec7b6 to your computer and use it in GitHub Desktop.
DL4J ComputationGraph throw exceptions on a) RepeatVector on dataset without masks b) ElementWiseVertex on dataset with masks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exception in thread "main" java.lang.IllegalStateException: Backprop: array (ACTIVATION_GRAD) workspace validation failed (vertex att_repeat - class: RepeatVector) - array is defined in incorrect workspace | |
at org.deeplearning4j.nn.graph.ComputationGraph.validateArrayWorkspaces(ComputationGraph.java:1866) | |
at org.deeplearning4j.nn.graph.ComputationGraph.calcBackpropGradients(ComputationGraph.java:2642) | |
at org.deeplearning4j.nn.graph.ComputationGraph.computeGradientAndScore(ComputationGraph.java:1361) | |
at org.deeplearning4j.nn.graph.ComputationGraph.computeGradientAndScore(ComputationGraph.java:1321) | |
at org.deeplearning4j.optimize.solvers.BaseOptimizer.gradientAndScore(BaseOptimizer.java:160) | |
at org.deeplearning4j.optimize.solvers.StochasticGradientDescent.optimize(StochasticGradientDescent.java:63) | |
at org.deeplearning4j.optimize.Solver.optimize(Solver.java:52) | |
at org.deeplearning4j.nn.graph.ComputationGraph.fitHelper(ComputationGraph.java:1145) | |
at org.deeplearning4j.nn.graph.ComputationGraph.fit(ComputationGraph.java:1095) | |
at org.deeplearning4j.nn.graph.ComputationGraph.fit(ComputationGraph.java:1082) | |
at org.deeplearning4j.nn.graph.ComputationGraph.fit(ComputationGraph.java:962) | |
at org.katso.issue.main(issue.java:73) | |
Caused by: org.nd4j.linalg.workspace.ND4JWorkspaceException: Array workspace validation failed: Array of type ACTIVATION_GRAD should be in workspace "WS_LAYER_ACT_2" but is in workspace "WS_LAYER_WORKING_MEM" | |
at org.nd4j.linalg.workspace.BaseWorkspaceMgr.validateArrayLocation(BaseWorkspaceMgr.java:238) | |
at org.deeplearning4j.nn.workspace.LayerWorkspaceMgr.validateArrayLocation(LayerWorkspaceMgr.java:86) | |
at org.deeplearning4j.nn.graph.ComputationGraph.validateArrayWorkspaces(ComputationGraph.java:1857) | |
... 11 more |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exception in thread "main" java.lang.IllegalArgumentException: Op.Z type must be bool: z.datatype=FLOAT for op class org.nd4j.linalg.api.ops.impl.transforms.pairwise.bool.Or | |
at org.nd4j.base.Preconditions.throwEx(Preconditions.java:636) | |
at org.nd4j.base.Preconditions.checkArgument(Preconditions.java:137) | |
at org.nd4j.linalg.api.ops.BaseTransformBoolOp.validateDataTypes(BaseTransformBoolOp.java:106) | |
at org.nd4j.linalg.cpu.nativecpu.ops.NativeOpExecutioner.exec(NativeOpExecutioner.java:742) | |
at org.nd4j.linalg.cpu.nativecpu.ops.NativeOpExecutioner.exec(NativeOpExecutioner.java:126) | |
at org.deeplearning4j.nn.graph.vertex.impl.ElementWiseVertex.feedForwardMaskArrays(ElementWiseVertex.java:211) | |
at org.deeplearning4j.nn.graph.ComputationGraph.setLayerMaskArrays(ComputationGraph.java:3728) | |
at org.deeplearning4j.nn.graph.ComputationGraph.fitHelper(ComputationGraph.java:1113) | |
at org.deeplearning4j.nn.graph.ComputationGraph.fit(ComputationGraph.java:1095) | |
at org.deeplearning4j.nn.graph.ComputationGraph.fit(ComputationGraph.java:960) | |
at org.katso.issue.main(issue.java:76) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration; | |
import org.deeplearning4j.nn.conf.NeuralNetConfiguration; | |
import org.deeplearning4j.nn.conf.graph.ElementWiseVertex; | |
import org.deeplearning4j.nn.conf.graph.PreprocessorVertex; | |
import org.deeplearning4j.nn.conf.inputs.InputType; | |
import org.deeplearning4j.nn.conf.layers.*; | |
import org.deeplearning4j.nn.conf.layers.misc.RepeatVector; | |
import org.deeplearning4j.nn.conf.layers.recurrent.Bidirectional; | |
import org.deeplearning4j.nn.conf.preprocessor.ComposableInputPreProcessor; | |
import org.deeplearning4j.nn.conf.preprocessor.FeedForwardToRnnPreProcessor; | |
import org.deeplearning4j.nn.conf.preprocessor.RnnToFeedForwardPreProcessor; | |
import org.deeplearning4j.nn.graph.ComputationGraph; | |
import org.deeplearning4j.nn.modelimport.keras.preprocessors.PermutePreprocessor; | |
import org.nd4j.linalg.activations.Activation; | |
import org.nd4j.linalg.api.ndarray.INDArray; | |
import org.nd4j.linalg.dataset.DataSet; | |
import org.nd4j.linalg.factory.Nd4j; | |
import org.nd4j.linalg.learning.config.Adam; | |
import org.nd4j.linalg.lossfunctions.LossFunctions; | |
import static org.deeplearning4j.nn.conf.layers.recurrent.Bidirectional.Mode.CONCAT; | |
public class issue { | |
public static void main(String... args){ | |
int inputSize = 300; | |
int hiddenSize = 100; | |
//Build computation graph | |
ComputationGraphConfiguration configuration = new NeuralNetConfiguration.Builder() | |
.updater(new Adam()) | |
.graphBuilder() | |
.addInputs("x_emb") | |
.setInputTypes(InputType.recurrent(inputSize)) | |
//LSTM layers | |
.addLayer("agg_lstm", new Bidirectional(CONCAT, new LSTM.Builder().nIn(inputSize).nOut(hiddenSize/2).build()), "x_emb") | |
//Column attention layers | |
.addLayer("agg_att", new DenseLayer.Builder().nIn(100).nOut(1).activation(Activation.SOFTMAX).build(), "agg_lstm") | |
//Collumn attention tranformation | |
.addVertex("att", new PreprocessorVertex(new ComposableInputPreProcessor(new FeedForwardToRnnPreProcessor(), new PermutePreprocessor(new int[] {0,2,1}), new RnnToFeedForwardPreProcessor())), "agg_att") | |
.addLayer("att_repeat", new RepeatVector.Builder(hiddenSize).build(),"att") | |
.addVertex("att_trans", new PreprocessorVertex(new PermutePreprocessor(new int[] {0, 2, 1})), "att_repeat") | |
//Combine LSTM and collumn attention | |
.addVertex("mult", new ElementWiseVertex(ElementWiseVertex.Op.Product), "agg_lstm", "att_trans") | |
.addLayer("sum", new GlobalPoolingLayer.Builder().build(), "mult") | |
//Linear layers | |
.addLayer("agg_out", new DenseLayer.Builder().nIn(100).nOut(6).activation(Activation.TANH).build(), "sum") | |
//Output layer | |
.addLayer("output", new OutputLayer.Builder().nIn(6).nOut(6).lossFunction(LossFunctions.LossFunction.RECONSTRUCTION_CROSSENTROPY).build(), "agg_out") | |
.setOutputs("output") | |
.build(); | |
ComputationGraph net = new ComputationGraph(configuration); | |
net.init(); | |
//Create dummy dataset | |
int dataSize = 10; | |
int seqLen = 5; | |
INDArray features = Nd4j.rand(new int[] {dataSize, inputSize, seqLen}); | |
INDArray labels = Nd4j.rand(new int[] {dataSize, 6}); | |
INDArray featuresMask = Nd4j.ones(dataSize, seqLen); | |
INDArray labelsMask = Nd4j.ones(dataSize, 6); | |
//Running this gives exception (a) | |
DataSet dataSet1 = new DataSet(features, labels); | |
net.fit(dataSet1); | |
//Running this gives exception (b) | |
DataSet dataSet2 = new DataSet(features, labels, featuresMask, labelsMask); | |
net.fit(dataSet2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment