问题描述
可以将可变长度(即input_dim=None
)应用于简单的神经网络吗?具体来说,是Keras顺序模型.尝试采用相同的概念时,我一直遇到错误.我已经看过似乎支持此功能的文档:
Can a variable length, i.e. input_dim=None
, be applied to a simple neural network? Specifically, the Keras Sequential model. I've been running into errors when trying to employ the same concept. I've already seen the documentation that seems to support this functionality:
https://keras.io/getting-started/functional-api-指南/
但是当我执行以下操作时...
But when I do the following...
model = Sequential()
model.add(Dense(num_feat, input_dim = None, kernel_initializer = 'normal', activation='relu'))
model.add(Dense(num_feat, kernel_initializer = 'normal', activation = 'relu'))
model.add(Dropout(.2))
model.add(Dense(num_feat, kernel_initializer = 'normal', activation = 'relu'))
model.add(Dropout(.2))
model.add(Dense(num_feat, kernel_initializer = 'normal', activation = 'relu'))
model.add(Dropout(.2))
model.add(Dense(ouput.shape[1], kernel_initializer = 'normal', activation = 'linear'))
...我收到此错误:
...I get this error:
ValueError: ('Only Theano variables and integers are allowed in a size-tuple.', (None, 63), None)
任何帮助,想法或澄清将不胜感激!
Any help, ideas, or clarification would be greatly appreciated!!
推荐答案
不,您不能. (而且您也不能使用功能性API)
No, you can't. (And you can't with the functional API either)
权重矩阵的大小固定,此大小取决于输入的暗淡程度.
The weight matrix has a fixed size and this size depends on the input dim.
可能的变量尺寸为:
- 卷积:空间尺寸,但不包括通道/过滤器
- 一维:
input_shape=(None,channels)
- 2D:
input_shape=(None,None,channels)
- 3D:
input_shape=(None,None,None,channels)
- In convolution: the spatial dimensions, but not the channels/filters
- 1D:
input_shape=(None,channels)
- 2D:
input_shape=(None,None,channels)
- 3D:
input_shape=(None,None,None,channels)
-
input_shape = (None, features)
- 用于密集:
batch_shape=(None,input_dim)
或batch_input_shape=(None,input_dim)
这篇关于简单神经网络(Keras)的可变长度输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- 1D:
- 一维: