I want to take an input image img
(which also has negative values) and feed it into two activation layers. However, I want to make a simple transformation e.g. multiply the whole image with -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? Or can I wrap the result of tf.mul(img, -1.0)
somehow such that I can pass it on to Activation
?
Please note: The negative values may be important. Thus transforming the image s.t. the minimum is simply 0.0
is not a solution here.
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?
See doc 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With