简体   繁体   English

TypeError:模型的输出张量必须是Keras张量

[英]TypeError: Output tensors to a Model must be Keras tensors

I want to take an input image img (which also has negative values) and feed it into two activation layers. 我想拍摄输入图像img (也有负值)并将其输入两个激活层。 However, I want to make a simple transformation eg multiply the whole image with -1.0 : 但是,我想进行一个简单的转换,例如将整个图像乘以-1.0

left = Activation('relu')(img)
right = Activation('relu')(tf.mul(img, -1.0))

If I do it this way I am getting: 如果我这样做,我得到:

TypeError: Output tensors to a Model must be Keras tensors. Found: Tensor("add_1:0", shape=(?, 5, 1, 3), dtype=float32)

and I am not sure how I can fix that. 我不知道如何解决这个问题。 Is there a Keras side mul() method that I can use for such a thing? 是否有一个Keras side mul()方法可以用于这样的事情? Or can I wrap the result of tf.mul(img, -1.0) somehow such that I can pass it on to Activation ? 或者我可以以某种方式包装tf.mul(img, -1.0)的结果,以便我可以将其传递给Activation

Please note: The negative values may be important. 请注意:负值可能很重要。 Thus transforming the image st the minimum is simply 0.0 is not a solution here. 因此,将图像转换为最小值仅为0.0不是解决方案。


I am getting the same error for 我得到了同样的错误

left = Activation('relu')(conv)
right = Activation('relu')(-conv)

The same error for: 同样的错误:

import tensorflow as tf

minus_one = tf.constant([-1.])

# ...

    right = merge([conv, minus_one], mode='mul')

Does creating a Lambda Layer to wrap your function work? 创建一个Lambda图层来包装你的功能吗?

See doc here 请参阅此处的 doc

from keras.layers import Lambda
import tensorflow as tf

def mul_minus_one(x):
    return tf.mul(x,-1.0)
def mul_minus_one_output_shape(input_shape):
    return input_shape

myCustomLayer = Lambda(mul_minus_one, output_shape=mul_minus_one_output_shape)
right = myCustomLayer(img)
right = Activation('relu')(right)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模型的输出张量必须是Keras张量 - Output tensors to a Model must be Keras tensors Keras - TypeError:模型的输出张量必须是Keras张量 - 同时建模多输入,多输出网络 - Keras - TypeError: Output tensors to a Model must be Keras tensors - while modelling multiple input , multiple output network Keras简单数学运算模型失败,“输出张量到模型必须是Keras张量” - Keras simple math operation model fails with “Output tensors to a Model must be Keras tensors” Keras输出张量到模型必须是TensorFlow`Telay`的输出 - Keras Output tensors to a Model must be the output of a TensorFlow `Layer` 模型的Keras输出张量必须是Keras层的输出(因此保留了过去的层元数据) - Keras Output tensors to a Model must be the output of a Keras `Layer` (thus holding past layer metadata) ValueError:模型的输出张量必须是带有tf.keras Lambda层的TensorFlow层的输出 - ValueError: Output tensors to a Model must be the output of a TensorFlow Layer with tf.keras Lambda layer Tensorflow - ValueError:模型的输出张量必须是 TensorFlow `Layer` 的输出 - Tensorflow - ValueError: Output tensors to a Model must be the output of a TensorFlow `Layer` ValueError:模型的输出张量必须是TensorFlow`Layer`的输出 - ValueError: Output tensors to a Model must be the output of a TensorFlow `Layer` 如何解决 ValueError:模型的输出张量必须是 Keras `Layer` 的输出(因此保存过去的层元数据)。? - How can I resolve ValueError: Output tensors to a Model must be the output of a Keras `Layer` (thus holding past layer metadata).? 模型的输出张量必须是 Keras `Layer` 的输出(因此保存过去的层元数据)。 CNN LSTM 使用函数式 api 时 - Output tensors to a Model must be the output of a Keras `Layer` (thus holding past layer metadata). When using functional api for CNN LSTM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM