From 70c3d5493311008fee2c8b7896b8227ea01fd74f Mon Sep 17 00:00:00 2001 From: Dawith Date: Thu, 23 Oct 2025 20:41:19 -0400 Subject: [PATCH] Working version of decoder added?? I think --- model/model.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/model/model.py b/model/model.py index ceea214..be7b97b 100644 --- a/model/model.py +++ b/model/model.py @@ -8,8 +8,8 @@ from keras import Input, Model from keras.layers import BatchNormalization, Conv1D, Dense, Dropout, Reshape, \ - GlobalAveragePooling1D, LayerNormalization, Masking, \ - MultiHeadAttention + GlobalAveragePooling1D, LayerNormalization, Masking, Conv2D, \ + MultiHeadAttention, concatenate from model.transformer import TimeseriesTransformerBuilder as TSTFBuilder @@ -146,7 +146,7 @@ def __init__(self, input_shape, head_size, num_heads, ff_dim, """ self.tstfbuilder = TSTFBuilder() - super(CompoundModel, self).__init__() + super(DecoderModel, self).__init__() self.timeseriestransdecoder = self._modelstack( input_shape, head_size, num_heads, ff_dim, num_Transformer_blocks, mlp_units, n_classes, @@ -176,18 +176,24 @@ def _modelstack(self, input_shape, head_size, num_heads, ff_dim, A Keras model. """ - x1, x2 = Input(shape=input_shape) - x1 = Dense(n_classes[0], activation="relu")(x1) - x2 = Dense(n_classes[1], activation="relu")(x2) - x = (x1 + x2) - x = GlobalAveragePooling1D(data_format="channels_first")(x) + shape0 = n_classes[0] + shape1 = n_classes[1] + x0 = Input(shape=(shape0,)) + x1 = Input(shape=(shape1,)) + inputs = [x0, x1] + x0 = Dense(n_classes[0], activation="relu")(x0) + x1 = Dense(n_classes[1], activation="relu")(x1) + x = concatenate([x0, x1], axis=-1) + full_dimension = input_shape[0] * input_shape[1] + x = Dense(full_dimension, activation="relu")(x) + x = Reshape((input_shape[0], input_shape[1]))(x) for dim in mlp_units: x = Dense(dim, activation="relu")(x) x = Dropout(mlp_dropout)(x) for _ in range(num_Transformer_blocks): - x = self.tstfbuilder.build_decoderblock( + x = self.tstfbuilder.build_transformerblock( x, head_size, num_heads, @@ -195,7 +201,13 @@ def _modelstack(self, input_shape, head_size, num_heads, ff_dim, dropout ) - return Model(inputs, z) + # final layer with corrected shape + x = Conv1D(filters=input_shape[1], + kernel_size=1, + padding="valid", + activation="linear")(x) + + return Model(inputs, x) def call(self, inputs): """ @@ -207,7 +219,7 @@ def call(self, inputs): Returns: Tensor, resulting output of the TimeSeriesTransformer model. """ - return self.timeseriestransformer(inputs) + return self.timeseriestransdecoder(inputs) def summary(self): """ @@ -219,6 +231,6 @@ def summary(self): Returns: None. """ - self.timeseriestransformer.summary() + self.timeseriestransdecoder.summary() # EOF