Giter VIP home page Giter VIP logo

spkeras's People

Contributors

dengyu-wu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spkeras's Issues

How the conversion process takes place ?

Hi, I have used SpKeras for a couple of applications, but still I am not sure of the conversion process from a CNN to SNN. I did refer this code, but wasn't able to get any satisfactory insights. So, can anyone help me on this ?

Bugs in SpKeras.2

Hello @Dengyu-Wu,
I've had the chance to try SpKeras.2 recently and have come across the below bugs.

  1. This one is fixed easily by commenting out the unseen file imports in the project.
spkeras/spkeras/layers/__init__.py", line 2, in <module>
    from .MaxNorm_test import MaxNorm
ModuleNotFoundError: No module named 'networks.snn.spkeras.spkeras.layers.MaxNorm_test'
  1. I -tried to- fix this one via adding a control statement if num+1 < len(lmax).
spkeras/spkeras/models.py", line 100, in convert
    _bias = kappa*_weights[1]/lmax[num+1]
IndexError: list index out of range
  1. I -tried to- fix this one via adding a control statement as well if num < len(l).
spkeras/spkeras/models.py", line 104, in convert
    _weights[0] = kappa*_weights[0]/l[num]
IndexError: list index out of range

However, in the end another error gets thrown which I don't know how to get into. I tried running two different CNN models, one with BN layers, one without. Below error is thrown after trying the no-BN CNN:

spkeras/spkeras/models.py", line 179, in convert
    layer.set_weights(weights[m])
File "/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1783, in set_weights
    'shape %s' % (ref_shape, weight.shape))
ValueError: Layer weight shape (65536, 1024) not compatible with provided weight shape (4096, 1024)

and this error belongs to the CNN with BN layers:

ValueError: Dimensions must be equal, but are 10 and 84 for '{{node spike_activation_6/Add}} = Add[T=DT_FLOAT](Placeholder, spike_activation_6/Mul)' with input shapes: [?,10], [84].

Any fixes?

getting pretty low accuracy with SNN

Hello @Dengyu-Wu,

I'm trying out spkeras on LeNet-5, yet the results are not satisfactory.
The org. ANN's accuracy is 0.9674, then it drops to 0.0980 when converted to SNN.
Can you please reason it out?

Below is the console output starting with evaluating the ANN's accuracy.

1875/1875 - 50s - loss: 0.2242 - accuracy: 0.9349 - val_loss: 0.0861 - val_accuracy: 0.9756
313/313 [==============================] - 5s 16ms/step - loss: 0.1085 - accuracy: 0.9674
|||||  Model is ready.  |||||
{'timesteps': 256, 'thresholding': 0.5, 'amp_factor': 100, 'signed_bit': 0, 'spike_ext': 0, 'epsilon': 0.001, 'use_bias': True, 'scaling_factor': 1, 'noneloss': False, 'method': 1}
Start Converting...
Extracting Lambda...
1/8AveragePooling2D
3/8AveragePooling2D
maximum activations: [1.0, 0.94426966, 0.99999297]
Building new model...
spikeforward_0_threshold: 100
spikeforward_1_threshold: 1.059012
spikeforward_2_threshold: 100
spikeforward_3_threshold: 1.059012
spikeforward_4_threshold: 100
spikeforward_5_threshold: 100
spikeforward_6_threshold: 100
New model generated!
|||||  Model converted to SNN.  |||||
Changing model timesteps...
New model generated!
{'timesteps': 256, 'thresholding': 0.5, 'amp_factor': 100, 'signed_bit': 0, 'spike_ext': 0, 'epsilon': 0.001, 'use_bias': True, 'scaling_factor': 1, 'noneloss': False, 'method': 1}
313/313 [==============================] - 6s 16ms/step - loss: nan - accuracy: 0.0980
|||||  Model evaluated with accuracy 0.09799999743700027.  |||||

I tried the code as in the usage example with different timesteps, threshold values, and scaling factors as well, but it didn't affect the output.
Note that I didn't use batch-normalization between the layers.

AssertionError:

