Java Code Examples for org.deeplearning4j.nn.graph.ComputationGraph#load()
The following examples show how to use
org.deeplearning4j.nn.graph.ComputationGraph#load() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegressionTest100b4.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void testYoloHouseNumber() throws Exception { File f = Resources.asFile("regression_testing/100b4/HouseNumberDetection_100b4.bin"); ComputationGraph net = ComputationGraph.load(f, true); int nBoxes = 5; int nClasses = 10; ConvolutionLayer cl = (ConvolutionLayer) ((LayerVertex) net.getConfiguration().getVertices() .get("convolution2d_9")).getLayerConf().getLayer(); assertEquals(nBoxes * (5 + nClasses), cl.getNOut()); assertEquals(new ActivationIdentity(), cl.getActivationFn()); assertEquals(ConvolutionMode.Same, cl.getConvolutionMode()); assertEquals(new WeightInitXavier(), cl.getWeightInitFn()); assertArrayEquals(new int[]{1, 1}, cl.getKernelSize()); INDArray outExp; File f2 = Resources.asFile("regression_testing/100b4/HouseNumberDetection_Output_100b4.bin"); try (DataInputStream dis = new DataInputStream(new FileInputStream(f2))) { outExp = Nd4j.read(dis); } INDArray in; File f3 = Resources.asFile("regression_testing/100b4/HouseNumberDetection_Input_100b4.bin"); try (DataInputStream dis = new DataInputStream(new FileInputStream(f3))) { in = Nd4j.read(dis); } INDArray outAct = net.outputSingle(in); boolean eq = outExp.equalsWithEps(outAct.castTo(outExp.dataType()), 1e-3); assertTrue(eq); }
Example 2
Source File: RegressionTest100b3.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test @Ignore("AB 2019/05/23 - Failing on linux-x86_64-cuda-9.2 - see issue #7657") public void testYoloHouseNumber() throws Exception { File f = Resources.asFile("regression_testing/100b3/HouseNumberDetection_100b3.bin"); ComputationGraph net = ComputationGraph.load(f, true); int nBoxes = 5; int nClasses = 10; ConvolutionLayer cl = (ConvolutionLayer)((LayerVertex)net.getConfiguration().getVertices().get("convolution2d_9")).getLayerConf().getLayer(); assertEquals(nBoxes * (5 + nClasses), cl.getNOut()); assertEquals(new ActivationIdentity(), cl.getActivationFn()); assertEquals(ConvolutionMode.Same, cl.getConvolutionMode()); assertEquals(new WeightInitXavier(), cl.getWeightInitFn()); assertArrayEquals(new int[]{1,1}, cl.getKernelSize()); assertArrayEquals(new int[]{1,1}, cl.getKernelSize()); INDArray outExp; File f2 = Resources.asFile("regression_testing/100b3/HouseNumberDetection_Output_100b3.bin"); try(DataInputStream dis = new DataInputStream(new FileInputStream(f2))){ outExp = Nd4j.read(dis); } INDArray in; File f3 = Resources.asFile("regression_testing/100b3/HouseNumberDetection_Input_100b3.bin"); try(DataInputStream dis = new DataInputStream(new FileInputStream(f3))){ in = Nd4j.read(dis); } INDArray outAct = net.outputSingle(in); boolean eq = outExp.equalsWithEps(outAct.castTo(outExp.dataType()), 1e-3); assertTrue(eq); }
Example 3
Source File: RegressionTest100b6.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void testYoloHouseNumber() throws Exception { File f = Resources.asFile("regression_testing/100b6/HouseNumberDetection_100b6.bin"); ComputationGraph net = ComputationGraph.load(f, true); int nBoxes = 5; int nClasses = 10; ConvolutionLayer cl = (ConvolutionLayer) ((LayerVertex) net.getConfiguration().getVertices() .get("convolution2d_9")).getLayerConf().getLayer(); assertEquals(nBoxes * (5 + nClasses), cl.getNOut()); assertEquals(new ActivationIdentity(), cl.getActivationFn()); assertEquals(ConvolutionMode.Same, cl.getConvolutionMode()); assertEquals(new WeightInitXavier(), cl.getWeightInitFn()); assertArrayEquals(new int[]{1, 1}, cl.getKernelSize()); INDArray outExp; File f2 = Resources.asFile("regression_testing/100b6/HouseNumberDetection_Output_100b6.bin"); try (DataInputStream dis = new DataInputStream(new FileInputStream(f2))) { outExp = Nd4j.read(dis); } INDArray in; File f3 = Resources.asFile("regression_testing/100b6/HouseNumberDetection_Input_100b6.bin"); try (DataInputStream dis = new DataInputStream(new FileInputStream(f3))) { in = Nd4j.read(dis); } INDArray outAct = net.outputSingle(in); boolean eq = outExp.equalsWithEps(outAct.castTo(outExp.dataType()), 1e-3); assertTrue(eq); }
Example 4
Source File: TestDL4JStep.java From konduit-serving with Apache License 2.0 | 4 votes |
public INDArray[] predictFromFileCG(File f, INDArray in) throws Exception { ComputationGraph net = ComputationGraph.load(f, false); return net.output(in); }
Example 5
Source File: RegressionTest100b4.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Test public void testSyntheticBidirectionalRNNGraph() throws Exception { File f = Resources.asFile("regression_testing/100b4/SyntheticBidirectionalRNNGraph_100b4.bin"); ComputationGraph net = ComputationGraph.load(f, true); Bidirectional l0 = (Bidirectional) net.getLayer("rnn1").conf().getLayer(); LSTM l1 = (LSTM) l0.getFwd(); assertEquals(16, l1.getNOut()); assertEquals(new ActivationReLU(), l1.getActivationFn()); assertEquals(new L2Regularization(0.0001), TestUtils.getL2Reg(l1)); LSTM l2 = (LSTM) l0.getBwd(); assertEquals(16, l2.getNOut()); assertEquals(new ActivationReLU(), l2.getActivationFn()); assertEquals(new L2Regularization(0.0001), TestUtils.getL2Reg(l2)); Bidirectional l3 = (Bidirectional) net.getLayer("rnn2").conf().getLayer(); SimpleRnn l4 = (SimpleRnn) l3.getFwd(); assertEquals(16, l4.getNOut()); assertEquals(new ActivationReLU(), l4.getActivationFn()); assertEquals(new L2Regularization(0.0001), TestUtils.getL2Reg(l4)); SimpleRnn l5 = (SimpleRnn) l3.getBwd(); assertEquals(16, l5.getNOut()); assertEquals(new ActivationReLU(), l5.getActivationFn()); assertEquals(new L2Regularization(0.0001), TestUtils.getL2Reg(l5)); MergeVertex mv = (MergeVertex) net.getVertex("concat"); GlobalPoolingLayer gpl = (GlobalPoolingLayer) net.getLayer("pooling").conf().getLayer(); assertEquals(PoolingType.MAX, gpl.getPoolingType()); assertArrayEquals(new int[]{2}, gpl.getPoolingDimensions()); assertTrue(gpl.isCollapseDimensions()); OutputLayer outl = (OutputLayer) net.getLayer("out").conf().getLayer(); assertEquals(3, outl.getNOut()); assertEquals(new LossMCXENT(), outl.getLossFn()); INDArray outExp; File f2 = Resources.asFile("regression_testing/100b4/SyntheticBidirectionalRNNGraph_Output_100b4.bin"); try (DataInputStream dis = new DataInputStream(new FileInputStream(f2))) { outExp = Nd4j.read(dis); } INDArray in; File f3 = Resources.asFile("regression_testing/100b4/SyntheticBidirectionalRNNGraph_Input_100b4.bin"); try (DataInputStream dis = new DataInputStream(new FileInputStream(f3))) { in = Nd4j.read(dis); } INDArray outAct = net.output(in)[0]; assertEquals(outExp, outAct); }
Example 6
Source File: RegressionTest100b6.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Test public void testSyntheticBidirectionalRNNGraph() throws Exception { File f = Resources.asFile("regression_testing/100b6/SyntheticBidirectionalRNNGraph_100b6.bin"); ComputationGraph net = ComputationGraph.load(f, true); Bidirectional l0 = (Bidirectional) net.getLayer("rnn1").conf().getLayer(); LSTM l1 = (LSTM) l0.getFwd(); assertEquals(16, l1.getNOut()); assertEquals(new ActivationReLU(), l1.getActivationFn()); assertEquals(new L2Regularization(0.0001), TestUtils.getL2Reg(l1)); LSTM l2 = (LSTM) l0.getBwd(); assertEquals(16, l2.getNOut()); assertEquals(new ActivationReLU(), l2.getActivationFn()); assertEquals(new L2Regularization(0.0001), TestUtils.getL2Reg(l2)); Bidirectional l3 = (Bidirectional) net.getLayer("rnn2").conf().getLayer(); SimpleRnn l4 = (SimpleRnn) l3.getFwd(); assertEquals(16, l4.getNOut()); assertEquals(new ActivationReLU(), l4.getActivationFn()); assertEquals(new L2Regularization(0.0001), TestUtils.getL2Reg(l4)); SimpleRnn l5 = (SimpleRnn) l3.getBwd(); assertEquals(16, l5.getNOut()); assertEquals(new ActivationReLU(), l5.getActivationFn()); assertEquals(new L2Regularization(0.0001), TestUtils.getL2Reg(l5)); MergeVertex mv = (MergeVertex) net.getVertex("concat"); GlobalPoolingLayer gpl = (GlobalPoolingLayer) net.getLayer("pooling").conf().getLayer(); assertEquals(PoolingType.MAX, gpl.getPoolingType()); assertArrayEquals(new int[]{2}, gpl.getPoolingDimensions()); assertTrue(gpl.isCollapseDimensions()); OutputLayer outl = (OutputLayer) net.getLayer("out").conf().getLayer(); assertEquals(3, outl.getNOut()); assertEquals(new LossMCXENT(), outl.getLossFn()); INDArray outExp; File f2 = Resources.asFile("regression_testing/100b6/SyntheticBidirectionalRNNGraph_Output_100b6.bin"); try (DataInputStream dis = new DataInputStream(new FileInputStream(f2))) { outExp = Nd4j.read(dis); } INDArray in; File f3 = Resources.asFile("regression_testing/100b6/SyntheticBidirectionalRNNGraph_Input_100b6.bin"); try (DataInputStream dis = new DataInputStream(new FileInputStream(f3))) { in = Nd4j.read(dis); } INDArray outAct = net.output(in)[0]; assertEquals(outExp, outAct); }
Example 7
Source File: RegressionTest100a.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Test @Ignore("AB 2019/05/23 - Failing on linux-x86_64-cuda-9.2 - see issue #7657") public void testYoloHouseNumber() throws Exception { File f = Resources.asFile("regression_testing/100a/HouseNumberDetection_100a.bin"); ComputationGraph net = ComputationGraph.load(f, true); int nBoxes = 5; int nClasses = 10; ConvolutionLayer cl = (ConvolutionLayer)((LayerVertex)net.getConfiguration().getVertices().get("convolution2d_9")).getLayerConf().getLayer(); assertEquals(nBoxes * (5 + nClasses), cl.getNOut()); assertEquals(new ActivationIdentity(), cl.getActivationFn()); assertEquals(ConvolutionMode.Same, cl.getConvolutionMode()); assertEquals(new WeightInitXavier(), cl.getWeightInitFn()); assertArrayEquals(new int[]{1,1}, cl.getKernelSize()); assertArrayEquals(new int[]{1,1}, cl.getKernelSize()); INDArray outExp; File f2 = Resources.asFile("regression_testing/100a/HouseNumberDetection_Output_100a.bin"); try(DataInputStream dis = new DataInputStream(new FileInputStream(f2))){ outExp = Nd4j.read(dis); } INDArray in; File f3 = Resources.asFile("regression_testing/100a/HouseNumberDetection_Input_100a.bin"); try(DataInputStream dis = new DataInputStream(new FileInputStream(f3))){ in = Nd4j.read(dis); } //Minor bug in 1.0.0-beta and earlier: not adding epsilon value to forward pass for batch norm //Which means: the record output doesn't have this. To account for this, we'll manually set eps to 0.0 here //https://github.com/deeplearning4j/deeplearning4j/issues/5836#issuecomment-405526228 for(Layer l : net.getLayers()){ if(l.conf().getLayer() instanceof BatchNormalization){ BatchNormalization bn = (BatchNormalization) l.conf().getLayer(); bn.setEps(0.0); } } INDArray outAct = net.outputSingle(in).castTo(outExp.dataType()); boolean eq = outExp.equalsWithEps(outAct, 1e-4); if(!eq){ log.info("Expected: {}", outExp); log.info("Actual: {}", outAct); } assertTrue("Output not equal", eq); }