Package com.github.neuralnetworks.architecture

Examples of com.github.neuralnetworks.architecture.Layer


    }

    @Test
    public void testConvolutions() {
  Environment.getInstance().setUseWeightsSharedMemory(true);
  Conv2DConnection c = new ConnectionFactory().conv2d(new Layer(), new Layer(), 3, 3, 2, 2, 2, 1, 1);

  c.getWeights().setElements(new float[] {1, 2, 3, 4, 1, 2, 3, 4});

  ValuesProvider vp = TensorFactory.tensorProvider(c, 1, true);
  TensorIterator it = vp.get(c.getInputLayer()).iterator();
View Full Code Here


    }

    @Test
    public void testConvolutions2() {
  Environment.getInstance().setUseWeightsSharedMemory(true);
  Conv2DConnection c = new ConnectionFactory().conv2d(new Layer(), new Layer(), 3, 3, 2, 2, 2, 2, 1);
  c.getWeights().setElements(new float[] {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4});

  ValuesProvider vp = TensorFactory.tensorProvider(c, 1, true);
  TensorIterator it = vp.get(c.getInputLayer()).iterator();
  for (int i = 0; i < vp.get(c.getInputLayer()).getSize(); i++) {
View Full Code Here

  assertEquals(244, o.get(1, 0, 0, 0), 0);
    }

    @Test
    public void testMaxPooling() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);
  List<Connections> connections = new ArrayList<Connections>();
  connections.add(c);

  ConnectionCalculator calc = new AparapiMaxPooling2D();
View Full Code Here

  assertEquals(32, o.get(1, 1, 1, 1), 0);
    }

    @Test
    public void testAveragePooling() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);
  List<Connections> connections = new ArrayList<Connections>();
  connections.add(c);

  AparapiAveragePooling2D calc = new AparapiAveragePooling2D();
View Full Code Here

  assertEquals(29.5, o.get(1, 1, 1, 1), 0);
    }

    @Test
    public void testStochasticPooling() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 3, 3, 3, 3, 1);
  List<Connections> connections = new ArrayList<Connections>();
  connections.add(c);

  ValuesProvider vp = TensorFactory.tensorProvider(c, 2, true);
  float[] src = new float[] { 1.6f, 1.6f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.4f, 2.4f };
View Full Code Here

    }

    @Test
    public void testMaxPoolingBackpropagation() {
  Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);

  List<Connections> connections = new ArrayList<Connections>();
  connections.add(c);

  // max pooling
View Full Code Here

  assertEquals(true, bpo.get(1, 3, 2, 1) == a.get(1, 3, 2, 1));
    }

    @Test
    public void testAveragePoolingBackpropagation() {
  Subsampling2DConnection c = new Subsampling2DConnection(new Layer(), new Layer(), 4, 4, 2, 2, 2);

  // average pooling
  ConnectionCalculator calc = new AparapiAveragePooling2D();

  List<Connections> connections = new ArrayList<Connections>();
View Full Code Here

  NeuralNetworkImpl result = new NeuralNetworkImpl();
  ConnectionFactory cf = new ConnectionFactory();
  result.setProperties(new Properties());
  result.getProperties().setParameter(Constants.CONNECTION_FACTORY, cf);

  Layer prev = null;
  int prevUnitCount = layers[0][0] * layers[0][1] * layers[0][2];
  result.addLayer(prev = new Layer());
  for (int i = 1; i < layers.length; i++) {
      int[] l = layers[i];
      Layer newLayer = null;
      Layer biasLayer = null;
      if (l.length == 1) {
    cf.fullyConnected(prev, newLayer = new Layer(), prevUnitCount, l[0]);
    if (addBias) {
        cf.fullyConnected(biasLayer = new Layer(), newLayer, 1, l[0]);
    }

    prevUnitCount = l[0];
      } else if (l.length == 4 || l.length == 2) {
    Integer inputFMRows = null;
    Integer inputFMCols = null;
    Integer filters = null;
    if (i == 1) {
        inputFMRows = layers[0][0];
        inputFMCols = layers[0][1];
        filters = layers[0][2];
    } else {
        for (Connections c : prev.getConnections()) {
      if (c.getOutputLayer() == prev) {
          if (c instanceof Conv2DConnection) {
        Conv2DConnection cc = (Conv2DConnection) c;
        inputFMRows = cc.getOutputFeatureMapRows();
        inputFMCols = cc.getOutputFeatureMapColumns();
        filters = cc.getOutputFilters();
        break;
          } else if (c instanceof Subsampling2DConnection) {
        Subsampling2DConnection sc = (Subsampling2DConnection) c;
        inputFMRows = sc.getOutputFeatureMapRows();
        inputFMCols = sc.getOutputFeatureMapColumns();
        filters = sc.getFilters();
        break;
          }
      }
        }
    }

    if (l.length == 4) {
        Conv2DConnection c = cf.conv2d(prev, newLayer = new Layer(), inputFMRows, inputFMCols, filters, l[0], l[1], l[2], l[3]);
        if (addBias) {
      cf.conv2d(biasLayer = new Layer(), newLayer, c.getOutputFeatureMapRows(), c.getOutputFeatureMapColumns(), 1, 1, 1, l[2], l[3]);
        }

        prevUnitCount = c.getOutputUnitCount();
    } else if (l.length == 2) {
        Subsampling2DConnection c = cf.subsampling2D(prev, newLayer = new Layer(), inputFMRows, inputFMCols, l[0], l[1], filters);
        prevUnitCount = c.getOutputUnitCount();
    }
      }

      result.addLayer(newLayer);
View Full Code Here

  if (nn.getProperties() == null) {
      nn.setProperties(new Properties());
  }
  nn.getProperties().setParameter(Constants.CONNECTION_FACTORY, cf);

  addFullyConnectedLayer(nn, new Layer(), cf, layers[0], layers[0], addBias);
  for (int i = 1; i < layers.length; i++) {
      addFullyConnectedLayer(nn, new Layer(), cf, layers[i - 1], layers[i], addBias);
  }
    }
View Full Code Here

  if (nn.addLayer(layer) && nn.getOutputLayer() != layer) {
      result = cf.fullyConnected(nn.getOutputLayer(), layer, inputUnitCount, outputUnitCount);
  }

  if (addBias && nn.getInputLayer() != layer) {
      nn.addConnections(cf.fullyConnected(new Layer(), layer, 1, outputUnitCount));
  }

  return result;
    }
View Full Code Here

TOP

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

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.