Comments (4)
If someone ever wants to look into #33, this question here (#62) could be a starting point for doing something like #33, too, if I understand that correctly. So I'll leave this link here.
from keras-tcn.
@beasteers hey, sorry for the (very) late reply! You can use keract to get the activations of each layer in a Keras model. The only problem here is that we merge all the TCN into one single layer so at the moment it's not possible to get the activations of each sub-layer inside. I'll try to find a way around it.
from keras-tcn.
But at the moment, you can get exactly what you want with the previous version of keras-tcn: 2.8.3.
So consider doing something like:
pip install keras-tcn==2.8.3 tensorflow keract
"""
#Trains a TCN on the IMDB sentiment classification task.
Output after 1 epochs on CPU: ~0.8611
Time per epoch on CPU (Core i7): ~64s.
Based on: https://github.com/keras-team/keras/blob/master/examples/imdb_bidirectional_lstm.py
"""
import numpy as np
from keras import Model, Input
from keras.datasets import imdb
from keras.layers import Dense, Dropout, Embedding
from keras.preprocessing import sequence
import keract
from tcn import TCN
max_features = 20000
# cut texts after this number of words
# (among top max_features most common words)
maxlen = 100
batch_size = 32
print('Loading data...')
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features)
print(len(x_train), 'train sequences')
print(len(x_test), 'test sequences')
print('Pad sequences (samples x time)')
x_train = sequence.pad_sequences(x_train, maxlen=maxlen)
x_test = sequence.pad_sequences(x_test, maxlen=maxlen)
print('x_train shape:', x_train.shape)
print('x_test shape:', x_test.shape)
y_train = np.array(y_train)
y_test = np.array(y_test)
i = Input(shape=(maxlen,))
x = Embedding(max_features, 128)(i)
x = TCN(nb_filters=64,
kernel_size=6,
dilations=[1, 2, 4, 8, 16, 32, 64])(x)
x = Dropout(0.5)(x)
x = Dense(1, activation='sigmoid')(x)
model = Model(inputs=[i], outputs=[x])
model.summary()
# try using different optimizers and different optimizer configs
model.compile('adam', 'binary_crossentropy', metrics=['accuracy'])
activations = keract.get_activations(model, x_train[0:1])
print('Train...')
model.fit(x_train, y_train,
batch_size=batch_size,
epochs=1,
validation_data=[x_test, y_test])
I added activations = keract.get_activations(model, x_train[0:1])
Then you should get something like this:
Let me know if it helps :)
from keras-tcn.
Issue resolved. I think there’s an example with keract in the examples folder
from keras-tcn.
Related Issues (20)
- Target variable prediction With time series: separate train and test set HOT 2
- TCN for Time Series Image Classification HOT 3
- ValueError: Cannot serialize LeakyReLU since it doesn't implement `get_config()`, and also doesn have `__name__` HOT 2
- setup.py requirements on mac os HOT 7
- How do I use a masking layer for TCN? I want to mask certain time steps which are missing. HOT 4
- ValueError: Unknown layer: TCN when trying to load saved model HOT 3
- Dilations and nb_stack relationship HOT 4
- The parameter of the TCN HOT 7
- Masking time steps in order to use TCN for variable length sequences HOT 2
- data shape of tcn layer HOT 1
- help one regression per sequence HOT 1
- Ensuring unique weights when a model uses multiple TCNs HOT 2
- Question: TCN Dilated Convolutions? HOT 3
- How can i use TCN to build seq2seq model? HOT 1
- keras-tcn for R HOT 2
- Visualization of internal structure of TCN block HOT 1
- Low accuracy in keras-tuner based TCN model for audio classification HOT 6
- Saving a loaded model gets warning and then fails to open HOT 1
- exchange_rate.txt HOT 5
- Question: Skip connections HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keras-tcn.