Giter VIP home page Giter VIP logo

Comments (4)

philipperemy avatar philipperemy commented on May 25, 2024

Like this: https://keras.io/api/layers/core_layers/masking

import numpy as np
import tensorflow as tf

from tcn import TCN

samples, timesteps, features = 32, 10, 8
inputs = np.random.random([samples, timesteps, features]).astype(np.float32)

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Masking(mask_value=0., input_shape=(timesteps, features)))
model.add(TCN(32))

output = model(inputs)
print(output)

from keras-tcn.

philipperemy avatar philipperemy commented on May 25, 2024

I'm adding more comments here. Might be useful for later. It seems to work correctly because:

inputs[:, :, :] = 1.
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Masking(mask_value=1., input_shape=(timesteps, features)))

The model will output only zeros. If we change it to inputs[:, :, :] = 2., the model will output different values.

Another example:

import numpy as np
import tensorflow as tf

from tcn import TCN

samples, timesteps, features = 32, 10, 8
inputs = np.random.random([samples, timesteps, features]).astype(np.float32)
inputs[:, :-1, :] = 1.

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Masking(mask_value=1., input_shape=(timesteps, features)))
model.add(TCN(16, return_sequences=True))

output = model(inputs)
print(output.shape)
print(np.mean(np.abs(output[:, :-1, :]))) # 0.0 EXPECTED (EQUAL TO 0, due to masking).
print(np.mean(np.abs(output[:, -1:, :]))) # 0.8137888 EXPECTED (DIFFERENT THAN 0).

from keras-tcn.

arvind267 avatar arvind267 commented on May 25, 2024

Thank you so much @philipperemy!

from keras-tcn.

philipperemy avatar philipperemy commented on May 25, 2024

@arvind267 happy I could help!

from keras-tcn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.