当我打算将keras输出乘以常数张量时,遇到了一个问题? 这是我的密码
a = tf.constant(ws, "float32")
output4 = AveragePooling3D(pool_size=(X_shape[0], 1, 1), strides = None, padding='valid')(output3)
output5 = Conv3D(filters=X_shape[3], kernel_size=(1, 1, 1),padding='same',data_format='channels_last')(output4)
output6 = Lambda( tf.multiply(output5, a))(output5)
这是我的错误“
ValueError: Tensor("Const:0", shape=(1, 1, 21, 27, 3), dtype=float32) must be from the same graph as Tensor("conv3d_1/add:0", shape=(None, 1, 21, 27, 3), dtype=float32).
提前感谢您的帮助
由于您使用的是函数式API,因此需要提供常量张量作为模型的输入,或者作为继承
Layer
的对象的构造函数的输入方法1(首选)-作为自定义图层的输入:
方法2-作为单独的输入层:
然后将
const_inp
添加到模型的输入列表中。但这不是最好的办法相关问题 更多 >
编程相关推荐