【问题标题】:Keras Model doesn't accept input_layerKeras 模型不接受 input_layer
【发布时间】:2017-06-28 22:13:49
【问题描述】:

我是深度学习的新手,正在尝试使用 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

谁能帮我弄清楚如何为我的模型设置输入层?

【问题讨论】:

    标签: r python-2.7 deep-learning keras


    【解决方案1】:

    使用 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')
    

    在使用函数式 API 时,您可以使用 layer_input 函数。查看更多here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 2018-12-13
      • 2018-02-25
      • 2016-07-18
      • 2021-10-21
      • 1970-01-01
      相关资源
      最近更新 更多