Skip to content

Commit a3477f6

Browse files
committed
Accept NA in shape argumennts
1 parent ca11331 commit a3477f6

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

NEWS.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
- `layer_stacked_rnn_cells()`
1414
To learn more, including how to make a custom cell layer, see the new vignette:
1515
"Working with RNNs".
16-
16+
1717
- New dataset loader `text_dataset_from_directory()`.
1818

1919
- New layers:
2020
- `layer_additive_attention()`
2121
- `layer_conv_lstm_1d()`
2222
- `layer_conv_lstm_3d()`
2323

24-
- `layer_cudnn_gru()` and `layer_cudnn_lstm()` are deprecated.
24+
- `layer_cudnn_gru()` and `layer_cudnn_lstm()` are deprecated.
2525
`layer_gru()` and `layer_lstm()` will automatically use CuDNN if it is available.
2626

27-
- `layer_lstm()` and `layer_gru()`:
28-
default value for `recurrent_activation` changed
27+
- `layer_lstm()` and `layer_gru()`:
28+
default value for `recurrent_activation` changed
2929
from `"hard_sigmoid"` to `"sigmoid"`.
3030

3131
- `layer_gru()`: default value `reset_after` changed from `FALSE` to `TRUE`
@@ -35,7 +35,7 @@
3535
- New applications:
3636
- MobileNet V3: `application_mobilenet_v3_large()`, `application_mobilenet_v3_small()`
3737
- ResNet: `application_resnet101()`, `application_resnet152()`, `resnet_preprocess_input()`
38-
- ResNet V2:`application_resnet50_v2()`, `application_resnet101_v2()`,
38+
- ResNet V2:`application_resnet50_v2()`, `application_resnet101_v2()`,
3939
`application_resnet152_v2()` and `resnet_v2_preprocess_input()`
4040
- EfficientNet: `application_efficientnet_b{0,1,2,3,4,5,6,7}()`
4141

@@ -51,19 +51,23 @@
5151
`keepdims` argument with default value `FALSE`.
5252

5353
- Signatures for layer functions are in the process of being simplified.
54-
Standard layer arguments are moving to `...` where appropriate
54+
Standard layer arguments are moving to `...` where appropriate
5555
(and will need to be provided as named arguments).
56-
Standard layer arguments include:
57-
`input_shape`, `batch_input_shape`, `batch_size`, `dtype`,
56+
Standard layer arguments include:
57+
`input_shape`, `batch_input_shape`, `batch_size`, `dtype`,
5858
`name`, `trainable`, `weights`.
59-
Layers updated:
60-
`layer_global_{max,average}_pooling_{1,2,3}d()`,
59+
Layers updated:
60+
`layer_global_{max,average}_pooling_{1,2,3}d()`,
6161
`time_distributed()`, `bidirectional()`,
6262
`layer_gru()`, `layer_lstm()`, `layer_simple_rnn()`
6363

6464
- All the backend function with a shape argument `k_*(shape =)` that now accept a
6565
a mix of integer tensors and R numerics in the supplied list.
6666

67+
- All layer functions now accept `NA` as a synonym for `NULL` in arguments
68+
that specify shape as a vector of dimension values,
69+
e.g., `input_shape`, `batch_input_shape`.
70+
6771
- `k_random_uniform()` now automatically casts `minval` and `maxval` to the output dtype.
6872

6973
# keras 2.6.1

tests/testthat/test-model.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,16 @@ test_succeeds("can call model with R objects", {
126126
})
127127

128128

129-
test_succeeds("layer_input() ", {
129+
test_succeeds("layer_input()", {
130130
# can take dtype = Dtype
131131
layer_input(shape = 1, dtype = tf$string)
132132

133-
expect_identical(as.list(layer_input(shape = c(NA))$shape),
134-
list(NULL, NULL))
133+
# can take shape=NA correctly
134+
shp <- layer_input(shape = c(NA))$shape
135+
if(inherits(shp, "tensorflow.python.framework.tensor_shape.TensorShape"))
136+
shp <- shp$as_list()
137+
138+
expect_identical(shp, list(NULL, NULL))
135139
})
136140

137141

tools/test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ export TF_CPP_MIN_LOG_LEVEL=2
1010
# 3 = INFO, WARNING, and ERROR messages are not printed
1111

1212

13-
for i in 2.{4..7} nightly
13+
for i in 2.{6..7}
14+
# for i in 2.{4..7} nightly
1415
# for i in 2.{1..3}
1516
do
1617
TMPDIR="/tmp/r-keras-tests/tf-$i/"
1718
mkdir -p $TMPDIR
1819
rsync -a --delete . $TMPDIR
1920
gnome-terminal --title="keras test: tf $i" --working-directory=$TMPDIR -- \
20-
Rscript -e "{options(error=recover); cat('\n\n\n'); reticulate::use_miniconda('tf-$i-cpu', required=TRUE); devtools::test(); cat('Done!')}"
21+
Rscript -e "{options(error=recover); cat('\n\n\n'); Sys.unsetenv('RETICULATE_PYTHON'); reticulate::use_miniconda('tf-$i-cpu', required=TRUE); devtools::test(); cat('Done!')}"
2122
# Rscript -e "{cat('\n\n\n'); }"
2223
# ; scan('stdin', nlines=1)
2324
done

0 commit comments

Comments
 (0)