I'm building a simple neural network using keras.
Each element of the training data has 100 dimensions, and I'm reading the labels of the elements from a text file.
f = open('maleE', "rt")
labelsTrain = [line.rstrip() for line in f.readlines()]
f.close()
The labels are strings that have this structure: number_text
To fit the model on the training data:
model.fit(train, labelsTrain, epochs= 20000, batch_size= 1350)
And I get the following error:
File "DNN.py", line 112, in <module>
model.fit(train, labelsTrain, epochs=20000, batch_size=1350)
File "/Users/renzo/PyEnvironments/tensorKeras/lib/python2.7/site-packages/keras/models.py", line 867, in fit
initial_epoch=initial_epoch)
File "/Users/renzo/PyEnvironments/tensorKeras/lib/python2.7/site-packages/keras/engine/training.py", line 1598, in fit
validation_steps=validation_steps)
File "/Users/renzo/PyEnvironments/tensorKeras/lib/python2.7/site-packages/keras/engine/training.py", line 1183, in _fit_loop
outs = f(ins_batch)
File "/Users/renzo/PyEnvironments/tensorKeras/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 2273, in __call__
**self.session_kwargs)
File "/Users/renzo/PyEnvironments/tensorKeras/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 889, in run
run_metadata_ptr)
File "/Users/renzo/PyEnvironments/tensorKeras/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1087, in _run
np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
File "/Users/renzo/PyEnvironments/tensorKeras/lib/python2.7/site-packages/numpy/core/numeric.py", line 531, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: invalid literal for float(): 225_sokode
The label is the element 279 from a list of 378 labels.
First of all, pick a unique name for each of your classes. I say this because I don't get what is the
number
in your class labels (if it is not same for each class, usestr.split()
to just keep thetext
). Then you should encode your string labels. For example, see this post for One-hot encoding of labels.