Hi,
I did add relu activation layer after each conv2d layer and the previous issue did get resolved. I am facing the following issue.

Issue:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In [13], line 7
      2 from spkeras.spkeras.models import cnn_to_snn
      4 #Current normalisation using cnn_to_snn
      5 ##Default: signed_bit=0, amp_factor=100, method=1, epsilon = 0.001
----> 7 snn_model = cnn_to_snn(signed_bit=0)(cnn_model,x_train)

File /opt/ml_team_data/saurav/new/saurav/vgg16/SpKeras/spkeras/spkeras/models.py:29, in cnn_to_snn.__call__(self, mdl, x_train)
     27 self.use_bias = use_bias        
     28 self.get_config()
---> 29 self.model = self.convert(mdl,x_train,                    
     30                           thresholding = self.thresholding,
     31                           scaling_factor = self.scaling_factor,
     32                           method = self.method,
     33                           timesteps=self.timesteps)
     35 return self

File /opt/ml_team_data/saurav/new/saurav/vgg16/SpKeras/spkeras/spkeras/models.py:169, in cnn_to_snn.convert(self, mdl, x_train, thresholding, scaling_factor, method, timesteps)
    167 new_mdl['config']['layers'] = layers
    168 new_mdl = json.dumps(new_mdl)
--> 169 new_model = model_from_json(new_mdl,
    170                              custom_objects={'SpikeActivation':SpikeActivation})
    171 input_shape = model.layers[0].input_shape
    172 #new_model.build(input_shape)                            
    173 #new_model = keras.Model(inputs=inputs, outputs=outputs)

File ~/.local/lib/python3.8/site-packages/keras/saving/model_config.py:109, in model_from_json(json_string, custom_objects)
     86 """Parses a JSON model configuration string and returns a model instance.
     87 
     88 Usage:
   (...)
    103     A Keras model instance (uncompiled).
    104 """
    105 from keras.layers import (
    106     deserialize_from_json,
    107 )
--> 109 return deserialize_from_json(json_string, custom_objects=custom_objects)

File ~/.local/lib/python3.8/site-packages/keras/layers/serialization.py:272, in deserialize_from_json(json_string, custom_objects)
    266 populate_deserializable_objects()
    267 config = json_utils.decode_and_deserialize(
    268     json_string,
    269     module_objects=LOCAL.ALL_OBJECTS,
    270     custom_objects=custom_objects,
    271 )
--> 272 return deserialize(config, custom_objects)

File ~/.local/lib/python3.8/site-packages/keras/layers/serialization.py:249, in deserialize(config, custom_objects)
    212 """Instantiates a layer from a config dictionary.
    213 
    214 Args:
   (...)
    246 ```
    247 """
    248 populate_deserializable_objects()
--> 249 return generic_utils.deserialize_keras_object(
    250     config,
    251     module_objects=LOCAL.ALL_OBJECTS,
    252     custom_objects=custom_objects,
    253     printable_module_name="layer",
    254 )

File ~/.local/lib/python3.8/site-packages/keras/utils/generic_utils.py:734, in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    731 custom_objects = custom_objects or {}
    733 if "custom_objects" in arg_spec.args:
--> 734     deserialized_obj = cls.from_config(
    735         cls_config,
    736         custom_objects=dict(
    737             list(_GLOBAL_CUSTOM_OBJECTS.items())
    738             + list(_THREAD_LOCAL_CUSTOM_OBJECTS.__dict__.items())
    739             + list(custom_objects.items())
    740         ),
    741     )
    742 else:
    743     with CustomObjectScope(custom_objects):

File ~/.local/lib/python3.8/site-packages/keras/engine/training.py:3034, in Model.from_config(cls, config, custom_objects)
   3027 functional_model_keys = [
   3028     "name",
   3029     "layers",
   3030     "input_layers",
   3031     "output_layers",
   3032 ]
   3033 if all(key in config for key in functional_model_keys):
-> 3034     inputs, outputs, layers = functional.reconstruct_from_config(
   3035         config, custom_objects
   3036     )
   3037     model = cls(
   3038         inputs=inputs, outputs=outputs, name=config.get("name")
   3039     )
   3040     functional.connect_ancillary_layers(model, layers)

