diff --git a/aeon/classification/deep_learning/_cnn.py b/aeon/classification/deep_learning/_cnn.py index d099fb04fc..3b9a0fa674 100644 --- a/aeon/classification/deep_learning/_cnn.py +++ b/aeon/classification/deep_learning/_cnn.py @@ -42,6 +42,9 @@ class TimeCNNClassifier(BaseDeepClassifier): strides : int or list of int, default = 1 The strides of kernels in the convolution and max pooling layers, if not a list, the same strides are used for all layers. + strides_pooling : int or list of int, default = None + Strides for the pooling layers. If None, defaults to pool_size. + If not a list, the same strides are used for all pooling layers. dilation_rate : int or list of int, default = 1 The dilation rate of the convolution layers, if not a list, the same dilation rate is used all over the network. @@ -125,6 +128,7 @@ def __init__( activation="sigmoid", padding="valid", strides=1, + strides_pooling=None, dilation_rate=1, n_epochs=2000, batch_size=16, @@ -148,6 +152,7 @@ def __init__( self.n_filters = n_filters self.padding = padding self.strides = strides + self.strides_pooling = strides_pooling self.dilation_rate = dilation_rate self.avg_pool_size = avg_pool_size self.activation = activation @@ -182,6 +187,7 @@ def __init__( activation=self.activation, padding=self.padding, strides=self.strides, + strides_pooling=self.strides_pooling, dilation_rate=self.dilation_rate, use_bias=self.use_bias, ) diff --git a/aeon/networks/_cnn.py b/aeon/networks/_cnn.py index c7ce13734c..67fab21b99 100644 --- a/aeon/networks/_cnn.py +++ b/aeon/networks/_cnn.py @@ -32,6 +32,9 @@ class TimeCNNNetwork(BaseDeepLearningNetwork): strides : int or list of int, default = 1 The strides of kernels in the convolution and max pooling layers, if not a list, the same strides are used for all layers. + strides_pooling : int or list of int, default = None + Strides for the pooling layers. If None, defaults to pool_size. + If not a list, the same strides are used for all pooling layers. dilation_rate : int or list of int, default = 1 The dilation rate of the convolution layers, if not a list, the same dilation rate is used all over the network. @@ -65,6 +68,7 @@ def __init__( activation="sigmoid", padding="valid", strides=1, + strides_pooling=None, dilation_rate=1, use_bias=True, ): @@ -75,6 +79,7 @@ def __init__( self.activation = activation self.padding = padding self.strides = strides + self.strides_pooling = strides_pooling self.dilation_rate = dilation_rate self.use_bias = use_bias @@ -131,6 +136,19 @@ def build_network(self, input_shape, **kwargs): else: self._avg_pool_size = [self.avg_pool_size] * self.n_layers + if self.strides_pooling is None: + self._strides_pooling = self._avg_pool_size + elif isinstance(self.strides_pooling, list): + if len(self.strides_pooling) != self.n_layers: + raise ValueError( + f"Number of strides for pooling {len(self.strides_pooling)}" + f" should be the same as number of layers but is" + f" not: {self.n_layers}" + ) + self._strides_pooling = self.strides_pooling + else: + self._strides_pooling = [self.strides_pooling] * self.n_layers + if isinstance(self.activation, list): if len(self.activation) != self.n_layers: raise ValueError( @@ -204,9 +222,10 @@ def build_network(self, input_shape, **kwargs): use_bias=self._use_bias[i], )(x) - conv = tf.keras.layers.AveragePooling1D(pool_size=self._avg_pool_size[i])( - conv - ) + conv = tf.keras.layers.AveragePooling1D( + pool_size=self._avg_pool_size[i], + strides=self._strides_pooling[i], + )(conv) x = conv