CEA-LIST / N2D2

N2D2 is an open source CAD framework for Deep Neural Network simulation and full DNN-based applications building.
Other
146 stars 35 forks source link

How to use a dataset not predefined in N2D2? #31

Closed vankhoa21991 closed 1 year ago

vankhoa21991 commented 5 years ago

Hello, For our project, I want to import my own dataset to N2D2. It could be both images dataset or spike dataset from event camera like files .raw, .aedat, .dat, etc. Do you have any tutorial for that function. Thanks

johannesthiele-cea commented 5 years ago

Hello,

I updated the Environment class so that it is possible to either convert a static dataset or use a AER dataset. You can compare the models mnist-stdp.ini and mnist-stdp-NMNIST.ini to see how this is done for the MNIST and NMNIST dataset.s

In general, you have to write your own driver if you want to include a dataset. A driver is a module that manages the training and test partition and how the dataset is read from the raw data. How this is done can be seen in the classes src/Database/MNIST_IDX_Database.cpp, src/Generator/MNIST_IDX_DatabaseGenerator.cpp (and the respective versions for NMNIST).

vankhoa21991 commented 5 years ago

Hello, I ran into this error while launching the mnist-stdpNMNIST.ini . I think the data is good, so it could be a problem in the code.

/n2d2 "mnist-stdp-NMNIST.ini" -learn 500000 -log 10000... Option -log: number of steps between logs [10000] Option -learn: number of backprop learning steps [500000] Loading network configuration file mnist-stdp-NMNIST.ini Layer: fc1 [Fc(Spike_Analog)] Notice: Could not open configuration file: fc1.cfg

Synapses: 115650

Inputs dims: 34 34 2

Outputs dims: 1 1 50

Target: fc1 (target value: 1 / default value: 0 / top-n value: 1) Total number of neurons: 50 Total number of nodes: 50 Total number of synapses: 115650 Total number of virtual synapses: 115650 Total number of connections: 115650 Notice: Unused section fc1.Target in INI file Notice: Unused section common.config in INI file Notice: Unused section common_Spike_RRAM.config in INI file Learning database size: 30000 images Validation database size: 30000 images Testing database size: 10000 images [LOG] Stimuli transformations flow (transformations.png) sh: 1: dot: not found [LOG] Network graph (mnist-stdp-NMNIST.ini.png) [LOG] Network SVG graph (mnist-stdp-NMNIST.ini.svg) sh: 1: dot: not found [LOG] Network stats (stats/) [LOG] Solvers scheduling (schedule/) [LOG] Layer's receptive fields (receptive_fields.log) [LOG] Labels mapping (.Target/labels_mapping.log) [LOG] Labels legend (.Target/labels_legend.png) Warning: empty y range [115650:115650], adjusting to [114494:116806] Warning: empty cb range [115650:115650], adjusting to [114494:116806] Warning: empty y range [115650:115650], adjusting to [114494:116806] Warning: empty cb range [115650:115650], adjusting to [114494:116806] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [50:50], adjusting to [49.5:50.5] Warning: empty cb range [50:50], adjusting to [49.5:50.5] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [115650:115650], adjusting to [114494:116806] Warning: empty cb range [115650:115650], adjusting to [114494:116806] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [115650:115650], adjusting to [114494:116806] Warning: empty cb range [115650:115650], adjusting to [114494:116806] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [50:50], adjusting to [49.5:50.5] Warning: empty cb range [50:50], adjusting to [49.5:50.5] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] line 0: Can't plot with an empty x range!

Invalid registrar key "bin" terminate called after throwing an instance of 'std::bad_function_call' what(): bad_function_call 10:12:25: The program has unexpectedly finished.

vankhoa21991 commented 5 years ago

I found the answer, have to use -learn-stdp instead.

vankhoa21991 commented 5 years ago

Hello, I tried this example, and the acc reach ~72% /n2d2 ../../../models/mnist-stdp.ini -learn-stdp 100000 -log 10000

