我正在尝试使用layer_zero_padding_2d向MNIST数据集中的每个图像添加2行/列。我希望图像的尺寸为32X32,而不是28X28。我知道我可以用其他方法做到这一点,但是我试图理解为什么我的模型给我错误:“列表索引超出范围”
这是我的代码:
library(keras)
mnist <- dataset_mnist()
c(c(train_images, train_labels), c(test_images, test_labels)) %<-% mnist
train_images <- array_reshape(train_images, c(60000, 28, 28, 1))
train_images <- train_images / 255
test_images <- array_reshape(test_images, c(10000, 28, 28, 1))
test_images <- test_images / 255
train_labels <- to_categorical(train_labels)
test_labels <- to_categorical(test_labels)
mnist.LeNet5 <- keras_model_sequential() %>%
layer_zero_padding_2d(padding = 2)
mnist.LeNet5 %>% compile(
optimizer = optimizer_rmsprop(),
loss = "categorical_crossentropy",
metrics = c("accuracy")
)
history <- mnist.LeNet5 %>% fit(x = train_images)