I’m trying to make some LSTM+CNN hybrid for my college project and here’s my code
def model_robo(): grid=tf.keras.Input(shape=(1,10,12),dtype=tf.float32) print(grid.shape) cnn_result=tf.keras.layers.TimeDistributed(Conv2D(1,kernel_size=(3,3),data_format="channels_first"))(grid) cnn_result=tf.keras.layers.TimeDistributed(MaxPooling2D(2,2))(cnn_result) cnn_result=tf.keras.layers.TimeDistributed(flatten())(cnn_result) 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]) optim=tf.keras.optimizers.Adam(lr=0.001,amsgrad=False) model.compile(optimizer=optim,loss='mae') return model
but when I’m trying to call the model with
ValueError: The channel dimension of the inputs should be defined. Found None
which stems from:
I’ve tried searching for answer but I think most error comes from the images format like here or here while I don’t really use one (the CNN input is numerical matrix put together to form an "image"). the would-be input is 2159x1x10x12 matrix and the
grid.shape result is (none,1,10,12)
how can i fix this?
let me know if you need additional information and thanks!
It works after I delete the
channels_first (and changed it to
Conv1D but that’s another matters. see here for detail)
My hypothesis is
channels_first took the first dimension (None) as the channel instead of the second one. API docs said first channel should be reserved for batch size but like the comment said, it’s probably a bug
Answered By – Ikhwan Nuttaqwa