How to concatenate inputs parameters to the CNN_M_LSTM model?

I try to feed the the energy consumption with timestamp dataset and covid dataset into the CNN_M_LSTM model (library Tensorflow and Keras API).

Energy consumption with timestamp dataset has the size (730, 2)

Covid dataset has the size (730, 1)

I want to slice and window both covid dataset, Energy consumption with timestamp ( with batch size = 128 and window size is 96). Finally zip both dataset together.

Here is my code slice and window both the energy consumption and timestamp dataset, the covid dataset:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>MAX_LENGTH = 96
BATCH_SIZE = 128
TRAIN.SHUFFLE_BUFFER_SIZE = 1000
</code>
<code>MAX_LENGTH = 96 BATCH_SIZE = 128 TRAIN.SHUFFLE_BUFFER_SIZE = 1000 </code>
MAX_LENGTH = 96
BATCH_SIZE = 128 
TRAIN.SHUFFLE_BUFFER_SIZE = 1000

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def windowed_dataset(series, window_size=MAX_LENGTH, batch_size=BATCH_SIZE, shuffle_buffer=TRAIN.SHUFFLE_BUFFER_SIZE):
"""
We create time windows to create X and y features.
For example, if we choose a window of 30, we will create a dataset formed by 30 points as X
"""
dataset= tf.data.Dataset.from_tensor_slices(series)
dataset = dataset.window(window_size + 1, shift=1)
dataset = dataset.flat_map(lambda window: window.batch(window_size + 1)) # the order dataset stays the same
dataset = dataset.shuffle(1000)
dataset = dataset.map(lambda window: (window[:-1], window[-1][0]))
dataset = dataset.padded_batch(128,drop_remainder=True).cache()
return dataset
</code>
<code>def windowed_dataset(series, window_size=MAX_LENGTH, batch_size=BATCH_SIZE, shuffle_buffer=TRAIN.SHUFFLE_BUFFER_SIZE): """ We create time windows to create X and y features. For example, if we choose a window of 30, we will create a dataset formed by 30 points as X """ dataset= tf.data.Dataset.from_tensor_slices(series) dataset = dataset.window(window_size + 1, shift=1) dataset = dataset.flat_map(lambda window: window.batch(window_size + 1)) # the order dataset stays the same dataset = dataset.shuffle(1000) dataset = dataset.map(lambda window: (window[:-1], window[-1][0])) dataset = dataset.padded_batch(128,drop_remainder=True).cache() return dataset </code>
def windowed_dataset(series, window_size=MAX_LENGTH, batch_size=BATCH_SIZE, shuffle_buffer=TRAIN.SHUFFLE_BUFFER_SIZE):
    """
    We create time windows to create X and y features.
    For example, if we choose a window of 30, we will create a dataset formed by 30 points as X
    """
    dataset= tf.data.Dataset.from_tensor_slices(series) 
    dataset = dataset.window(window_size + 1, shift=1) 
    dataset = dataset.flat_map(lambda window: window.batch(window_size + 1)) # the order dataset stays the same
    dataset = dataset.shuffle(1000)
    dataset = dataset.map(lambda window: (window[:-1], window[-1][0])) 
    dataset = dataset.padded_batch(128,drop_remainder=True).cache()

    return dataset

Here how I zip the dataset:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
train_energy_dataset = windowed_dataset(TRAIN.PRE_PROCESSED_SERIES)
train_covid_dataset = windowed_dataset(TRAIN.SERIES_COVID)
train_dataset = tf.data.Dataset.zip((train_covid_dataset,train_energy_dataset))
train_dataset = train_dataset.shuffle(buffer_size=1000)
train_dataset = train_dataset.map(lambda data1, data2: ((data1[0], data2[0]), data1[1])) # Adjust mapping as per your need
train_dataset = train_dataset.batch(128, drop_remainder=True).cache()
</code>
<code> train_energy_dataset = windowed_dataset(TRAIN.PRE_PROCESSED_SERIES) train_covid_dataset = windowed_dataset(TRAIN.SERIES_COVID) train_dataset = tf.data.Dataset.zip((train_covid_dataset,train_energy_dataset)) train_dataset = train_dataset.shuffle(buffer_size=1000) train_dataset = train_dataset.map(lambda data1, data2: ((data1[0], data2[0]), data1[1])) # Adjust mapping as per your need train_dataset = train_dataset.batch(128, drop_remainder=True).cache() </code>

