Trains a simple deep CNN on the CIFAR10 small images dataset.
Train a simple deep CNN on the CIFAR10 small images dataset.
It gets down to 0.65 test logloss in 25 epochs, and down to 0.55 after 50 epochs, though it is still underfitting at that point.
If doing data augmentation you may try increasing the number of filters in convolutions and in dense layers.
library(keras)# Parameters --------------------------------------------------------------batch_size <-32epochs <-50data_augmentation <-FALSE# Data Preparation --------------------------------------------------------# See ?dataset_cifar10 for more infocifar10 <-dataset_cifar10()
Loaded Tensorflow version 2.9.1
# Feature scale RGB values in test and train inputs x_train <- cifar10$train$x/255x_test <- cifar10$test$x/255y_train <- cifar10$train$yy_test <- cifar10$test$y# Defining Model ----------------------------------------------------------# Initialize sequential modelmodel <-keras_model_sequential()if (data_augmentation) { data_augmentation =keras_model_sequential() %>%layer_random_flip("horizontal") %>%layer_random_rotation(0.2) model <- model %>%data_augmentation()}model <- model %>%# Start with hidden 2D convolutional layer being fed 32x32 pixel imageslayer_conv_2d(filter =16, kernel_size =c(3,3), padding ="same", input_shape =c(32, 32, 3) ) %>%layer_activation_leaky_relu(0.1) %>%# Second hidden layerlayer_conv_2d(filter =32, kernel_size =c(3,3)) %>%layer_activation_leaky_relu(0.1) %>%# Use max poolinglayer_max_pooling_2d(pool_size =c(2,2)) %>%layer_dropout(0.25) %>%# 2 additional hidden 2D convolutional layerslayer_conv_2d(filter =32, kernel_size =c(3,3), padding ="same") %>%layer_activation_leaky_relu(0.1) %>%layer_conv_2d(filter =64, kernel_size =c(3,3)) %>%layer_activation_leaky_relu(0.1) %>%# Use max pooling once morelayer_max_pooling_2d(pool_size =c(2,2)) %>%layer_dropout(0.25) %>%# Flatten max filtered output into feature vector # and feed into dense layerlayer_flatten() %>%layer_dense(256) %>%layer_activation_leaky_relu(0.1) %>%layer_dropout(0.5) %>%# Outputs from dense layer are projected onto 10 unit output layerlayer_dense(10)
Warning in layer_conv_2d(., filter = 64, kernel_size = c(3, 3)): partial
argument match of 'filter' to 'filters'
Warning in layer_conv_2d(., filter = 32, kernel_size = c(3, 3), padding =
"same"): partial argument match of 'filter' to 'filters'
Warning in layer_conv_2d(., filter = 32, kernel_size = c(3, 3)): partial
argument match of 'filter' to 'filters'
Warning in layer_conv_2d(., filter = 16, kernel_size = c(3, 3), padding =
"same", : partial argument match of 'filter' to 'filters'