Skip to content

Commit dab4323

Browse files
authored
Merge pull request #1032 from dfalbel/bugfix/fit_with_validation_data
Bugfix/fit with validation data
2 parents 74fb570 + 8809c21 commit dab4323

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

R/model.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,14 @@ fit.keras.engine.training.Model <-
439439
dataset <- resolve_tensorflow_dataset(validation_data)
440440
if (!is.null(dataset))
441441
args$validation_data <- dataset
442-
else
442+
else {
443443
args$validation_data <- keras_array(validation_data)
444+
445+
if (tensorflow::tf_version() >="2.2")
446+
args$validation_data <- do.call(reticulate::tuple, args$validation_data)
447+
448+
}
449+
444450
}
445451

446452
# resolve x and y (check for TF dataset)

inst/python/kerastools/progbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def apply_patch():
1616
# save existing version of update for delegation
1717
update = Progbar.update
1818

19-
def update_with_patch(self, current, values=None, force=False):
19+
def update_with_patch(self, current, values=None, force=False, finalize=None):
2020
# force dynamic display
2121
self._dynamic_display = True
2222
# delegate

tests/testthat/test-model.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ test_succeeds("can call a model with additional arguments", {
116116

117117
})
118118

119+
test_succeeds("pass validation_data to model fit", {
120+
121+
model <- keras_model_sequential() %>%
122+
layer_dense(units =1, input_shape = 2)
123+
124+
model %>% compile(loss = "mse", optimizer = "sgd")
125+
126+
model %>%
127+
fit(
128+
matrix(runif(100), ncol = 2), y = runif(50),
129+
batch_size = 10,
130+
validation_data = list(matrix(runif(100), ncol = 2), runif(50))
131+
)
132+
133+
})
134+
119135

120136

121137

0 commit comments

Comments
 (0)