-
-
Notifications
You must be signed in to change notification settings - Fork 453
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
The parameter of the TCN #239
Comments
@yanghui-wng here is a detailed version of the weights contained in the TCN model:
|
And here are the TCN blocks (the breakdown by block):
|
To reproduce it you can run this script: import numpy as np
from tensorflow.keras import Input
from tensorflow.keras import Sequential
from tensorflow.keras.callbacks import TensorBoard
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LeakyReLU
from tcn import TCN
input_dim = 7
timesteps = 1
print('Loading data...')
x_train = np.zeros(shape=(100, timesteps, input_dim))
y_train = np.zeros(shape=(100, 1))
batch_size = None
model = Sequential()
input_layer = Input(batch_shape=(batch_size, timesteps, input_dim))
model.add(input_layer)
model.add(TCN(nb_filters=100,
# Integer. The number of filters to use in the convolutional layers. Would be similar to units for LSTM. Can be a list.
kernel_size=3, # Integer. The size of the kernel to use in each convolutional layer.
nb_stacks=1, # The number of stacks of residual blocks to use.
dilations=(1, 2, 4), # List/Tuple. A dilation list. Example is: [1, 2, 4, 8, 16, 32, 64].
padding='causal',
use_skip_connections=False,
dropout_rate=0.1,
return_sequences=False,
activation='relu',
kernel_initializer='he_normal',
use_batch_norm=False,
use_layer_norm=False,
))
model.add(Dense(64))
model.add(LeakyReLU(alpha=0.3))
model.add(Dense(32))
model.add(LeakyReLU(alpha=0.3))
model.add(Dense(16))
model.add(LeakyReLU(alpha=0.3))
model.add(Dense(1))
model.add(LeakyReLU(alpha=0.3))
model.compile(loss='mse', optimizer='adam')
# tensorboard --logdir logs_tcn
# Browse to http://localhost:6006/#graphs&run=train.
# and double click on TCN to expand the inner layers.
# It takes time to write the graph to tensorboard. Wait until the first epoch is completed.
tensorboard = TensorBoard(
log_dir='logs_tcn',
histogram_freq=1,
write_images=True
)
print('Train...')
model.fit(
x_train, y_train,
batch_size=batch_size,
callbacks=[tensorboard],
epochs=10
) Run it and a folder called
And go to http://localhost:6006/. Select GRAPH and you will see it: |
I guess with all those tools, you should be able to have an answer. |
Thank you for your help! Through your explanation, I have known how to calculate the parameters of TCN. |
Good to hear! |
I am studying the code about TCN on github (https://github.com/philipperemy/keras-tcn). The number of parameters of the TCN I calculated is different from the answer of the function "model.summary()". The parameter of TCN layer that calculated by the function "model.summary()" is 153500, but I am not clear about how to calculate this value and I am trying to calculate the value, but the result is 153000.
Code
Output
The text was updated successfully, but these errors were encountered: