Package com.github.neuralnetworks.architecture

Examples of com.github.neuralnetworks.architecture.Conv2DConnection


  Environment.getInstance().setUseWeightsSharedMemory(true);
  NeuralNetworkImpl nn = NNFactory.convNN(new int[][] { { 3, 3, 2 }, { 2, 2, 1, 1 } }, true);
  nn.setLayerCalculator(NNFactory.lcSigmoid(nn, null));

  Conv2DConnection c = (Conv2DConnection) nn.getInputLayer().getConnections().get(0);
  TensorIterator it = c.getWeights().iterator();
  float x = 0.1f;
  while (it.hasNext()) {
      c.getWeights().getElements()[it.next()] = x;
      x += 0.1f;
  }

  Conv2DConnection b = (Conv2DConnection) nn.getOutputLayer().getConnections().get(1);
  b.getWeights().getElements()[b.getWeights().getStartIndex()] = -3f;

  SimpleInputProvider ts = new SimpleInputProvider(new float[][] { { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f } }, new float[][] { { 1, 1, 1, 1 } });
  BackPropagationTrainer<?> t = TrainerFactory.backPropagation(nn, ts, null, null, null, 0.5f, 0f, 0f, 0f, 0f, 1, 1, 1);
  t.train();

  it = c.getWeights().iterator();
  assertEquals(0.11756, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.22640, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.34408, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.45292, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.59712, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.70596, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.82364, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.93248, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(-2.911599, b.getWeights().getElements()[b.getWeights().getStartIndex()], 0.00001);
    }
View Full Code Here


  Environment.getInstance().setUseWeightsSharedMemory(true);
  NeuralNetworkImpl nn = NNFactory.convNN(new int[][] { { 3, 3, 2 }, { 2, 2, 1, 1 } }, true);
  nn.setLayerCalculator(NNFactory.lcSigmoid(nn, null));

  Conv2DConnection c = (Conv2DConnection) nn.getInputLayer().getConnections().get(0);
  TensorIterator it = c.getWeights().iterator();
  float x = 0.1f;
  while (it.hasNext()) {
      c.getWeights().getElements()[it.next()] = x;
      x += 0.1f;
  }

  Conv2DConnection b = (Conv2DConnection) nn.getOutputLayer().getConnections().get(1);
  b.getWeights().getElements()[b.getWeights().getStartIndex()] = -3f;
 
  SimpleInputProvider ts = new SimpleInputProvider(new float[][] { { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f }, { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f } }, new float[][] { { 1, 1, 1, 1 }, { 1, 1, 1, 1 } });
  BackPropagationTrainer<?> t = TrainerFactory.backPropagation(nn, ts, null, null, null, 0.5f, 0f, 0f, 0f, 0f, 1, 1, 1);
  t.train();

  it = c.getWeights().iterator();
  assertEquals(0.12317, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.23533, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.35966, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.47182, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.63263, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.74479, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.86911, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(0.98127, c.getWeights().getElements()[it.next()], 0.00001);
  assertEquals(-2.87839, b.getWeights().getElements()[b.getWeights().getStartIndex()], 0.00001);
    }
View Full Code Here

  Environment.getInstance().setUseWeightsSharedMemory(true);
  NeuralNetworkImpl nn = NNFactory.convNN(new int[][] { { 5, 5, 1 }, { 2, 2, 1, 2 } }, false);
  nn.setLayerCalculator(NNFactory.lcWeightedSum(nn, null));

  Conv2DConnection cc = (Conv2DConnection) nn.getInputLayer().getConnections().get(0);
  cc.getWeights().forEach(i -> cc.getWeights().getElements()[i] = 1);

  ValuesProvider vp = TensorFactory.tensorProvider(nn, 1, true);
  float[] src = new float[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
  System.arraycopy(src, 0, vp.get(nn.getInputLayer()).getElements(), vp.get(nn.getInputLayer()).getStartIndex(), src.length);
View Full Code Here

    result = new int[] { c.getFilters(), c.getOutputFeatureMapRows(), c.getOutputFeatureMapColumns(), miniBatchSize };
      } else if (c.getInputLayer() == targetLayer) {
    result = new int[] { c.getFilters(), c.getInputFeatureMapRows(), c.getInputFeatureMapColumns(), miniBatchSize };
      }
  } else if (hasConvolutional) {
      Conv2DConnection c = (Conv2DConnection) connections.iterator().next();
      if (c.getOutputLayer() == targetLayer) {
    result = new int[] { c.getOutputFilters(), c.getOutputFeatureMapRows(), c.getOutputFeatureMapColumns(), miniBatchSize };
      } else if (c.getInputLayer() == targetLayer) {
    result = new int[] { c.getInputFilters(), c.getInputFeatureMapRows(), c.getInputFeatureMapColumns(), miniBatchSize };
      }
  }

  return result;
    }
View Full Code Here

    }
    if (!dout.stream().anyMatch(i -> Arrays.equals(i, outputDim))) {
        dout.add(outputDim);
    }
      } else if (c instanceof Conv2DConnection) {
    Conv2DConnection cc = (Conv2DConnection) c;
    int[] inputDim = new int[] { cc.getInputFilters(), cc.getInputFeatureMapRows(), cc.getInputFeatureMapColumns(), miniBatchSize };
    int[] outputDim = new int[] { cc.getOutputFilters(), cc.getOutputFeatureMapRows(), cc.getOutputFeatureMapColumns(), miniBatchSize };
    if (!din.stream().anyMatch(i -> Arrays.equals(i, inputDim))) {
        din.add(inputDim);
    }
    if (!dout.stream().anyMatch(i -> Arrays.equals(i, outputDim))) {
        dout.add(outputDim);
    }
      } else if (c instanceof Subsampling2DConnection) {
    Subsampling2DConnection cc = (Subsampling2DConnection) c;
    int[] inputDim = new int[] { cc.getFilters(), cc.getInputFeatureMapRows(), cc.getInputFeatureMapColumns(), miniBatchSize };
    int[] outputDim = new int[] { cc.getFilters(), cc.getOutputFeatureMapRows(), cc.getOutputFeatureMapColumns(), miniBatchSize };
    if (!din.stream().anyMatch(i -> Arrays.equals(i, inputDim))) {
        din.add(inputDim);
    }
    if (!dout.stream().anyMatch(i -> Arrays.equals(i, outputDim))) {
        dout.add(outputDim);
View Full Code Here

        }
    } else {
        randomInitializer.initialize(fc.getWeights());
    }
      } else if (cc.connection instanceof Conv2DConnection) {
    Conv2DConnection c = (Conv2DConnection) cc.connection;
    if (Util.isBias(c.getInputLayer())) {
        if (biasDefaultValue != null) {
      c.getWeights().forEach(i -> c.getWeights().getElements()[i] = biasDefaultValue);
        } else if (biasRandomInitializer != null) {
      biasRandomInitializer.initialize(c.getWeights());
        } else {
      randomInitializer.initialize(c.getWeights());
        }
    } else {
        randomInitializer.initialize(c.getWeights());
    }
      }
  }
    }
View Full Code Here

TOP

Related Classes of com.github.neuralnetworks.architecture.Conv2DConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.