コード例 #1
0
    def test_partitionModel3(self):
        """Test partitioning of a NxModel.

        After completion of the algorithm, the partitioner reconstructs the
        kernelIdMap from the synapses and axons generated during partitioning.
        An exception is thrown if the reconstructed map does not equal the
        original map.
        """

        inputShape = (73, 81, 3)
        inputLayer = NxInputLayer(inputShape)
        hiddenLayer = NxConv2D(11,
                               3,
                               strides=(2, 2),
                               padding='same',
                               validatePartitions=True)(inputLayer.input)
        hiddenLayer = NxAveragePooling2D(4,
                                         validatePartitions=True)(hiddenLayer)
        hiddenLayer = NxFlatten()(hiddenLayer)
        outputLayer = NxDense(50, validatePartitions=True)(hiddenLayer)

        model = NxModel(inputLayer.input, outputLayer)

        model.partition()

        model.clearTemp()
コード例 #2
0
    def test_compileNxModel(self):
        """Check that NxModel can be compiled with Keras."""

        inputShape = (7, 7, 1)
        inputLayer = NxInputLayer(inputShape)
        outputLayer = NxConv2D(2, 3)(inputLayer.input)
        model = NxModel(inputLayer.input, outputLayer)
        model.clearTemp()
コード例 #3
0
    def test_partition1(self):
        """Test partitioning a single NxConv1D layer."""

        inputShape = (5, 4)
        inputLayer = NxInputLayer(inputShape)
        outputLayer = NxConv1D(2, 3, validatePartitions=True)
        model = NxModel(inputLayer.input, outputLayer(inputLayer.input))

        model.partition()

        model.clearTemp()
コード例 #4
0
    def test_partitionPooling(self):
        """Test partitioning a single pooling layer."""

        inputShape = (5, 5, 4)
        inputLayer = NxInputLayer(inputShape)
        outputLayer = NxAveragePooling2D(2, validatePartitions=True)
        model = NxModel(inputLayer.input, outputLayer(inputLayer.input))

        model.partition()

        model.clearTemp()
コード例 #5
0
    def test_partition1(self):
        """Test partitioning a single fully-connected layer."""

        inputShape = (3, 3, 2)
        inputLayer = NxInputLayer(inputShape)
        flattenLayer = NxFlatten()(inputLayer.input)
        outputLayer = NxDense(10, validatePartitions=True)
        model = NxModel(inputLayer.input, outputLayer(flattenLayer))

        model.partition()

        model.clearTemp()
コード例 #6
0
    def test_evaluateNxModel(self):
        """Check that NxModel can be evaluated like a Keras Model."""

        batchSize = 10
        batchInputShape = (batchSize, 7, 7, 1)
        inputLayer = NxInputLayer(batch_input_shape=batchInputShape)
        layer = NxConv2D(2, 3)(inputLayer.input)
        model = NxModel(inputLayer.input, layer)

        model.compile('sgd', 'mse')
        model.evaluate(np.random.random_sample(model.input_shape),
                       np.random.random_sample(model.output_shape))
        model.clearTemp()
コード例 #7
0
    def test_partition2(self):
        """Test partitioning two fully-connected layers."""

        inputShape = (40, 32, 2)
        inputLayer = NxInputLayer(inputShape)
        flattenLayer = NxFlatten()(inputLayer.input)
        hiddenLayer = NxDense(100, validatePartitions=True)
        outputLayer = NxDense(10, validatePartitions=True)
        model = NxModel(inputLayer.input,
                        outputLayer(hiddenLayer(flattenLayer)))

        model.partition()

        model.clearTemp()
コード例 #8
0
    def test_partition2(self):
        """Test partitioning two NxConv1D layers."""

        inputShape = (500, 4)
        inputLayer = NxInputLayer(inputShape)
        hiddenLayer = NxConv1D(20,
                               3,
                               strides=2,
                               padding='same',
                               validatePartitions=True)
        outputLayer = NxConv1D(10, 2, padding='same', validatePartitions=True)
        model = NxModel(inputLayer.input,
                        outputLayer(hiddenLayer(inputLayer.input)))

        model.partition()

        model.clearTemp()
コード例 #9
0
    def test_partitionPooling2(self):
        """Test partitioning two pooling layers."""

        inputShape = (30, 40, 4)
        inputLayer = NxInputLayer(inputShape)
        hiddenLayer = NxAveragePooling2D(2,
                                         padding='same',
                                         validatePartitions=True)
        outputLayer = NxAveragePooling2D(3,
                                         strides=(1, 1),
                                         validatePartitions=True)
        model = NxModel(inputLayer.input,
                        outputLayer(hiddenLayer(inputLayer.input)))

        model.partition()

        model.clearTemp()
コード例 #10
0
    def test_partition2(self):
        """Test partitioning two DepthwiseConv2D layers."""

        inputShape = (50, 20, 4)
        inputLayer = NxInputLayer(inputShape)
        hiddenLayer = NxDepthwiseConv2D(3,
                                        strides=(2, 2),
                                        padding='same',
                                        validatePartitions=True)
        outputLayer = NxDepthwiseConv2D(2,
                                        padding='same',
                                        validatePartitions=True)
        model = NxModel(inputLayer.input,
                        outputLayer(hiddenLayer(inputLayer.input)))

        model.partition()

        model.clearTemp()
コード例 #11
0
    def test_saveLoadNxModel(self):
        """Check that NxModel can be saved and loaded like a Keras Model."""

        inputLayer = NxInputLayer(batch_input_shape=(1, 10, 10, 3))
        layer = NxConv2D(2, 3)(inputLayer.input)
        model1 = NxModel(inputLayer.input, layer)
        model1.compile('sgd', 'mse')
        model1.compileModel()
        model1.clearTemp()
        filename = os.path.abspath(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         '../../..', 'temp', str(hash(model1))))
        model1.save(filename)
        model2 = loadNxModel(filename)
        os.remove(filename)

        x = np.random.random_sample(model1.input_shape)
        y1 = model1.predict(x)
        y2 = model2.predict(x)

        self.assertTrue(np.array_equal(y1, y2))
コード例 #12
0
    def test_partitionModel2(self):
        """Test partitioning of a NxModel.

        After completion of the algorithm, the partitioner reconstructs the
        kernelIdMap from the synapses and axons generated during partitioning.
        An exception is thrown if the reconstructed map does not equal the
        original map.
        """

        inputShape = (2, 2, 128)
        inputLayer = NxInputLayer(inputShape)
        hiddenLayer = NxConv2D(128, 2, padding='same', validatePartitions=True)
        hiddenLayer.exclusionCriteria.maxNumCompartments /= 4
        outputLayer = NxConv2D(256, 3, padding='same', validatePartitions=True)
        outputLayer.exclusionCriteria.maxNumCompartments /= 4

        model = NxModel(inputLayer.input,
                        outputLayer(hiddenLayer(inputLayer.input)))

        model.partition()

        model.clearTemp()
コード例 #13
0
    def test_partitionModel4(self):
        """Test partitioning of a NxModel.

        After completion of the algorithm, the partitioner reconstructs the
        kernelIdMap from the synapses and axons generated during partitioning.
        An exception is thrown if the reconstructed map does not equal the
        original map.
        """

        inputShape = (15, 15, 3)
        inputLayer = NxInputLayer(inputShape)
        outputLayer = NxConv2D(3,
                               3,
                               strides=(2, 2),
                               padding='same',
                               validatePartitions=True)(inputLayer.input)

        model = NxModel(inputLayer.input,
                        outputLayer,
                        numCandidatesToCompute=10)

        model.partition()

        model.clearTemp()