Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 如何扩大keras中嵌入层的输出_Tensorflow_Keras_Keras Layer - Fatal编程技术网

Tensorflow 如何扩大keras中嵌入层的输出

Tensorflow 如何扩大keras中嵌入层的输出,tensorflow,keras,keras-layer,Tensorflow,Keras,Keras Layer,我拥有以下网络: model = Sequential() model.add(Embedding(400000, 100, weights=[emb], input_length=12, trainable=False)) model.add(Conv2D(256,(2,2),activation='relu')) 嵌入层的输出为形状(batchSize,12100)。conv2D层需要输入shape(batchSize,filter,12100),我得到以下错误: Input 0 is

我拥有以下网络:

model = Sequential()
model.add(Embedding(400000, 100, weights=[emb], input_length=12, trainable=False))

model.add(Conv2D(256,(2,2),activation='relu'))
嵌入层的输出为形状(batchSize,12100)。conv2D层需要输入shape(batchSize,filter,12100),我得到以下错误:

 Input 0 is incompatible with layer conv2d_1: expected ndim=4, found ndim=3
那么,如何扩展嵌入层的输出,使其适合于Conv2D层呢


我正在使用Keras和Tensorflow作为后端。

添加重塑层应该是一个不错的选择
根据具体情况,Conv1D虽然工作很冷。

我设法用以下代码添加了另一个维度:

model = Sequential()
model.add(Embedding(400000, 100, weights=[emb], input_length=12, trainable=False))
model.add(Lambda(lambda x: expand_dims(x, 3)))
model.add(Conv2D(256,(2,2),activation='relu'))

将Conv2d替换为Conv1D。不需要展开维度。重塑将更改数据本身,但我需要添加另一个长度为1的维度!!看起来你解决了你的问题(我完全忘记了lambda层),但是有没有理由不使用Conv1D?我需要一个二维内核(窗口)来滑动数据,Conv1D只在一个维度上进行卷积。