File ~/.local/lib/python3.8/site-packages/keras/engine/functional.py:1510, in reconstruct_from_config(config, custom_objects, created_layers)
   1508 for layer_data in tf.nest.flatten(output_layers):
   1509     layer_name, node_index, tensor_index = layer_data.as_list()
-> 1510     assert layer_name in created_layers
   1511     layer = created_layers[layer_name]
   1512     node_index = get_node_index(layer, node_index)

AssertionError: 

My model architecture:

input_shape = (32, 32, 3)
input_layer = Input(input_shape)

layer = Conv2D(filters=4,
               kernel_size=(1, 1),
               strides=(1, 1),
               padding="same")(input_layer)

layer=Activation('relu')(layer)

# 1
layer = Conv2D(filters=64,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(input_layer)

layer=Activation('relu')(layer)


# 2
layer = Conv2D(filters=64,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# Using Conv layer as a pooling layer
layer = Conv2D(filters=64,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

layer=Activation('relu')(layer)

# 3
layer = Conv2D(filters=128,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# 4
layer = Conv2D(filters=128,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# Using Conv layer as a pooling layer
layer = Conv2D(filters=128,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

layer=Activation('relu')(layer)


# 5
layer = Conv2D(filters=256,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# 6
layer = Conv2D(filters=256,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)


# 7
layer = Conv2D(filters=256,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# Using Conv layer as a pooling layer
layer = Conv2D(filters=256,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

layer=Activation('relu')(layer)

# 8
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# 9
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)


# 10
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)


layer=Activation('relu')(layer)

# Using Conv layer as a pooling layer
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

layer=Activation('relu')(layer)


# 11
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# 12
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)


layer=Activation('relu')(layer)


# 13
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# Using Conv layer as a pooling layer
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

layer=Activation('relu')(layer)

layer = Flatten()(layer)

layer = Dense(units=512)(layer)

layer=Activation('relu')(layer)

layer = Dense(units=10)(layer)

layer=Activation('relu')(layer)

model = Model(input_layer, layer)

My model summary:

Model: "model"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 input_1 (InputLayer)        [(None, 32, 32, 3)]       0         
                                                                 
 conv2d_1 (Conv2D)           (None, 32, 32, 64)        1792      
                                                                 
 activation_1 (Activation)   (None, 32, 32, 64)        0         
                                                                 
 conv2d_2 (Conv2D)           (None, 32, 32, 64)        36928     
                                                                 
 activation_2 (Activation)   (None, 32, 32, 64)        0         
                                                                 
 conv2d_3 (Conv2D)           (None, 16, 16, 64)        36928     
                                                                 
 activation_3 (Activation)   (None, 16, 16, 64)        0         
                                                                 
 conv2d_4 (Conv2D)           (None, 16, 16, 128)       73856     
                                                                 
 activation_4 (Activation)   (None, 16, 16, 128)       0         
                                                                 
 conv2d_5 (Conv2D)           (None, 16, 16, 128)       147584    
                                                                 
 activation_5 (Activation)   (None, 16, 16, 128)       0         
                                                                 
 conv2d_6 (Conv2D)           (None, 8, 8, 128)         147584    
                                                                 
 activation_6 (Activation)   (None, 8, 8, 128)         0         
                                                                 
 conv2d_7 (Conv2D)           (None, 8, 8, 256)         295168    
                                                                 
 activation_7 (Activation)   (None, 8, 8, 256)         0         
                                                                 
 conv2d_8 (Conv2D)           (None, 8, 8, 256)         590080    
                                                                 
 activation_8 (Activation)   (None, 8, 8, 256)         0         
                                                                 
 conv2d_9 (Conv2D)           (None, 8, 8, 256)         590080    
                                                                 
 activation_9 (Activation)   (None, 8, 8, 256)         0         
                                                                 
 conv2d_10 (Conv2D)          (None, 4, 4, 256)         590080    
                                                                 
 activation_10 (Activation)  (None, 4, 4, 256)         0         
                                                                 
 conv2d_11 (Conv2D)          (None, 4, 4, 512)         1180160   
                                                                 
 activation_11 (Activation)  (None, 4, 4, 512)         0         
                                                                 
 conv2d_12 (Conv2D)          (None, 4, 4, 512)         2359808   
                                                                 
 activation_12 (Activation)  (None, 4, 4, 512)         0         
                                                                 
 conv2d_13 (Conv2D)          (None, 4, 4, 512)         2359808   
                                                                 
 activation_13 (Activation)  (None, 4, 4, 512)         0         
                                                                 
 conv2d_14 (Conv2D)          (None, 2, 2, 512)         2359808   
                                                                 
 activation_14 (Activation)  (None, 2, 2, 512)         0         
                                                                 
 conv2d_15 (Conv2D)          (None, 2, 2, 512)         2359808   
                                                                 
 activation_15 (Activation)  (None, 2, 2, 512)         0         
                                                                 
 conv2d_16 (Conv2D)          (None, 2, 2, 512)         2359808   
                                                                 
 activation_16 (Activation)  (None, 2, 2, 512)         0         
                                                                 
 conv2d_17 (Conv2D)          (None, 2, 2, 512)         2359808   
                                                                 
 activation_17 (Activation)  (None, 2, 2, 512)         0         
                                                                 
 conv2d_18 (Conv2D)          (None, 1, 1, 512)         2359808   
                                                                 
 activation_18 (Activation)  (None, 1, 1, 512)         0         
                                                                 
 flatten (Flatten)           (None, 512)               0         
                                                                 
 dense (Dense)               (None, 512)               262656    
                                                                 
 activation_19 (Activation)  (None, 512)               0         
                                                                 
 dense_1 (Dense)             (None, 10)                5130      
                                                                 
 activation_20 (Activation)  (None, 10)                0         
                                                                 
=================================================================
Total params: 20,476,682
Trainable params: 20,476,682
Non-trainable params: 0
_________________________________________________________________

List index out of range

Hello!
I am again facing the same issue with the following architecture. Everything is same as before. Can you please help me on this?

input_shape = (32, 32, 3)
input_layer = Input(input_shape)

layer = Conv2D(filters=4,
               kernel_size=(1, 1),
               strides=(1, 1),
               padding="same")(input_layer)

layer=Activation('relu')(layer)

# 1
layer = Conv2D(filters=64,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(input_layer)

# 2
layer = Conv2D(filters=64,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# Using Conv layer as a pooling layer
layer = Conv2D(filters=64,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

# 3
layer = Conv2D(filters=128,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)

# 4
layer = Conv2D(filters=128,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)


# Using Conv layer as a pooling layer
layer = Conv2D(filters=128,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

layer=Activation('relu')(layer)


# 5
layer = Conv2D(filters=256,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)


# 6
layer = Conv2D(filters=256,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)


# 7
layer = Conv2D(filters=256,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)


# Using Conv layer as a pooling layer
layer = Conv2D(filters=256,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

layer=Activation('relu')(layer)

# 8
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

# 9
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)

layer=Activation('relu')(layer)


# 10
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)


# Using Conv layer as a pooling layer
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

layer=Activation('relu')(layer)


# 11
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)


# 12
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)


layer=Activation('relu')(layer)


# 13
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(1, 1),
               padding="same")(layer)


# Using Conv layer as a pooling layer
layer = Conv2D(filters=512,
               kernel_size=(3, 3),
               strides=(2, 2),
               padding="same")(layer)

layer=Activation('relu')(layer)

layer = Flatten()(layer)

layer = Dense(units=512)(layer)

layer = Dense(units=10)(layer)

layer=Activation('relu')(layer)

model = Model(input_layer, layer)

My model summary:

Model: "model"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 input_1 (InputLayer)        [(None, 32, 32, 3)]       0         
                                                                 
 conv2d_1 (Conv2D)           (None, 32, 32, 64)        1792      
                                                                 
 conv2d_2 (Conv2D)           (None, 32, 32, 64)        36928     
                                                                 
 activation_1 (Activation)   (None, 32, 32, 64)        0         
                                                                 
 conv2d_3 (Conv2D)           (None, 16, 16, 64)        36928     
                                                                 
 conv2d_4 (Conv2D)           (None, 16, 16, 128)       73856     
                                                                 
 activation_2 (Activation)   (None, 16, 16, 128)       0         
                                                                 
 conv2d_5 (Conv2D)           (None, 16, 16, 128)       147584    
                                                                 
 conv2d_6 (Conv2D)           (None, 8, 8, 128)         147584    
                                                                 
 activation_3 (Activation)   (None, 8, 8, 128)         0         
                                                                 
 conv2d_7 (Conv2D)           (None, 8, 8, 256)         295168    
                                                                 
 conv2d_8 (Conv2D)           (None, 8, 8, 256)         590080    
                                                                 
 activation_4 (Activation)   (None, 8, 8, 256)         0         
                                                                 
 conv2d_9 (Conv2D)           (None, 8, 8, 256)         590080    
                                                                 
 conv2d_10 (Conv2D)          (None, 4, 4, 256)         590080    
                                                                 
 activation_5 (Activation)   (None, 4, 4, 256)         0         
                                                                 
 conv2d_11 (Conv2D)          (None, 4, 4, 512)         1180160   
                                                                 
 conv2d_12 (Conv2D)          (None, 4, 4, 512)         2359808   
                                                                 
 activation_6 (Activation)   (None, 4, 4, 512)         0         
                                                                 
 conv2d_13 (Conv2D)          (None, 4, 4, 512)         2359808   
                                                                 
 conv2d_14 (Conv2D)          (None, 2, 2, 512)         2359808   
                                                                 
 activation_7 (Activation)   (None, 2, 2, 512)         0         
                                                                 
 conv2d_15 (Conv2D)          (None, 2, 2, 512)         2359808   
                                                                 
 conv2d_16 (Conv2D)          (None, 2, 2, 512)         2359808   
                                                                 
 activation_8 (Activation)   (None, 2, 2, 512)         0         
                                                                 
 conv2d_17 (Conv2D)          (None, 2, 2, 512)         2359808   
                                                                 
 conv2d_18 (Conv2D)          (None, 1, 1, 512)         2359808   
                                                                 
 activation_9 (Activation)   (None, 1, 1, 512)         0         
                                                                 
 flatten (Flatten)           (None, 512)               0         
                                                                 
 dense (Dense)               (None, 512)               262656    
                                                                 
 dense_1 (Dense)             (None, 10)                5130      
                                                                 
 activation_10 (Activation)  (None, 10)                0         
                                                                 
=================================================================
Total params: 20,476,682
Trainable params: 20,476,682
Non-trainable params: 0
_________________________________________________________________

The error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In [13], line 7
      2 from spkeras.spkeras.models import cnn_to_snn
      4 #Current normalisation using cnn_to_snn
      5 ##Default: signed_bit=0, amp_factor=100, method=1, epsilon = 0.001
----> 7 snn_model = cnn_to_snn(signed_bit=0)(cnn_model,x_train)

File /opt/ml_team_data/saurav/new/saurav/vgg16/SpKeras/spkeras/spkeras/models.py:29, in cnn_to_snn.__call__(self, mdl, x_train)
     27 self.use_bias = use_bias        
     28 self.get_config()
---> 29 self.model = self.convert(mdl,x_train,                    
     30                           thresholding = self.thresholding,
     31                           scaling_factor = self.scaling_factor,
     32                           method = self.method,
     33                           timesteps=self.timesteps)
     35 return self

File /opt/ml_team_data/saurav/new/saurav/vgg16/SpKeras/spkeras/spkeras/models.py:101, in cnn_to_snn.convert(self, mdl, x_train, thresholding, scaling_factor, method, timesteps)
     98     _weights[0] = _weights[0].astype(int)   
     99     _weights[0] = _weights[0]/2**bit
--> 101 _bias = kappa*_weights[1]/lmax[num+1]
    102 _bias = _bias/norm
    103 bias.append(_bias.tolist())    

IndexError: list index out of range

IndexError: list index out of range

I have trained and saved a model and want to convert it to SNN by using SpKeras, but after running the code to convert I am facing the following issue:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Input In [10], in <cell line: 7>()
      2 from spkeras.spkeras.models import cnn_to_snn
      4 #Current normalisation using cnn_to_snn
      5 ##Default: signed_bit=0, amp_factor=100, method=1, epsilon = 0.001
----> 7 snn_model = cnn_to_snn(signed_bit=0)(cnn_model,x_train)

File ~/Desktop/Toy network/spkeras/spkeras/models.py:29, in cnn_to_snn.__call__(self, mdl, x_train)
     27 self.use_bias = use_bias        
     28 self.get_config()
---> 29 self.model = self.convert(mdl,x_train,                    
     30                           thresholding = self.thresholding,
     31                           scaling_factor = self.scaling_factor,
     32                           method = self.method,
     33                           timesteps=self.timesteps)
     35 return self

File ~/Desktop/Toy network/spkeras/spkeras/models.py:101, in cnn_to_snn.convert(self, mdl, x_train, thresholding, scaling_factor, method, timesteps)
     98     _weights[0] = _weights[0].astype(int)   
     99     _weights[0] = _weights[0]/2**bit
--> 101 _bias = kappa*_weights[1]/lmax[num+1]
    102 _bias = _bias/norm
    103 bias.append(_bias.tolist())    

IndexError: list index out of range

My model:

Model: "model"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 input_1 (InputLayer)        [(None, 32, 32, 3)]       0         
                                                                 
 conv2d (Conv2D)             (None, 32, 32, 4)         16        
                                                                 
 conv2d_1 (Conv2D)           (None, 16, 16, 64)        2368      
                                                                 
 conv2d_2 (Conv2D)           (None, 16, 16, 72)        41544     
                                                                 
 conv2d_3 (Conv2D)           (None, 8, 8, 256)         166144    
                                                                 
 conv2d_4 (Conv2D)           (None, 8, 8, 256)         65792     
                                                                 
 conv2d_5 (Conv2D)           (None, 8, 8, 64)          16448     
                                                                 
 flatten (Flatten)           (None, 4096)              0         
                                                                 
 dropout (Dropout)           (None, 4096)              0         
                                                                 
 dense (Dense)               (None, 100)               409700    
                                                                 
 dense_1 (Dense)             (None, 10)                1010      
                                                                 
=================================================================
Total params: 703,022
Trainable params: 703,022
Non-trainable params: 0

Any solutions ?

I also tried solving it by referring to this, but I wasn't able to.

Which neuromorphic hardware does SpKeras simulate ?

Hello,

I have been recently using SpKeras, but I am still not sure which neuromorphic hardware does it simulate ?
For example,
I used it to create an ANN, convert it to SNN and then simulate the SNN using SpKeras. But which neuromorphic hardware does SpKeras use to simulate SNNs ?

Also, the code the network architecture that I tried simulating is this

Low accuracy with bitwidth = 32

Hello @Dengyu-Wu ,
We are attempting to convert VGG16 network to snn, but are getting low accuracies whenever signed_bit is set to anything other than 0 (including 32, all other params unchanged). Please let us know if you've faced this issue before, or if it could be something on our end.

Output for Signed_bit = 0 :
{'timesteps': 256, 'thresholding': 0.5, 'amp_factor': 100, 'signed_bit': 0, 'spike_ext': 0, 'epsilon': 0.001, 'use_bias': True, 'scaling_factor': 1, 'noneloss': False, 'method': 1} 313/313 [==============================] - 35s 111ms/step - loss: 1624.8730 - accuracy: 0.7886

Output for Signed_bit = 32 :
{'timesteps': 256, 'thresholding': 0.5, 'amp_factor': 100, 'signed_bit': 32, 'spike_ext': 0, 'epsilon': 0.001, 'use_bias': True, 'scaling_factor': 1, 'noneloss': False, 'method': 1} 313/313 [==============================] - 39s 125ms/step - loss: 375521.1562 - accuracy: 0.1000

Thanks and regards,
Madhav

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.