NeuromorphicProcessorProject / snn_toolbox

Toolbox for converting analog to spiking neural networks (ANN to SNN), and running them in a spiking neuron simulator.
MIT License
360 stars 104 forks source link

AttributeError: module 'numpy' has no attribute 'asscalar' #123

Closed sauravtii closed 2 years ago

sauravtii commented 2 years ago

I am following this script (https://github.com/NeuromorphicProcessorProject/snn_toolbox/blob/master/examples/mnist_keras_spiNNaker.py) with some modifications like I am using CIFAR-10 dataset instead of MNIST and my architecture is different. But after calling the main function on my config file I am facing the following issue. I have provided the whole output of when I ran main function on my config file.

Can anyone please provide me a solution to this issue ?

Thanks, Saurav

SNN toolbox WARNING: Delay (0.0) must be at least one time step (0.1). Setting delay = dt.

SNN toolbox WARNING: For optimal correspondence between the original ANN and the converted SNN simulated on pyNN, the threshold should be 0.01. Current value: 1.0.
Initializing spiNNaker simulator...

2022-08-11 14:16:55 INFO: Read cfg files: /home/sauravpawar/.local/lib/python3.8/site-packages/spinn_front_end_common/interface/spinnaker.cfg, /home/sauravpawar/.local/lib/python3.8/site-packages/spynnaker/pyNN/spynnaker.cfg, /home/sauravpawar/.spynnaker.cfg
2022-08-11 14:16:55 INFO: Will search these locations for binaries: /home/sauravpawar/.local/lib/python3.8/site-packages/spinn_front_end_common/common_model_binaries : /home/sauravpawar/.local/lib/python3.8/site-packages/spynnaker/pyNN/model_binaries
2022-08-11 14:16:55 WARNING: /home/sauravpawar/Desktop/spiNNaker_cnn/reports has 48 old reports that have not been closed
2022-08-11 14:16:55 WARNING: A timestep was entered that has forced sPyNNaker to automatically slow the simulation down from real time by a factor of 10. To remove this automatic behaviour, please enter a timescaleFactor value in your .spynnaker.cfg
2022-08-11 14:16:55 INFO: Setting time scale factor to 10.
2022-08-11 14:16:55 INFO: Setting machine time step to 100 micro-seconds.
['/home/sauravpawar/.local/lib/python3.8/site-packages/spinn_front_end_common/interface/spinnaker.cfg', '/home/sauravpawar/.local/lib/python3.8/site-packages/spynnaker/pyNN/spynnaker.cfg', '/home/sauravpawar/.spynnaker.cfg']
Loading data set from '.npz' files in /home/sauravpawar/temp/1660212961.8469374.

Model: "model"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 input_1 (InputLayer)        [(None, 32, 32, 3)]       0         

 conv2d (Conv2D)             (None, 32, 32, 4)         12        

 conv2d_1 (Conv2D)           (None, 15, 15, 64)        2304      

 conv2d_2 (Conv2D)           (None, 15, 15, 72)        41472     

 conv2d_3 (Conv2D)           (None, 8, 8, 256)         165888    

 conv2d_4 (Conv2D)           (None, 8, 8, 256)         65536     

 conv2d_5 (Conv2D)           (None, 8, 8, 64)          16384     

 flatten (Flatten)           (None, 4096)              0         

 dense (Dense)               (None, 100)               409600    

 dense_1 (Dense)             (None, 10)                1000      

=================================================================
Total params: 702,196
Trainable params: 702,196
Non-trainable params: 0
_________________________________________________________________
Evaluating input model on 5 samples...
Top-1 accuracy: 0.00%
Top-5 accuracy: 40.00%

Parsing input model...
Skipping layer InputLayer.
Parsing layer Conv2D.
Using activation relu.
Parsing layer Conv2D.
Using activation linear.
Parsing layer Conv2D.
Using activation linear.
Parsing layer Conv2D.
Using activation linear.
Parsing layer Conv2D.
Using activation linear.
Parsing layer Conv2D.
Using activation linear.
Parsing layer Flatten.
Parsing layer Dense.
Using activation linear.
Parsing layer Dense.
Using activation linear.

Building parsed model...

Compiling parsed model...

Model: "model_1"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 input_1 (InputLayer)        [(1, 32, 32, 3)]          0         

 00Conv2D_32x32x4 (Conv2D)   (1, 32, 32, 4)            16        

 01Conv2D_15x15x64 (Conv2D)  (1, 15, 15, 64)           2368      

 02Conv2D_15x15x72 (Conv2D)  (1, 15, 15, 72)           41544     

 03Conv2D_8x8x256 (Conv2D)   (1, 8, 8, 256)            166144    

 04Conv2D_8x8x256 (Conv2D)   (1, 8, 8, 256)            65792     

 05Conv2D_8x8x64 (Conv2D)    (1, 8, 8, 64)             16448     

 06Flatten_4096 (Flatten)    (1, 4096)                 0         

 07Dense_100 (Dense)         (1, 100)                  409700    

 08Dense_10 (Dense)          (1, 10)                   1010      

=================================================================
Total params: 703,022
Trainable params: 703,022
Non-trainable params: 0
_________________________________________________________________
Normalizing parameters...
Using 5000 samples for normalization.
INFO: Need ['0.08', '0.29', '0.32', '0.33', '0.33', '0.08', '0.00', '0.00'] GB for layer activations.
May have to reduce size of data set used for normalization.
Calculating activations of layer 00Conv2D_32x32x4 ...
5000/5000 [==============================] - 2s 449us/step
Writing activations to disk...
Scale factor: 2.31.
Calculating activations of layer 01Conv2D_15x15x64 ...
5000/5000 [==============================] - 3s 531us/step
Writing activations to disk...
Scale factor: 1.12.
Calculating activations of layer 02Conv2D_15x15x72 ...
5000/5000 [==============================] - 3s 695us/step
Writing activations to disk...
Scale factor: 2.26.
Calculating activations of layer 03Conv2D_8x8x256 ...
5000/5000 [==============================] - 4s 873us/step
Writing activations to disk...
Scale factor: 4.20.
Calculating activations of layer 04Conv2D_8x8x256 ...
5000/5000 [==============================] - 5s 969us/step
Writing activations to disk...
Scale factor: 7.65.
Calculating activations of layer 05Conv2D_8x8x64 ...
5000/5000 [==============================] - 5s 1ms/step
Writing activations to disk...
Scale factor: 22.41.
Calculating activations of layer 07Dense_100 ...
5000/5000 [==============================] - 6s 1ms/step
Writing activations to disk...
Scale factor: 251.85.
Calculating activations of layer 08Dense_10 ...
5000/5000 [==============================] - 6s 1ms/step
Writing activations to disk...
Scale factor: 791.56.

Evaluating parsed model on 5 samples...
Top-1 accuracy: 0.00%
Top-5 accuracy: 0.00%

Building spiking model...
Instantiating layer: 00Conv2D_32x32x4
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [17], in <cell line: 4>()
      1 # RUN SNN TOOLBOX #
      2 ###################
----> 4 main(config_filepath)

File ~/.local/lib/python3.8/site-packages/snntoolbox/bin/run.py:31, in main(filepath)
     29 if filepath is not None:
     30     config = update_setup(filepath)
---> 31     run_pipeline(config)
     32     return
     34 parser = argparse.ArgumentParser(
     35     description='Run SNN toolbox to convert an analog neural network into '
     36                 'a spiking neural network, and optionally simulate it.')

File ~/.local/lib/python3.8/site-packages/snntoolbox/bin/utils.py:127, in run_pipeline(config, queue)
    121     except FileNotFoundError:
    122         print("Could not find parsed model {} in path {}. Consider "
    123               "setting `parse = True` in your config file.".format(
    124                 config.get('paths', 'path_wd'),
    125                 config.get('paths', 'filename_parsed_model')))
--> 127 spiking_model.build(parsed_model, **testset)
    129 # Export network in a format specific to the simulator with which it
    130 # will be tested later.
    131 spiking_model.save(config.get('paths', 'path_wd'),
    132                    config.get('paths', 'filename_snn'))

File ~/.local/lib/python3.8/site-packages/snntoolbox/simulation/utils.py:438, in AbstractSNN.build(self, parsed_model, **kwargs)
    435 self.preprocessing(**kwargs)
    437 # Iterate over layers to create spiking neurons and connections.
--> 438 self.setup_layers(batch_shape)
    440 print("Compiling spiking model...\n")
    441 self.compile()

File ~/.local/lib/python3.8/site-packages/snntoolbox/simulation/target_simulators/spiNNaker_target_sim.py:57, in SNN.setup_layers(self, batch_shape)
     55 for layer in self.parsed_model.layers[1:]:
     56     print("Instantiating layer: {}".format(layer.name))
---> 57     self.add_layer(layer)
     59     layer_type = get_type(layer)
     60     print("Building layer: {}".format(layer.name))

File ~/.local/lib/python3.8/site-packages/snntoolbox/simulation/target_simulators/spiNNaker_target_sim.py:96, in SNN.add_layer(self, layer)
     93 if 'Reshape' in layer.__class__.__name__:
     94     return
     95 self.layers.append(self.sim.Population(
---> 96     np.asscalar(np.prod(layer.output_shape[1:], dtype=np.int)),
     97     self.sim.IF_curr_exp, self.cellparams, label=layer.name))
     99 self.layers[-1].initialize(v=self.layers[-1].get('v_rest'))

File ~/.local/lib/python3.8/site-packages/numpy/__init__.py:311, in __getattr__(attr)
    308     from .testing import Tester
    309     return Tester
--> 311 raise AttributeError("module {!r} has no attribute "
    312                      "{!r}".format(__name__, attr))

AttributeError: module 'numpy' has no attribute 'asscalar'

My config file:

[paths]
path_wd = /home/sauravpawar/temp/1660212961.8469374
dataset_path = /home/sauravpawar/temp/1660212961.8469374
filename_ann = spinnaker_cifar_10_cnn

[tools]
evaluate_ann = True
normalize = True
scale_weights_exp = True

[simulation]
simulator = spiNNaker
duration = 50
num_to_test = 5
batch_size = 1
dt = 0.1

[input]
poisson_input = True
input_rate = 1000

[cell]
tau_syn_e = 0.01
tau_syn_i = 0.01

[output]
plot_vars = {'spikerates', 'error_t', 'spiketrains', 'activations', 'v_mem', 'correlation'}