【发布时间】:2019-08-07 10:55:30
【问题描述】:
我有 7 个分类特征 我正在尝试在嵌入层之后添加一个 CNN 层
我的第一层是输入层 第二层是嵌入层 第三层我想添加一个 Conv2D 层
我在 Conv_2D 中尝试过 input_shape=(7,36,1) 但没有成功
input2 = Input(shape=(7,))
embedding2 = Embedding(76474, 36)(input2)
# 76474 is the number of datapoints (rows)
# 36 is the output dim of embedding Layer
cnn1 = Conv2D(64, (3, 3), activation='relu')(embedding2)
flat2 = Flatten()(cnn1)
但是我收到了这个错误
Input 0 of layer conv2d is incompatible with the layer: expected
ndim=4, found ndim=3. Full shape received: [None, 7, 36]
【问题讨论】:
-
您需要使用一维卷积,因为您的数据是一维的。其次,只有当输入数据是元素顺序很重要并表示意义的序列时(例如,单词序列、基因组序列、音频样本序列),使用 1D conv 才有意义。如果这七个分类特征彼此之间没有顺序关系,那么使用卷积就没有意义了。
标签: python-3.x keras deep-learning conv-neural-network