python - Keras misinterprets training data shape -
my training data has form (?,15) ? variable length.
when creating model specify this:
inp = input(shape=(none,15)) conv = conv1d(32,3,padding='same',activation='relu')(inp) ...
my training data has shape (35730,?,15).
checking in python get:
x.shape
outputs: (35730,)
x[0].shape
outputs: (513, 15)
when try fit model on training data valueerror:
error when checking input: expected input_1 have 3 dimensions, got array shape (35730, 1)
i can train model using model.train_on_batch() on single sample.
how can solve this? seems keras thinks shape of input data (35730, 1) when (35730, ?, 15)
is bug in keras or did wrong?
i using tensorflow backend if matters. keras 2
(edited, according op's comment on question, posted link: https://github.com/fchollet/keras/issues/1920)
your x
not single numpy array, it's array of arrays. (otherwise shape x.shape=(35730,513,15)
.
it must single numpy array fit
method. since have variable length, cannot have single numpy array containing data, have divide in smaller arrays, each array containing data same length.
for that, should maybe create dictionary shape, , loop dictionary manually (there may other better ways this...):
#code in python 3.5 xbyshapes = {} ybyshapes = {} itemx,itemy in zip(x,y): if itemx.shape in xbyshapes: xbyshapes[itemx.shape].append(itemx) ybyshapes[itemx.shape].append(itemy) else: xbyshapes[itemx.shape] = [itemx] #initially list, because we're going append items ybyshapes[itemx.shape] = [itemy]
at end, loop dictionary training:
for shape in xbyshapes: model.fit( np.asarray(xbyshapes[shape]), np.asarray(ybyshapes[shape]),... )
Comments
Post a Comment