如何使用Tensorflow张量设置Keras层的输入?

古鲁鲁

上一个问题中,我使用Layer.set_input()Keras '将Tensorflow预处理输出张量连接到Keras模型的输入。但是,此方法在Keras版本之后已删除1.1.1

如何在较新的Keras版本中实现此目的?

例:

# Tensorflow pre-processing
raw_input = tf.placeholder(tf.string)
### some TF operations on raw_input ###
tf_embedding_input = ...    # pre-processing output tensor

# Keras model
model = Sequential()
e = Embedding(max_features, 128, input_length=maxlen)

### THIS DOESN'T WORK ANYMORE ###
e.set_input(tf_embedding_input)
################################

model.add(e)
model.add(LSTM(128, activation='sigmoid'))
model.add(Dense(num_classes, activation='softmax'))
因陀罗

完成预处理后,可以通过调用以下tensor参数来将张量添加为输入层Input

因此,在您的情况下:

tf_embedding_input = ...    # pre-processing output tensor

# Keras model
model = Sequential()
model.add(Input(tensor=tf_embedding_input)) 
model.add(Embedding(max_features, 128, input_length=maxlen))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在3D张量输入中使用keras嵌入层?

如何使Keras密集层处理3D张量作为此Softmax全连接层的输入?

如何使用张量作为函数的输入?(tensorflow)

如何在Tensorflow 2.x Keras自定义层中使用多个输入?

如何在Keras / tensorflow中向输入张量添加恒定张量

使用自定义张量作为变量的TensorFlow 2.0 Keras层

tensorflow.js层API的输入输出张量如何工作

在Keras中使用Tensorflow层

应用于张量的 Tensorflow/Keras 嵌入层

Keras/Tensorflow 输入到 RNN 层

输入层的TensorFlow Keras尺寸错误

keras模型类中的输入层使用numpy数组或张量作为输入给出类型错误。那么正确的类型是什么?

向keras模型添加预处理层并设置张量值

在使用多个输入层训练的keras模型中,如何在预测时忽略某些输入层?

如何使用Keras API提取“从输入层到隐藏层”和“从隐藏层到输出层”的权重?

如何使用批量大小在自定义TensorFlow层中创建张量

Tensorflow Keras输入层不添加_keras_shape

使用numpy方法修改(keras / tensorflow)张量

如何将张量流对象包装为Keras层?

如何为基本向量/张量乘法编写 Keras 层

Keras:如何使用 Keras 中的输入张量对常量矩阵进行切片?

在Tensorflow 2.0上将tf.data.Dataset与Keras输入层一起使用

Keras 中的输入层是如何定义的?

Tensorflow Keras:评估时如何在自定义层中设置断点(调试)?

在tensorflow代码中使用keras层

使用 keras tensorflow 实现共享卷积层

keras - 层模型_131 需要 7 个输入,但它收到 1 个输入张量

Keras:“指定为模型输入的张量不是输入张量。” 如何正确地将输出张量转换为输入张量?

张量层的Tensorflow随机分布