Keras Model不接受input_layer

时间:2017-06-28 22:13:49

标签: r python-2.7 deep-learning keras

我是Deep Learning的新手,我正在尝试使用Keras在R中构建模型。我有20,000个32x32x3图像存储在阵列中进行模型训练。当我跑:

model = keras_model_sequential()
model %>% layer_input(shape = c(32,32,3))

我收到以下错误:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
TypeError: int() argument must be a string or a number, not 'Sequential'

Detailed traceback: 
File "/home/abhijit331/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/contrib/keras/python/keras/engine/topology.py", line 1380, in Input
input_tensor=tensor)
File "/home/abhijit331/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/contrib/keras/python/keras/engine/topology.py", line 1287, in __init__
name=self.name)
File "/home/abhijit331/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/contrib/keras/python/keras/backend.py", line 545, in placeholder
x = array_ops.placeholder(dtype, shape=shape, name=name)
File "/home/abhijit331/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1499, in placeholder
shape = tensor_shape.as_shape(shape)
File "/home/abhijit331/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.py", line 80

任何人都可以帮我弄清楚如何为我的模型设置输入图层吗?

1 个答案:

答案 0 :(得分:3)

使用Sequential API时,您不能使用layer_input功能。 您的第一个图层需要有一个input_shape参数,该参数将充当layer_input。例如:

model %>% 
  layer_dense(units = 32, input_shape = c(784)) %>%
  layer_activation('relu') %>% 
  layer_dense(units = 10) %>% 
  layer_activation('softmax')

使用Functional API时,您可以使用layer_input功能。查看更多here