fit_k_ontram_augmented_data | R Documentation |
k_ontram
or k_ontram_ci
model with augmented images as inputFunction for estimating a k_ontram
or k_ontram_ci
model with augmented images as input
fit_k_ontram_augmented_data(
m,
im_train,
im_val = NULL,
x_train = NULL,
x_val = NULL,
y_train,
y_val = NULL,
generator,
epochs = 10,
mim_as_mbl = FALSE,
bs = 32,
history = TRUE,
save_best_only = TRUE,
patience = 1,
filepath = NULL
)
mnist <- dataset_mnist()
c(c(x_train, y_train), c(x_val, y_val)) %<-% mnist
y_train <- to_categorical(y_train)
y_val <- to_categorical(y_val)
x_train <- array_reshape(x_train, c(60000, 28, 28, 1))
x_val <- array_reshape(x_val, c(10000, 28, 28, 1))
x_train <- x_train / 255
x_val <- x_val / 255
nim_train <- 100
nim_val <- 50
x_train <- x_train[1:nim_train, , , , drop = FALSE]
y_train <- y_train[1:nim_train, , drop = FALSE]
x_val <- x_val[1:nim_val, , , , drop = FALSE]
y_val <- y_val[1:nim_val, , drop = FALSE]
mbl <- k_mod_baseline(ncol(y_train))
mim <- keras_model_sequential() %>%
layer_conv_2d(filters = 32, kernel_size = c(3, 3), activation = "relu",
input_shape = c(28, 28, 1)) %>%
layer_max_pooling_2d(pool_size = c(2, 2)) %>%
layer_conv_2d(filters = 64, kernel_size = c(3, 3), activation = "relu") %>%
layer_max_pooling_2d(pool_size = c(2, 2)) %>%
layer_flatten() %>%
layer_dense(units = 32, activation = "relu") %>%
layer_dense(units = 1L)
m <- k_ontram(mbl, mim)
compile(m, optimizer = optimizer_adam(learning_rate = 10^-4), loss = k_ontram_loss(ncol(y_train)))
datagen <- image_data_generator(
rotation_range = 20,
width_shift_range = 0.2,
height_shift_range = 0.2,
shear_range = 0.15,
zoom_range = 0.15,
fill_mode = "nearest"
)
f <- fit_k_ontram_augmented_data(m = m, im_train = x_train, im_val = x_val, y_train = y_train, y_val = y_val,
generator = datagen, epochs = 10, mim_as_mbl = FALSE, bs = 32,
history = TRUE, save_best_only = TRUE)
f$hist
f$best_epoch
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.