Import sensor dataset

Hello everyone

I’m new to Nengo and I have some doubts about how I can solve a classification problem with NengoDL. First I have a question about how to import the input data. In most NengoDL data training examples the MNIST dataset is used, but if I have a dataset (in a text file) of FSR (Force Sensing Resistors) type force sensor signal with a certain sample frequency. How can you import this temporal data into a training?

I would say that this is not a NengoDL question, but rather, a general question on how you would import this form of temporal data into a Keras network. It really depends on what format your data is in, and for the following suggestions, I’m assuming that your data is just the waveform (e.g. voltage or current or resistance reading) you record from the FSR. Off the top of my head, I can think of two methods:

  1. The first method is to treat the entire FSR waveform as the input signal. I.e., rather than an input “image” to an “MNIST” network, you would have the entire FSR waveform as your “image”. This may work for your application, but the one downside to this method is that the waveforms for all training / testing data points must have the same length (i.e., same number of sample points).
  2. The second method is to present the FSR waveform as an input to the network. The psMNIST example is a good reference for how to take “static” data and convert it to “temporal” data. Note that in order for this approach to work, you’ll need a Keras or NengoDL network that has some kind of recurrence.

Hello xchoo!
Many thanks for the reply!

You are correct in assuming that it is just a signal (waveform) that I record from the FSR. But let me explain my problem to see if these two proposed methods can really be used in solving the problem.

I have several experiments with FSR sensor registers and I also have my waveform target of each input signal (as a ground truth of the FSR waveform). All data from the training experiments are concatenated in a single file, as well as the test data (in a separate file). So, I want to perform a supervised training so that the input waveform (train data) represents my waveform target (train target). In this way, can these proposed methods be used for this problem?

Also, if I assume my input data is being imported in this way, for example:

# Import data 
data_train = np.genfromtxt('localdata\dataTrain.txt', delimiter=' ')
data_test = np.genfromtxt('localdata\dataTest.txt', delimiter=' ')

# Assign the correct values ​​in a vector
train_data = data_train.T[0, 0:40000]        # FSR
train_target = data_train.T[1, 0:40000]      # Ground Truth
test_data = data_test.T[0, 0:40000]           # FSR
test_target = data_test.T[1, 0:40000]        # Ground Truth

# Reshape train and test datas
train_data = np.reshape(train_data,(train_data.size,1,1))
train_target = np.reshape(train_target ,(train_target.size,1,1))
test_data = np.reshape(test_data ,(test_data.size,1,1))
test_target = np.reshape(test_target ,(test_target.size,1,1))

# create data dictionaries
# assume that inpt_probe and out_probe are input and output nodes of a neural network;
train_inputs = {inpt_probe: train_data }
train_targets = {out_probe: train_target}
test_inputs = {inpt_probe: test_data}
test_targets = {out_probe: test_target}

Is it correct to enter this data in this way in the sim.fit function in NengoDL to do the training? Or is another way to do it? Example:

sim.fit(train_inputs, train_targets, epochs=10)

Also, can I calculate training accuracy in the same way as used in training examples with MNIST data? Also, if I want to calculate, for example, false positives or negatives, does NengoDL have any function to calculate this metric?

Thanks a lot!

From the brief look at the code, yes, the way to train your network would be to use the sim.fit function. I should note that NengoDL’s sim.fit function is just a wrapper around Tensorflow’s model.fit function, so whatever you can do with model.fit, you can do with sim.fit.

There shouldn’t be anything stopping you from obtaining the training accuracy in the same way as the MNIST data.

NengoDL itself doesn’t have any built-in functions to compute these metrics, but this is because NengoDL run on top of Tensorflow, and so you can use Tensorflow’s metrics to accomplish the things you want to do.

Thank a lot @xchoo for the reply!