作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想获取输入图像 img
(它也有负值)并将其馈送到两个激活层。但是,我想做一个简单的转换,例如将整个图像乘以 -1.0
:
left = Activation('relu')(img)
right = Activation('relu')(tf.mul(img, -1.0))
如果我这样做,我会得到:
TypeError: Output tensors to a Model must be Keras tensors. Found: Tensor("add_1:0", shape=(?, 5, 1, 3), dtype=float32)
我不确定该如何解决。是否有 Keras
方面的 mul()
方法可以用于此类事情?或者我能否以某种方式包装 tf.mul(img, -1.0)
的结果,以便我可以将其传递给 Activation
?
请注意:负值可能很重要。从而转换图像 st。最小值只是 0.0
不是这里的解决方案。
同样的错误
left = Activation('relu')(conv)
right = Activation('relu')(-conv)
同样的错误:
import tensorflow as tf
minus_one = tf.constant([-1.])
# ...
right = merge([conv, minus_one], mode='mul')
最佳答案
创建 Lambda 层来包装您的函数是否有效?
参见文档 here
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)
关于python - 类型错误 : Output tensors to a Model must be Keras tensors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42297359/
我是一名优秀的程序员,十分优秀!