Commit 87036e4e authored by lucas_miranda's avatar lucas_miranda
Browse files

Implemented S2SAE model in models.py

parent 8f59594e
......@@ -12,16 +12,125 @@ import tensorflow as tf
class SEQ_2_SEQ_AE:
pass
def __init__(
self,
input_shape,
CONV_filters,
LSTM_units_1,
LSTM_units_2,
DENSE_2,
DROPOUT_RATE,
ENCODING,
learn_rate
):
self.input_shape = input_shape
self.CONV_filters = CONV_filters
self.LSTM_units_1 = LSTM_units_1
self.LSTM_units_2 = LSTM_units_2
self.DENSE_1 = LSTM_units_2
self.DENSE_2 = DENSE_2
self.DROPOUT_RATE = DROPOUT_RATE
self.ENCODING = ENCODING
self.learn_rate = learn_rate
def build(self):
# Encoder Layers
Model_E0 = tf.keras.layers.Conv1D(
filters=self.CONV_filters,
kernel_size=5,
strides=1,
padding="causal",
activation="relu",
input_shape=self.input_shape[1:],
)
Model_E1 = Bidirectional(
LSTM(
self.LSTM_units_1,
activation="tanh",
return_sequences=True,
kernel_constraint=UnitNorm(axis=0),
)
)
Model_E2 = Bidirectional(
LSTM(
self.LSTM_units_2,
activation="tanh",
return_sequences=False,
kernel_constraint=UnitNorm(axis=0),
)
)
Model_E3 = Dense(self.DENSE_1, activation="relu", kernel_constraint=UnitNorm(axis=0))
Model_E4 = Dense(self.DENSE_2, activation="relu", kernel_constraint=UnitNorm(axis=0))
Model_E5 = Dense(
self.ENCODING,
activation="relu",
kernel_constraint=UnitNorm(axis=1),
activity_regularizer=UncorrelatedFeaturesConstraint(3, weightage=1.0),
)
# Decoder layers
Model_D4 = Bidirectional(
LSTM(
self.LSTM_units_1,
activation="tanh",
return_sequences=True,
kernel_constraint=UnitNorm(axis=1),
)
)
Model_D5 = Bidirectional(
LSTM(
self.LSTM_units_1,
activation="sigmoid",
return_sequences=True,
kernel_constraint=UnitNorm(axis=1),
)
)
# Define and instanciate encoder
encoder = Sequential(name="DLC_encoder")
encoder.add(Model_E0)
encoder.add(Model_E1)
encoder.add(Model_E2)
encoder.add(Model_E3)
encoder.add(Dropout(self.DROPOUT_RATE))
encoder.add(Model_E4)
encoder.add(Model_E5)
# Define and instanciate decoder
decoder = Sequential(name="DLC_Decoder")
decoder.add(
DenseTranspose(
Model_E5, activation="relu", input_shape=(self.ENCODING,), output_dim=64
)
)
decoder.add(DenseTranspose(Model_E4, activation="relu", output_dim=128))
decoder.add(DenseTranspose(Model_E3, activation="relu", output_dim=256))
decoder.add(RepeatVector(self.input_shape[1]))
decoder.add(Model_D4)
decoder.add(Model_D5)
decoder.add(TimeDistributed(Dense(self.input_shape[2])))
model = Sequential([encoder, decoder], name="DLC_Autoencoder")
model.compile(
loss=Huber(reduction="sum", delta=100.0),
optimizer=Adam(
lr=self.learn_rate,
clipvalue=0.5,
),
metrics=["mae"],
)
return model
class SEQ_2_SEQ_VAE:
pass
class SEQ_2_SEQ_MVAE(HyperModel):
class SEQ_2_SEQ_MVAE():
pass
class SEQ_2_SEQ_MMVAE(HyperModel):
class SEQ_2_SEQ_MMVAE():
pass
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment