带有keras和R的CNN:应用了滑动窗口以在具有几位数字的图像中查找特定的手写数字

我想应用一个滑动窗口来查找具有多个数字(wh_img)的图像中的手写数字。首先,使用经典的MNIST示例创建cnn

#Preparing the Data - using MNIST dataset is included with Kera
library(keras)
mnist <- dataset_mnist()
x_train <- mnist$train$x
y_train <- mnist$train$y
x_test <- mnist$test$x
y_test <- mnist$test$y

# reshape
x_train <- array_reshape(x_train,c(nrow(x_train),784))
x_test <- array_reshape(x_test,c(nrow(x_test),784))
# rescale
x_train <- x_train / 255
x_test <- x_test / 255

y_train <- to_categorical(y_train,10)
y_test <- to_categorical(y_test,10)


#cnn model
model <- keras_model_sequential() 
model %>% 
  layer_dense(units = 256,activation = 'relu',input_shape = c(784)) %>% 
  layer_dropout(rate = 0.4) %>% 
  layer_dense(units = 128,activation = 'relu') %>%
  layer_dropout(rate = 0.3) %>%
  layer_dense(units = 10,activation = 'softmax')

model %>% compile(
  loss = 'categorical_crossentropy',optimizer = optimizer_rmsprop(),metrics = c('accuracy')
)

#Training and Evaluation
history <- model %>% fit(
  x_train,y_train,epochs = 30,batch_size = 128,validation_split = 0.2
)
plot(history)

现在,我必须在y.png图像中应用带有几个手写数字的滑动窗口,以使用经过训练的modelpredict_classes函数仅查找4个数字:

# Open an image with handwrite numbers colections
y = "http://mariakravtsova.us/img/numbers.png"
download.file(y,'y.png',mode = 'wb')
library("png")
wh_img <- readPNG("y.png")
plot.new() 
rasterImage(wh_img,1,1)

带有keras和R的CNN:应用了滑动窗口以在具有几位数字的图像中查找特定的手写数字

# Applied cnn model to wh_img using sliding window  
predictions <-  predict_classes(model,??????)

这在R中可能吗?因为在Python中有很多功能,请选择窗口大小等。有什么想法吗?

shark14146 回答:带有keras和R的CNN:应用了滑动窗口以在具有几位数字的图像中查找特定的手写数字

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2996569.html

大家都在问