## Issue

I’m trying to make some LSTM+CNN hybrid for my college project.

Basically, I have 2 kind of data: a grid which is 10×12 matrix containing 12 technical indicators for stock’s price for the last 10 days, and the price itself

The idea is to process the grid with CNN then use the output as LSTM’s input along with the price

here’s my code

```
def model_robo():
grid=tf.keras.Input(shape=(10,12,1),dtype=tf.float32) #grid input
#processing with CNN
cnn_result=tf.keras.layers.TimeDistributed(Conv2D(1,kernel_size=(3,3),data_format="channels_first"))(grid) #here's the error
cnn_result=tf.keras.layers.TimeDistributed(MaxPooling2D(2,2))(cnn_result)
cnn_result=tf.keras.layers.TimeDistributed(flatten())(cnn_result)
#processing with LSTM
lstm_input=Concatenate()([price,cnn_result])
masked_position=Masking(mask_value=-1)(lstm_input)
result=LSTM(50, name='LSTM')(masked_position)
prediction=(TimeDistributed(Dense(1,activation="relu")))(result)
model=tf.keras.Model(inputs=[grid,price],outputs=[prediction])
return model
```

but when I’m trying to call the model with

```
model=model_robo()
```

it gives:

```
ValueError: Input 0 of layer conv2d_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 12, 1)
```

which stems from:

```
cnn_result=tf.keras.layers.TimeDistributed(Conv2D(1,kernel_size=(3,3),data_format="channels_first"))(grid)
```

I’ve also tried to put:

```
grid=tf.keras.layers.Reshape((10,12,1))(grid)
```

above the error line, no luck.

i’ve check the grid’s dimension with `print(grid.shape)`

and it gives me `(None,10,12,1)`

which I’m sure is the correct dimension but the code delete the second dimension for some reason.

does anyone know how to fix this? let me know if you need additional information and thank you

## Solution

After reviewing what each function does again I realized I shouldn’t use TimeDistributed because each batch already represent one period of time.

changing the line into `cnn_result=tf.keras.layers.Conv2D(1,kernel_size=(3,3))(grid)`

fix the problem.

Answered By – Ikhwan Nuttaqwa

**This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 **