0

My data is a (83,104) pandas dataframe. And my first(only) hidden layer is expected to have 5 neurons.

When I wrote my code like this:

input_img = Input(shape=(104,)) # 104 dates as variable

encoded = Dense(5, activation='relu')(input_img)
decoded = Dense(104, activation='relu')(encoded)
autoencoder = Model(input_img, decoded)

autoencoder.compile(loss='mean_squared_error', optimizer='sgd')
autoencoder.fit(train_data, train_data, epochs=50)

I receive error message:

ValueError: Shape mismatch: x has 32 cols (and 83 rows) but y has 104 rows (and 5 cols)
Apply node that caused the error: Dot22(/input_24, dense_47/kernel)
Toposort index: 2
Inputs types: [TensorType(float32, matrix), TensorType(float32, matrix)]
Inputs shapes: [(83, 32), (104, 5)]
Inputs strides: [(4, 332), (20, 4)]

I have followed the guidance from https://blog.keras.io/building-autoencoders-in-keras.html.

Does anyone know what is wrong here?

Thanks,

phil
  • 171
  • 2
  • 8
  • are you sure about your shapes you enter, input and output. What is the input and output shape your are feeding the model? – J.Down May 27 '17 at 03:23
  • I am pretty sure. Input is (83,104) pandas dataframe. Since it is an autoencoder model, output should be the same as input, with only hidden layer 5 neurons. – phil May 27 '17 at 04:39
  • The error indicates that the shapes are inconsistent.. But your fit take in `train_data` in both input and output.. Could you make a reproducible example with full traceback. – J.Down May 27 '17 at 04:44
  • I just follow https://blog.keras.io/building-autoencoders-in-keras.html but change dataset. You can see that he took in train_data in both input and output as well. – phil May 27 '17 at 05:03
  • I do see that it is the same... But again.. It could be something with your data.. an working example code would help. – J.Down May 27 '17 at 05:07
  • Sry but what means "working example code"... – phil May 27 '17 at 05:10
  • https://stackoverflow.com/help/mcve – J.Down May 27 '17 at 05:16
  • Actually these 6 lines are my core code... – phil May 27 '17 at 05:18
  • Your error message indicate something is wrong the it the input/output shapes, which seem to inconsistent with the code you've provided.. The only way we can help from here is to have a MVCE and a full traceback to work with.. Besides that..An MVCE would make it easier for us to help you. – J.Down May 27 '17 at 05:25
  • I have solved this problem. I use as_matrix() for input – phil Jun 08 '17 at 22:28

0 Answers0