Skip to content

Commit 94ea1a2

Browse files
Merge branch 'keras-team:master' into nnx
2 parents e9dbca4 + 92bfff0 commit 94ea1a2

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

keras/src/layers/convolutional/base_conv_transpose.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def __init__(
112112
output_padding,
113113
rank,
114114
"output_padding",
115+
allow_zero=True,
115116
)
116117
self.data_format = standardize_data_format(data_format)
117118
self.activation = activations.get(activation)

keras/src/layers/convolutional/conv1d_transpose.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,22 @@ class Conv1DTranspose(BaseConvTranspose):
2929
`"valid"` means no padding. `"same"` results in padding evenly to
3030
the left/right or up/down of the input such that output has the same
3131
height/width dimension as the input.
32+
output_padding: An integer tuple/list of 1 integer specifying the
33+
amount of padding along the time dimension of the output tensor.
34+
The amount of output padding must be lower than the stride.
35+
If set to `None` (default), the output shape is inferred.
3236
data_format: string, either `"channels_last"` or `"channels_first"`.
3337
The ordering of the dimensions in the inputs. `"channels_last"`
3438
corresponds to inputs with shape `(batch, steps, features)`
3539
while `"channels_first"` corresponds to inputs with shape
3640
`(batch, features, steps)`. It defaults to the `image_data_format`
3741
value found in your Keras config file at `~/.keras/keras.json`.
3842
If you never set it, then it will be `"channels_last"`.
39-
dilation_rate: int or tuple/list of 1 integers, specifying the dilation
40-
rate to use for dilated transposed convolution.
43+
dilation_rate: An integer tuple/list of 1 integer, specifying
44+
the dilation rate to use for dilated convolution.
45+
Currently, specifying a `dilation_rate` value != 1 is
46+
incompatible with specifying a stride value != 1.
47+
Also dilation rate larger than 1 is not currently supported.
4148
activation: Activation function. If `None`, no activation is applied.
4249
use_bias: bool, if `True`, bias will be added to the output.
4350
kernel_initializer: Initializer for the convolution kernel. If `None`,
@@ -97,6 +104,7 @@ def __init__(
97104
kernel_size,
98105
strides=1,
99106
padding="valid",
107+
output_padding=None,
100108
data_format=None,
101109
dilation_rate=1,
102110
activation=None,
@@ -116,6 +124,7 @@ def __init__(
116124
kernel_size=kernel_size,
117125
strides=strides,
118126
padding=padding,
127+
output_padding=output_padding,
119128
data_format=data_format,
120129
dilation_rate=dilation_rate,
121130
activation=activation,

keras/src/layers/convolutional/conv2d_transpose.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ class Conv2DTranspose(BaseConvTranspose):
2929
`"valid"` means no padding. `"same"` results in padding evenly to
3030
the left/right or up/down of the input. When `padding="same"` and
3131
`strides=1`, the output has the same size as the input.
32+
output_padding: An integer or tuple/list of 2 integers,
33+
specifying the amount of padding along the height and width
34+
of the output tensor.
35+
Can be a single integer to specify the same value for all
36+
spatial dimensions.
37+
The amount of output padding along a given dimension must be
38+
lower than the stride along that same dimension.
39+
If set to `None` (default), the output shape is inferred.
3240
data_format: string, either `"channels_last"` or `"channels_first"`.
3341
The ordering of the dimensions in the inputs. `"channels_last"`
3442
corresponds to inputs with shape
@@ -38,8 +46,13 @@ class Conv2DTranspose(BaseConvTranspose):
3846
`image_data_format` value found in your Keras config file at
3947
`~/.keras/keras.json`. If you never set it, then it will be
4048
`"channels_last"`.
41-
dilation_rate: int or tuple/list of 1 integers, specifying the dilation
42-
rate to use for dilated transposed convolution.
49+
dilation_rate: An integer or tuple/list of 2 integers,
50+
specifying the dilation rate for
51+
all spatial dimensions for dilated convolution.
52+
Specifying different dilation rates
53+
for different dimensions is not supported.
54+
Currently, specifying any `dilation_rate` value != 1 is
55+
incompatible with specifying any stride value != 1.
4356
activation: Activation function. If `None`, no activation is applied.
4457
use_bias: bool, if `True`, bias will be added to the output.
4558
kernel_initializer: Initializer for the convolution kernel. If `None`,
@@ -99,6 +112,7 @@ def __init__(
99112
kernel_size,
100113
strides=(1, 1),
101114
padding="valid",
115+
output_padding=None,
102116
data_format=None,
103117
dilation_rate=(1, 1),
104118
activation=None,
@@ -118,6 +132,7 @@ def __init__(
118132
kernel_size=kernel_size,
119133
strides=strides,
120134
padding=padding,
135+
output_padding=output_padding,
121136
data_format=data_format,
122137
dilation_rate=dilation_rate,
123138
activation=activation,

keras/src/layers/convolutional/conv3d_transpose.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ class Conv3DTranspose(BaseConvTranspose):
2929
`"valid"` means no padding. `"same"` results in padding evenly to
3030
the left/right or up/down of the input. When `padding="same"` and
3131
`strides=1`, the output has the same size as the input.
32+
output_padding: An integer or tuple/list of 3 integers,
33+
specifying the amount of padding along the depth, height, and
34+
width.
35+
Can be a single integer to specify the same value for all
36+
spatial dimensions.
37+
The amount of output padding along a given dimension must be
38+
lower than the stride along that same dimension.
39+
If set to `None` (default), the output shape is inferred.
3240
data_format: string, either `"channels_last"` or `"channels_first"`.
3341
The ordering of the dimensions in the inputs. `"channels_last"`
3442
corresponds to inputs with shape
@@ -38,8 +46,12 @@ class Conv3DTranspose(BaseConvTranspose):
3846
It defaults to the `image_data_format` value found in your Keras
3947
config file at `~/.keras/keras.json`. If you never set it, then it
4048
will be `"channels_last"`.
41-
dilation_rate: int or tuple/list of 1 integers, specifying the dilation
42-
rate to use for dilated transposed convolution.
49+
dilation_rate: an integer or tuple/list of 3 integers, specifying
50+
the dilation rate to use for dilated convolution.
51+
Can be a single integer to specify the same value for
52+
all spatial dimensions.
53+
Currently, specifying any `dilation_rate` value != 1 is
54+
incompatible with specifying any stride value != 1.
4355
activation: Activation function. If `None`, no activation is applied.
4456
use_bias: bool, if `True`, bias will be added to the output.
4557
kernel_initializer: Initializer for the convolution kernel. If `None`,
@@ -105,6 +117,7 @@ def __init__(
105117
strides=(1, 1, 1),
106118
padding="valid",
107119
data_format=None,
120+
output_padding=None,
108121
dilation_rate=(1, 1, 1),
109122
activation=None,
110123
use_bias=True,
@@ -123,6 +136,7 @@ def __init__(
123136
kernel_size=kernel_size,
124137
strides=strides,
125138
padding=padding,
139+
output_padding=output_padding,
126140
data_format=data_format,
127141
dilation_rate=dilation_rate,
128142
activation=activation,

keras/src/wrappers/sklearn_wrapper.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ class SKLearnClassifier(ClassifierMixin, SKLBase):
235235
scikit-learn model.
236236
237237
``` python
238-
from keras.src.layers import Dense, Input, Model
238+
from keras.layers import Dense, Input
239+
from keras.models import Model
239240
240241
def dynamic_model(X, y, loss, layers=[10]):
241242
# Creates a basic MLP model dynamically choosing the input and
@@ -248,7 +249,7 @@ def dynamic_model(X, y, loss, layers=[10]):
248249
hidden = Dense(layer_size, activation="relu")(hidden)
249250
250251
n_outputs = y.shape[1] if len(y.shape) > 1 else 1
251-
out = [Dense(n_outputs, activation="softmax")(hidden)]
252+
out = Dense(n_outputs, activation="softmax")(hidden)
252253
model = Model(inp, out)
253254
model.compile(loss=loss, optimizer="rmsprop")
254255
@@ -262,7 +263,7 @@ def dynamic_model(X, y, loss, layers=[10]):
262263
from sklearn.datasets import make_classification
263264
from keras.wrappers import SKLearnClassifier
264265
265-
X, y = make_classification(n_samples=1000, n_features=10, n_classes=3)
266+
X, y = make_classification(n_samples=1000, n_features=10)
266267
est = SKLearnClassifier(
267268
model=dynamic_model,
268269
model_kwargs={
@@ -346,7 +347,8 @@ class SKLearnRegressor(RegressorMixin, SKLBase):
346347
scikit-learn model.
347348
348349
``` python
349-
from keras.src.layers import Dense, Input, Model
350+
from keras.layers import Dense, Input
351+
from keras.models import Model
350352
351353
def dynamic_model(X, y, loss, layers=[10]):
352354
# Creates a basic MLP model dynamically choosing the input and
@@ -359,7 +361,7 @@ def dynamic_model(X, y, loss, layers=[10]):
359361
hidden = Dense(layer_size, activation="relu")(hidden)
360362
361363
n_outputs = y.shape[1] if len(y.shape) > 1 else 1
362-
out = [Dense(n_outputs, activation="softmax")(hidden)]
364+
out = Dense(n_outputs)(hidden)
363365
model = Model(inp, out)
364366
model.compile(loss=loss, optimizer="rmsprop")
365367

0 commit comments

Comments
 (0)