The fit_tuner
function in KerasTuneR, when used in Rstudio, only prints its progress for the first trial. The simplified code below
library(tidyverse)
library(tensorflow)
library(keras)
library(kerastuneR)
library(ggplot2)
x_data <- matrix(data = runif(500,0,1),nrow = 50,ncol = 5)
y_data <- ifelse(runif(50,0,1) > 0.6, 1L,0L) %>% as.matrix()
x_data2 <- matrix(data = runif(500,0,1),nrow = 50,ncol = 5)
y_data2 <- ifelse(runif(50,0,1) > 0.6, 1L,0L) %>% as.matrix()
hp = HyperParameters()
hp$Int('num_layers', 5L, 20L, 2L)
hp$Int('units', 60L, 160L, 10L)
build_model <- function(hp) {
model <- keras_model_sequential() %>%
layer_dense(units = hp$get('units'), activation = 'relu', input_shape = 5)
for (i in 1:hp$get('num_layers')) {
model %>%
layer_dense(units = hp$get('units'), activation = 'relu')
}
model %>% layer_dense(units = 1)
model %>% compile(optimizer = 'adam',
loss = 'binary_crossentropy',
metrics = c('accuracy'))
return(model)
}
tuner = RandomSearch(
hypermodel = build_model,
max_trials = 3,
executions_per_trial = 2,
hyperparameters = hp,
tune_new_entries = T,
objective = 'val_accuracy',
#directory = 'C:/Users/Penelope/Desktop/NN_models/',
#project_name = 'BigFoot2',
overwrite = TRUE
)
tuner %>% fit_tuner(x = x_data, y = y_data,
epochs = 2,
validation_data = list(x_data2, y_data2))
print("Completed")
Should print the output for every trial, but instead it prints only this:
Search: Running Trial #1
Value |Best Value So Far |Hyperparameter
13 |? |num_layers
110 |? |units
Epoch 1/2
2/2 [==============================] - 1s 220ms/step - loss: 4.5302 - accuracy: 0.6000 - val_loss: 1.5124 - val_accuracy: 0.6000
Epoch 2/2
2/2 [==============================] - 0s 26ms/step - loss: 1.4636 - accuracy: 0.6000 - val_loss: 1.1391 - val_accuracy: 0.6000
Epoch 1/2
2/2 [==============================] - 1s 166ms/step - loss: 2.3739 - accuracy: 0.6000 - val_loss: 1.3020 - val_accuracy: 0.6000
Epoch 2/2
2/2 [==============================] - 0s 21ms/step - loss: 1.2651 - accuracy: 0.6000 - val_loss: 0.9689 - val_accuracy: 0.6000
Interestingly, it never prints "Completed", even though that's the final line of my code.
If I run this directly in R (Rx64 4.1.2), it does print all the output (just all as one giant dump, rather than line by line).
Is this a known issue and how can I fix it? Thanks in advance.