[英]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图层来包装你的功能吗?
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.