But when I want to test the model, it demain the folder 'weights' and 'weights_range_normalized', when I only have the weights-init and weights-stdp instead. Do you have any idea about this? Thanks

davidbriand-cea commented 5 years ago

Hello, I think you have to specify the folder "weights-stdp" for testing : ./n2d2 ../../../models/mnist-stdp.ini -w weights-stdp -test

vankhoa21991 commented 5 years ago

Hello, it demands always the weights_range directory

/n2d2 ../../../models/mnist-stdp.ini -w weights-stdp -test Option -test: perform testing Option -w: start with weights imported from a specified location (even when loading a previously saved state) [weights-stdp] Loading network configuration file ../../../models/mnist-stdp.ini Layer: fc1 [Fc(Spike_Analog)] Notice: Could not open configuration file: fc1.cfg

Synapses: 39250

Inputs dims: 28 28 1

Outputs dims: 1 1 50

Target: fc1 (target value: 1 / default value: 0 / top-n value: 1) Total number of neurons: 50 Total number of nodes: 50 Total number of synapses: 39250 Total number of virtual synapses: 39250 Total number of connections: 39250 Notice: Unused section fc1.Target in INI file Notice: Unused section common.config in INI file Notice: Unused section common_Spike_RRAM.config in INI file Learning database size: 60000 images Validation database size: 0 images Testing database size: 10000 images [LOG] Stimuli transformations flow (transformations.png) [LOG] Network graph (mnist-stdp.ini.png) sh: 1: dot: not found [LOG] Network SVG graph (mnist-stdp.ini.svg) sh: 1: dot: not found [LOG] Network stats (stats/) [LOG] Solvers scheduling (schedule/) [LOG] Layer's receptive fields (receptive_fields.log) [LOG] Labels mapping (.Target/labels_mapping.log) [LOG] Labels legend (.Target/labels_legend.png) Warning: empty y range [39250:39250], adjusting to [38857.5:39642.5] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [39250:39250], adjusting to [38857.5:39642.5] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [39250:39250], adjusting to [38857.5:39642.5] Warning: empty y range [39250:39250], adjusting to [38857.5:39642.5] Warning: empty cb range [39250:39250], adjusting to [38857.5:39642.5] Warning: empty cb range [39250:39250], adjusting to [38857.5:39642.5] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [50:50], adjusting to [49.5:50.5] Warning: empty cb range [50:50], adjusting to [49.5:50.5] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [39250:39250], adjusting to [38857.5:39642.5] Warning: empty cb range [39250:39250], adjusting to [38857.5:39642.5] Warning: empty y range [100:100], adjusting to [99:101] Warning: empty cb range [100:100], adjusting to [99:101] Warning: empty y range [50:50], adjusting to [49.5:50.5] Warning: empty cb range [50:50], adjusting to [49.5:50.5] line 0: Can't plot with an empty x range!

Importing weights from directory 'weights-stdp'. Notice: Could not open synaptic file: weights-stdp/fc1_weights.syntxt [LOG] Learn frame samples (frames/frame) Notice: stimuli depth is 8U (according to database first stimulus) [LOG] Test frame samples (frames/test_frame) Error for testing: DeepNet::getTargetCell(): wrong cell type for index 0 Continue... Importing weights from directory 'weights_range_normalized'. Time elapsed: 1.40786 s Error: Could not open synaptic file: weights_range_normalized/fc1_weights.syntxt

vankhoa21991 commented 5 years ago

Actually I get the points, the weights_range_normalized folder only created by the function test (image). So for testing an SNN trained by back propagation on ANN and run on pure spike (NMNIST), I guess it's not possible. Another question about the mnist-stdp-NMNIST, I can only reach ~12%, do you know about this?

olivierbichler-cea commented 5 years ago

Hi, what you are saying is entirely possible. Actually there is a conflict between the -w parameter and the weight_range_normalized folder which is forced in testing when not using -learn-stdp. This behavior is confusing and must be changed. As a temporary fix, you can juste rename the weight_stdp or weight_validation folder into weight_range_normalized.