train_energy_dataset = windowed_dataset(TRAIN.PRE_PROCESSED_SERIES)
train_covid_dataset = windowed_dataset(TRAIN.SERIES_COVID)


train_dataset = tf.data.Dataset.zip((train_covid_dataset,train_energy_dataset))

train_dataset = train_dataset.shuffle(buffer_size=1000)
train_dataset = train_dataset.map(lambda data1, data2: ((data1[0], data2[0]), data1[1]))  # Adjust mapping as per your need
train_dataset = train_dataset.batch(128, drop_remainder=True).cache()

My model:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
def create_CNN_LSTM_model():
# Define the inputs
input1 = tf.keras.layers.Input(shape=(128,1), name="input1")
input2 = tf.keras.layers.Input(shape=(128,2), name="input2")
# Define the CNN-LSTM part of the model
x = tf.keras.layers.Conv1D(filters=128, kernel_size=3, activation='relu', strides=1, padding="causal")(input1)
x = tf.keras.layers.MaxPooling1D(pool_size=2)(x)
x = tf.keras.layers.Conv1D(filters=64, kernel_size=3, activation='relu', strides=1, padding="causal")(x)
x = tf.keras.layers.MaxPooling1D(pool_size=2)(x)
x = tf.keras.layers.Dropout(0.5)(x)
x = tf.keras.layers.LSTM(16, return_sequences=True)(x)
x = tf.keras.layers.LSTM(8, return_sequences=True)(x)
x = tf.keras.layers.Flatten()(x)
output_lstm = tf.keras.layers.Dense(1)(x)
# Define the dense part of the model
output_dense_1 = tf.keras.layers.Dense(1)(input2)
# Concatenate the outputs of LSTM and Dense layers
concatenated = tf.keras.layers.Concatenate(axis=1)([output_dense_1, output_lstm])
# Add further dense layers
x = tf.keras.layers.Dense(6, activation=tf.nn.leaky_relu)(concatenated)
output = tf.keras.layers.Dense(4)(x)
model_final = tf.keras.Model(inputs=[input1, input2], outputs=output)
# Define the final model
return model_final
</code>
<code> def create_CNN_LSTM_model(): # Define the inputs input1 = tf.keras.layers.Input(shape=(128,1), name="input1") input2 = tf.keras.layers.Input(shape=(128,2), name="input2") # Define the CNN-LSTM part of the model x = tf.keras.layers.Conv1D(filters=128, kernel_size=3, activation='relu', strides=1, padding="causal")(input1) x = tf.keras.layers.MaxPooling1D(pool_size=2)(x) x = tf.keras.layers.Conv1D(filters=64, kernel_size=3, activation='relu', strides=1, padding="causal")(x) x = tf.keras.layers.MaxPooling1D(pool_size=2)(x) x = tf.keras.layers.Dropout(0.5)(x) x = tf.keras.layers.LSTM(16, return_sequences=True)(x) x = tf.keras.layers.LSTM(8, return_sequences=True)(x) x = tf.keras.layers.Flatten()(x) output_lstm = tf.keras.layers.Dense(1)(x) # Define the dense part of the model output_dense_1 = tf.keras.layers.Dense(1)(input2) # Concatenate the outputs of LSTM and Dense layers concatenated = tf.keras.layers.Concatenate(axis=1)([output_dense_1, output_lstm]) # Add further dense layers x = tf.keras.layers.Dense(6, activation=tf.nn.leaky_relu)(concatenated) output = tf.keras.layers.Dense(4)(x) model_final = tf.keras.Model(inputs=[input1, input2], outputs=output) # Define the final model return model_final </code>

