Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time series classification #5

Open
lys15163238308 opened this issue Jul 27, 2024 · 1 comment
Open

Time series classification #5

lys15163238308 opened this issue Jul 27, 2024 · 1 comment

Comments

@lys15163238308
Copy link

Hello, could you please update the code on time series classification, as well as the example Thank you !

@claCase
Copy link
Owner

claCase commented Jul 27, 2024

Hi @lys15163238308 ,

I've updated the README with a classification example. The main idea is to squash the entire hidden state output sequence to a fixed size vector with the sequence statistics (mean, max, min) for each output feature dimension. This is achieved by global mean, max and min pooling. Then a final fully-connected layer is used to classify the sequence.

ki = tf.keras.Input(shape=(None, 1))
scan = models.ScanRNNAttentionModel([10, 10], [10, 10])
avg_pool = tf.keras.layers.GlobalAveragePooling1D()
max_pool = tf.keras.layers.GlobalMaxPooling1D()
min_pool = tf.keras.layers.Lambda(lambda x: tf.reduce_min(x, -2))
conc = tf.keras.layers.Concatenate()
dense = tf.keras.layers.Dense(1, "sigmoid")

h = scan(ki)
avgp = avg_pool(h)
maxp = max_pool(h)
minp = min_pool(h)
mix = conc([avgp, maxp, minp])
o = dense(mix)

classification_model = tf.keras.Model(ki, o)
classification_model.compile("adam", "bce")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants