Skip to content

Commit

Permalink
Merge pull request #35 from philipperemy/issue_34
Browse files Browse the repository at this point in the history
Small updates
  • Loading branch information
Philippe Rémy authored Jan 9, 2019
2 parents bcc210a + a86b5b3 commit 4f7ca60
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ model.fit(x, y) # Keras model.

### Arguments

`tcn.TCN(nb_filters=64, kernel_size=2, nb_stacks=1, dilations=None, activation='norm_relu', padding='causal', use_skip_connections=True, dropout_rate=0.0, return_sequences=True, name='tcn')`
`tcn.TCN(nb_filters=64, kernel_size=2, nb_stacks=1, dilations=[1, 2, 4, 8, 16, 32], activation='norm_relu', padding='causal', use_skip_connections=True, dropout_rate=0.0, return_sequences=True, name='tcn')`

- `nb_filters`: Integer. The number of filters to use in the convolutional layers.
- `kernel_size`: Integer. The size of the kernel to use in each convolutional layer.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='keras-tcn',
version='2.3.4',
version='2.3.5',
description='Keras TCN',
author='Philippe Remy',
license='MIT',
Expand Down
18 changes: 7 additions & 11 deletions tcn/tcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def wave_net_activation(x):


def residual_block(x, s, i, activation, nb_filters, kernel_size, padding, dropout_rate=0, name=''):
# type: (Layer, int, int, str, int, int, float, str) -> Tuple[Layer, Layer]
# type: (Layer, int, int, str, int, int, str, float, str) -> Tuple[Layer, Layer]
"""Defines the residual block for the WaveNet TCN
Args:
Expand All @@ -67,7 +67,7 @@ def residual_block(x, s, i, activation, nb_filters, kernel_size, padding, dropou
original_x = x
conv = Conv1D(filters=nb_filters, kernel_size=kernel_size,
dilation_rate=i, padding=padding,
name=name + '_dilated_conv_%d_tanh_s%d' % (i, s))(x)
name=name + '_d_%s_conv_%d_tanh_s%d' % (padding, i, s))(x)
if activation == 'norm_relu':
x = Activation('relu')(conv)
x = Lambda(channel_normalization)(x)
Expand Down Expand Up @@ -100,8 +100,10 @@ def is_power_of_two(num):
class TCN:
"""Creates a TCN layer.
Input shape:
A tensor of shape (batch_size, timesteps, input_dim).
Args:
input_layer: A tensor of shape (batch_size, timesteps, input_dim).
nb_filters: The number of filters to use in the convolutional layers.
kernel_size: The size of the kernel to use in each convolutional layer.
dilations: The list of the dilations. Example is: [1, 2, 4, 8, 16, 32, 64].
Expand All @@ -121,7 +123,7 @@ def __init__(self,
nb_filters=64,
kernel_size=2,
nb_stacks=1,
dilations=None,
dilations=[1, 2, 4, 8, 16, 32],
activation='norm_relu',
padding='causal',
use_skip_connections=True,
Expand All @@ -139,12 +141,8 @@ def __init__(self,
self.nb_filters = nb_filters
self.padding = padding

# backwards incompatibility warning.
# o = tcn.TCN(i, return_sequences=False) =>
# o = tcn.TCN(return_sequences=False)(i)

if padding != 'causal' and padding != 'same':
raise ValueError("Only 'causal' or 'same' paddings are compatible for this layer.")
raise ValueError("Only 'causal' or 'same' padding are compatible for this layer.")

if not isinstance(nb_filters, int):
print('An interface change occurred after the version 2.1.2.')
Expand All @@ -154,8 +152,6 @@ def __init__(self,
raise Exception()

def __call__(self, inputs):
if self.dilations is None:
self.dilations = [1, 2, 4, 8, 16, 32]
x = inputs
x = Convolution1D(self.nb_filters, 1, padding=self.padding, name=self.name + '_initial_conv')(x)
skip_connections = []
Expand Down

0 comments on commit 4f7ca60

Please sign in to comment.