zcakhaa / Multi-Horizon-Forecasting-for-Limit-Order-Books

MIT License
182 stars 73 forks source link

Incompatible shapes for concatenation: [(None, 1, 3), (None, 1, 64)] #4

Open bellerofonte opened 2 months ago

bellerofonte commented 2 months ago

Cell [4] in run_train_deeplob_attention.ipynb

model = get_model_attention(n_hidden)
model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')

fails with error:

ValueError                                Traceback (most recent call last)
Cell In[4], line 1
----> 1 model = get_model_attention(n_hidden)
      2 model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')

File ~/Projects/Multi-Horizon-Forecasting-for-Limit-Order-Books/code_gpu/model_gpu.py:148, in get_model_attention(latent_dim)
    145 all_attention = []
    147 encoder_state_h = keras.layers.Reshape((1, int(state_h.shape[1])))(state_h)
--> 148 inputs = keras.layers.concatenate([decoder_inputs, encoder_state_h], axis=2)
    150 for _ in range(5):
    151     # h'_t = f(h'_{t-1}, y_{t-1}, c)
    152     outputs, state_h, state_c = decoder_lstm(inputs, initial_state=states)

File ~/.conda/envs/tf/lib/python3.12/site-packages/keras/src/layers/merging/concatenate.py:172, in concatenate(inputs, axis, **kwargs)
    160 @keras_export("keras.layers.concatenate")
    161 def concatenate(inputs, axis=-1, **kwargs):
    162     """Functional interface to the `Concatenate` layer.
    163 
    164     Args:
   (...)
    170         A tensor, the concatenation of the inputs alongside axis `axis`.
    171     """
--> 172     return Concatenate(axis=axis, **kwargs)(inputs)
...
     96         if len(unique_dims) > 1:
---> 97             raise ValueError(err_msg)
     98 self.built = True

ValueError: A `Concatenate` layer requires inputs with matching shapes except for the concatenation axis. 
Received: input_shape=[(None, 1, 3), (None, 1, 64)]

same happens to run_train_deeplob_seq.ipynb at the same section.

what causes the issue?

TF version:

tensorflow                2.16.1          cuda120py312hee4d333_0    conda-forge
tensorflow-base           2.16.1          cuda120py312h3a81633_0    conda-forge
tensorflow-estimator      2.16.1          cuda120py312hfa0f5ef_0    conda-forge
tensorflow-gpu            2.16.1          cuda120py312hb76ca00_0    conda-forge

Keras verison:

keras                     3.3.3              pyhd8ed1ab_0    conda-forge
Gageen commented 1 week ago

Hey! Were you able to resolve this issue?

Gageen commented 1 week ago

Cell [4] in run_train_deeplob_attention.ipynb

model = get_model_attention(n_hidden)
model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')

fails with error:

ValueError                                Traceback (most recent call last)
Cell In[4], line 1
----> 1 model = get_model_attention(n_hidden)
      2 model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')

File ~/Projects/Multi-Horizon-Forecasting-for-Limit-Order-Books/code_gpu/model_gpu.py:148, in get_model_attention(latent_dim)
    145 all_attention = []
    147 encoder_state_h = keras.layers.Reshape((1, int(state_h.shape[1])))(state_h)
--> 148 inputs = keras.layers.concatenate([decoder_inputs, encoder_state_h], axis=2)
    150 for _ in range(5):
    151     # h'_t = f(h'_{t-1}, y_{t-1}, c)
    152     outputs, state_h, state_c = decoder_lstm(inputs, initial_state=states)

File ~/.conda/envs/tf/lib/python3.12/site-packages/keras/src/layers/merging/concatenate.py:172, in concatenate(inputs, axis, **kwargs)
    160 @keras_export("keras.layers.concatenate")
    161 def concatenate(inputs, axis=-1, **kwargs):
    162     """Functional interface to the `Concatenate` layer.
    163 
    164     Args:
   (...)
    170         A tensor, the concatenation of the inputs alongside axis `axis`.
    171     """
--> 172     return Concatenate(axis=axis, **kwargs)(inputs)
...
     96         if len(unique_dims) > 1:
---> 97             raise ValueError(err_msg)
     98 self.built = True

ValueError: A `Concatenate` layer requires inputs with matching shapes except for the concatenation axis. 
Received: input_shape=[(None, 1, 3), (None, 1, 64)]

same happens to run_train_deeplob_seq.ipynb at the same section.

what causes the issue?

TF version:

tensorflow                2.16.1          cuda120py312hee4d333_0    conda-forge
tensorflow-base           2.16.1          cuda120py312h3a81633_0    conda-forge
tensorflow-estimator      2.16.1          cuda120py312hfa0f5ef_0    conda-forge
tensorflow-gpu            2.16.1          cuda120py312hb76ca00_0    conda-forge

Keras verison:

keras                     3.3.3              pyhd8ed1ab_0    conda-forge

Hey!

Were you able to resolve this issue?