张量形状对keras模型的输入形状有影响吗?R-规划 库(png) 库(颜色空间) 文件

张量形状对keras模型的输入形状有影响吗?R-规划 库(png) 库(颜色空间) 文件,r,tensorflow,neural-network,keras,R,Tensorflow,Neural Network,Keras,对于卷积网络,这很重要,因为根据过滤器/池层(max/avg)的数量和尺寸,您需要决定输入形状。对于密集网络,理论上这并不重要。取决于网络。对于密集连接的网络,形状通常无关紧要。对于卷积网络,它绝对会。这个问题可能更适合stats.stackexchange.com。 library(png) library(colorspace) files <- list.files(pattern = ".png$", recursive = TRUE) filePathFunction <

对于卷积网络,这很重要,因为根据过滤器/池层(max/avg)的数量和尺寸,您需要决定输入形状。对于密集网络,理论上这并不重要。

取决于网络。对于密集连接的网络,形状通常无关紧要。对于卷积网络,它绝对会。这个问题可能更适合stats.stackexchange.com。
library(png)
library(colorspace)

files <- list.files(pattern = ".png$", recursive = TRUE)
filePathFunction <- function(x){
  a <- matrix(nrow=length(x))
  for(i in 1:length(x)){
    conc <- c("~/E-books/Coding/Machine Learning with R/Neural Networks/four-shapes",x[i])
    a[i] <- paste(conc, collapse="/")
  }
  return(a)
}


filePaths <- filePathFunction(files)
image(readPNG(filePaths[1]), useRaster=TRUE, axes=FALSE)

set.seed(101)
ind <- sample(nrow(filePaths),round(0.75*nrow(filePaths)),replace=F)
train <- filePaths[ind,]
test <- filePaths[-ind,]
library(keras)
mnist <- dataset_mnist()
train_images <- mnist$train$x
train_images <- array_reshape(train_images, c(60000, 28 * 28))
train_images <- train_images / 255
test_images <- mnist$test$x
test_images <- array_reshape(test_images, c(10000, 28 * 28))
test_images <- test_images / 255

network <- keras_model_sequential() %>%
layer_dense(units = 512, activation = "relu", input_shape = c(28*28)) %>%
layer_dense(units = 10, activation = "softmax")