I’m trying to build a very simple model of some numerical data.
My model is as follows:
model = Sequential()
model.add(Dense(32, activation=‘relu’, input_dim=1))
model.add(Dense(6, activation=‘sigmoid’))
model.compile(optimizer=‘rmsprop’, loss=‘binary_crossentropy’, metrics = [‘accuracy’])
model.fit(x_train, y_train, epochs=10)
x_train is a numpy.ndarray with size 236. Each element of x_train is a list containing 218 elements, all of which are numpy.float64.
y_train is a one-hot encoded numpy.ndarray with size 236. Each element is a list with 6 elements.
I’ve tried with x_train as a list also, just in case that would help, but I got the same error. I’m kind of stuck, and haven’t found a good answer on google.
I get a long error:
Epoch 1/10
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
3 model.add(Dense(6, activation=‘sigmoid’))
4 model.compile(optimizer=‘rmsprop’, loss=‘binary_crossentropy’, metrics = [‘accuracy’])
----> 5 model.fit(x_train, y_train, epochs=10)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/models.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, **kwargs)
851 class_weight=class_weight,
852 sample_weight=sample_weight,
--> 853 initial_epoch=initial_epoch)
854
855 def evaluate(self, x, y, batch_size=32, verbose=1,
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, **kwargs)
1484 val_f=val_f, val_ins=val_ins, shuffle=shuffle,
1485 callback_metrics=callback_metrics,
-> 1486 initial_epoch=initial_epoch)
1487
1488 def evaluate(self, x, y, batch_size=32, verbose=1, sample_weight=None):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training.py in _fit_loop(self, f, ins, out_labels, batch_size, epochs, verbose, callbacks, val_f, val_ins, shuffle, callback_metrics, initial_epoch)
1139 batch_logs['size'] = len(batch_ids)
1140 callbacks.on_batch_begin(batch_index, batch_logs)
-> 1141 outs = f(ins_batch)
1142 if not isinstance(outs, list):
1143 outs = [outs]
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/backend/theano_backend.py in __call__(self, inputs)
1120 def __call__(self, inputs):
1121 assert isinstance(inputs, (list, tuple))
-> 1122 return self.function(*inputs)
1123
1124
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/theano/compile/function_module.py in __call__(self, *args, **kwargs)
793 s.storage[0] = s.type.filter(
794 arg, strict=s.strict,
--> 795 allow_downcast=s.allow_downcast)
796
797 except Exception as e:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/theano/tensor/type.py in filter(self, data, strict, allow_downcast)
115 if allow_downcast:
116 # Convert to self.dtype, regardless of the type of data
--> 117 data = theano._asarray(data, dtype=self.dtype)
118 # TODO: consider to pad shape with ones to make it consistent
119 # with self.broadcastable... like vector->row type thing
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/theano/misc/safe_asarray.py in _asarray(a, dtype, order)
32 dtype = theano.config.floatX
33 dtype = np.dtype(dtype) # Convert into dtype object.
---> 34 rval = np.asarray(a, dtype=dtype, order=order)
35 # Note that dtype comparison must be done by comparing their `num`
36 # attribute. One cannot assume that two identical data types are pointers
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy/core/numeric.py in asarray(a, dtype, order)
529
530 """
--> 531 return array(a, dtype, copy=False, order=order)
532
533
ValueError: Bad input argument to theano function with name "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/backend/theano_backend.py:1118" at index 0 (0-based).
Backtrace when that variable is created:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2717, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2821, in run_ast_nodes
if self.run_code(code, result):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-201-84fb2cbef217>", line 2, in <module>
model.add(Dense(32, activation='relu', input_dim=1))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/models.py", line 426, in add
dtype=layer.dtype, name=layer.name + '_input')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/topology.py", line 1392, in Input
input_tensor=tensor)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/topology.py", line 1303, in __init__
name=self.name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/backend/theano_backend.py", line 184, in placeholder
x = T.TensorType(dtype, broadcast)(name)
setting an array element with a sequence.