def create_CNN_LSTM_model():
    # Define the inputs
    input1 = tf.keras.layers.Input(shape=(128,1), name="input1")
    input2 = tf.keras.layers.Input(shape=(128,2), name="input2")

    # Define the CNN-LSTM part of the model
    x = tf.keras.layers.Conv1D(filters=128, kernel_size=3, activation='relu', strides=1, padding="causal")(input1)
    x = tf.keras.layers.MaxPooling1D(pool_size=2)(x)
    x = tf.keras.layers.Conv1D(filters=64, kernel_size=3, activation='relu', strides=1, padding="causal")(x)
    x = tf.keras.layers.MaxPooling1D(pool_size=2)(x)
    x = tf.keras.layers.Dropout(0.5)(x)
    x = tf.keras.layers.LSTM(16, return_sequences=True)(x)
    x = tf.keras.layers.LSTM(8, return_sequences=True)(x)
    x = tf.keras.layers.Flatten()(x)
    output_lstm = tf.keras.layers.Dense(1)(x)

    # Define the dense part of the model
    output_dense_1 = tf.keras.layers.Dense(1)(input2)

    # Concatenate the outputs of LSTM and Dense layers
    concatenated = tf.keras.layers.Concatenate(axis=1)([output_dense_1, output_lstm])

    # Add further dense layers
    x = tf.keras.layers.Dense(6, activation=tf.nn.leaky_relu)(concatenated)
    output = tf.keras.layers.Dense(4)(x)
    model_final = tf.keras.Model(inputs=[input1, input2], outputs=output)
    # Define the final model
    return model_final
   

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>model_cnn_m_lstm = create_CNN_LSTM_model()
# Compile the model
model_cnn_m_lstm.compile(
loss=tf.keras.losses.Huber(),
optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
metrics=["mse"]
)
model_cnn_m_lstm.summary()
model_cnn_m_lstm.fit(train_dataset, epochs=100, batch_size=128)
</code>
<code>model_cnn_m_lstm = create_CNN_LSTM_model() # Compile the model model_cnn_m_lstm.compile( loss=tf.keras.losses.Huber(), optimizer=tf.keras.optimizers.Adam(learning_rate=0.001), metrics=["mse"] ) model_cnn_m_lstm.summary() model_cnn_m_lstm.fit(train_dataset, epochs=100, batch_size=128) </code>
model_cnn_m_lstm = create_CNN_LSTM_model()

    # Compile the model
model_cnn_m_lstm.compile(
        loss=tf.keras.losses.Huber(),
        optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
        metrics=["mse"]
    )

model_cnn_m_lstm.summary()



model_cnn_m_lstm.fit(train_dataset, epochs=100, batch_size=128)

With the trial to window and zip the datasets, I receive error as

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>ValueError: Exception encountered when calling Functional.call().
Invalid input shape for input Tensor("functional_100_1/Cast_1:0", shape=(128, 128, None, 2), dtype=float32). Expected shape (None, 128, 2), but input has incompatible shape (128, 128, None, 2)
Arguments received by Functional.call():
• inputs=('tf.Tensor(shape=(128, 128, None, 1), dtype=float64)', 'tf.Tensor(shape=(128, 128, None, 2), dtype=float64)')
• training=True
• mask=('None', 'None')
</code>
<code>ValueError: Exception encountered when calling Functional.call(). Invalid input shape for input Tensor("functional_100_1/Cast_1:0", shape=(128, 128, None, 2), dtype=float32). Expected shape (None, 128, 2), but input has incompatible shape (128, 128, None, 2) Arguments received by Functional.call(): • inputs=('tf.Tensor(shape=(128, 128, None, 1), dtype=float64)', 'tf.Tensor(shape=(128, 128, None, 2), dtype=float64)') • training=True • mask=('None', 'None') </code>
ValueError: Exception encountered when calling Functional.call().

Invalid input shape for input Tensor("functional_100_1/Cast_1:0", shape=(128, 128, None, 2), dtype=float32). Expected shape (None, 128, 2), but input has incompatible shape (128, 128, None, 2)

Arguments received by Functional.call():
  • inputs=('tf.Tensor(shape=(128, 128, None, 1), dtype=float64)', 'tf.Tensor(shape=(128, 128, None, 2), dtype=float64)')
  • training=True
  • mask=('None', 'None')

I also fixed by change the input shape of the model to

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> input1 = tf.keras.layers.Input(shape=(128,2), name="input1")
input2 = tf.keras.layers.Input(shape=(128), name="input2")
</code>
<code> input1 = tf.keras.layers.Input(shape=(128,2), name="input1") input2 = tf.keras.layers.Input(shape=(128), name="input2") </code>
    input1 = tf.keras.layers.Input(shape=(128,2), name="input1")
    input2 = tf.keras.layers.Input(shape=(128), name="input2")
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>The error appear as expected 2 dims but received 3 dims.
</code>
<code>The error appear as expected 2 dims but received 3 dims. </code>
The error appear as expected 2 dims but received 3 dims. 

My expectation is to feed the zip dataset into my CNN_M_LSTM model.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật