Exemplo n.º 1
0
def genLoihiParams(net):
    fc1Weights = quantizeWeights.apply(net.fc1.weight, 2).flatten().cpu().data.numpy()
    fc2Weights = quantizeWeights.apply(net.fc2.weight, 2).flatten().cpu().data.numpy()

    np.savetxt('Trained/OxfordFc1.txt', fc1Weights, fmt='%g')
    np.savetxt('Trained/OxfordFc2.txt', fc2Weights, fmt='%g')

    plt.figure(11)
    plt.hist(fc1Weights, 256)
    plt.title('fc1 weights')

    plt.figure(12)
    plt.hist(fc2Weights, 256)
    plt.title('fc2 weights')
Exemplo n.º 2
0
 def forward(self, input):
     if self.quantize is True:
         return F.conv3d(input, quantizeWeights.apply(self.weight, 2),
                         self.bias, self.stride, self.padding,
                         self.dilation, self.groups)
     else:
         return F.conv3d(input, self.weight, self.bias, self.stride,
                         self.padding, self.dilation, self.groups)
Exemplo n.º 3
0
 def pool(self, kernelSize, stride=None, padding=0, dilation=1):
     requiredWeight = quantizeWeights.apply(
         torch.tensor(1.1 * self.neuron['theta'] / self.maxPspKernel),
         2).cpu().data.item()
     # print('Required pool layer weight =', requiredWeight)
     return slayer._poolLayer(
         requiredWeight / 1.1,  # to compensate for maxPsp
         kernelSize,
         stride,
         padding,
         dilation)
Exemplo n.º 4
0
def genLoihiParams(net):
    fc1Weights = quantizeWeights.apply(net.fc1.weight,
                                       2).flatten().cpu().data.numpy()
    fc2Weights = quantizeWeights.apply(net.fc2.weight,
                                       2).flatten().cpu().data.numpy()
    conv1Weights = quantizeWeights.apply(net.conv1.weight,
                                         2).flatten().cpu().data.numpy()
    conv2Weights = quantizeWeights.apply(net.conv2.weight,
                                         2).flatten().cpu().data.numpy()
    pool1Weights = quantizeWeights.apply(net.pool1.weight,
                                         2).flatten().cpu().data.numpy()
    pool2Weights = quantizeWeights.apply(net.pool2.weight,
                                         2).flatten().cpu().data.numpy()
    pool3Weights = quantizeWeights.apply(net.pool3.weight,
                                         2).flatten().cpu().data.numpy()

    np.savetxt('Trained/fc1.txt', fc1Weights, fmt='%g')
    np.savetxt('Trained/fc2.txt', fc2Weights, fmt='%g')
    np.savetxt('Trained/conv1.txt', conv1Weights, fmt='%g')
    np.savetxt('Trained/conv2.txt', conv2Weights, fmt='%g')
    np.savetxt('Trained/pool1.txt', pool1Weights, fmt='%g')
    np.savetxt('Trained/pool2.txt', pool2Weights, fmt='%g')
    np.savetxt('Trained/pool3.txt', pool3Weights, fmt='%g')

    plt.figure(11)
    plt.hist(fc1Weights, 256)
    plt.title('fc1 weights')

    plt.figure(12)
    plt.hist(fc2Weights, 256)
    plt.title('fc2 weights')

    plt.figure(13)
    plt.hist(conv1Weights, 256)
    plt.title('conv1 weights')

    plt.figure(14)
    plt.hist(conv2Weights, 256)
    plt.title('conv2 weights')

    plt.figure(15)
    plt.hist(pool1Weights, 256)
    plt.title('pool1 weights')

    plt.figure(16)
    plt.hist(pool2Weights, 256)
    plt.title('pool2 weights')

    plt.figure(17)
    plt.hist(pool3Weights, 256)
    plt.title('pool3 weights')
Exemplo n.º 5
0
    def pool(self, kernelSize, stride=None, padding=0, dilation=1):
        '''
        This function behaves similar to :meth:`slayer.spikeLayer.pool`. 
        The only difference is that the weights are qunatized with step of 2 (as is the case for signed weights in Loihi).
        One can, however, skip the quantization step altogether as well.

        Arguments:
            The arguments set is same as :meth:`slayer.spikeLayer.pool`.

        Usage:
            Same as :meth:`slayer.spikeLayer.pool`
        '''
        requiredWeight = quantizeWeights.apply(torch.tensor(1.1 * self.neuron['theta'] / self.maxPspKernel), 2).cpu().data.item()
        # print('Required pool layer weight =', requiredWeight)
        return slayer._poolLayer(requiredWeight/ 1.1, # to compensate for maxPsp
                          kernelSize, stride, padding, dilation)