如何在R中使用CNN提高图像分类的准确性

时间:2018-11-10 11:44:24

标签: r tensorflow conv-neural-network

我是图像分类的新手。 我正在使用CNN对3个产品的3个图像进行分类。 下面是我的代码-

model <- keras_model_sequential()

model %>%

     layer_conv_2d(filters = 64, 
                   kernel_size = c(3,3),
                   activation = 'relu',
                   input_shape = c(100,100,3)) %>% 

   layer_conv_2d(filters = 32,
                   kernel_size = c(3,3),
                   activation = 'relu') %>%
layer_max_pooling_2d(pool_size = c(2,2)) %>%

     layer_dropout(rate = 0.25) %>%

     layer_conv_2d(filters = 64,
                   kernel_size = c(3,3),
                   activation = 'relu') %>%

     layer_conv_2d(filters = 64,
                   kernel_size = c(3,3),
                   activation = 'relu') %>%
     layer_max_pooling_2d(pool_size = c(2,2)) %>%
     layer_dropout(rate = 0.25) %>%
      layer_flatten() %>%
     layer_dense(units = 256, activation = 'relu') %>%
     layer_dropout(rate=0.25) %>%
     layer_dense(units = 3, activation = 'softmax') %>%

     compile(loss = 'categorical_crossentropy',
             optimizer = optimizer_sgd(lr = 0.01,
                                       decay = 1e-6,
                                       momentum = 0.9,
                                       nesterov = T),
             metrics = c('accuracy'))
# Fit model

历史记录<-模型%>%

     fit(train,
         trainLabels,
         epochs = 60,
         batch_size =  32,
         validation_split = 0.2,
         validation_data = list(test, testLabels))

我从中得到的准确度是0.333 我想提高这种准确性。我找不到任何说明如何确定适当的内核大小或适当的过滤器数量的教程。 有人可以向我解释吗? 如果您需要其他详细信息,请告诉我。

预先感谢

0 个答案:

没有答案