Skip to content

Commit

Permalink
Working version of decoder added?? I think
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawith committed Oct 24, 2025
1 parent b29467a commit 70c3d54
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -176,26 +176,38 @@ 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,
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):
"""
Expand All @@ -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):
"""
Expand All @@ -219,6 +231,6 @@ def summary(self):
Returns:
None.
"""
self.timeseriestransformer.summary()
self.timeseriestransdecoder.summary()

# EOF

0 comments on commit 70c3d54

Please sign in to comment.