0

I have three functions in file fe_extraction.py

def rms_value(x):
    return tf.sqrt(tf.reduce_mean(tf.square(x)))
def meanabs(x):
    return tf.reduce_mean(tf.abs(x))

def req_value(x,y,Thersh):
    z = tf.cond(y>Thersh,rms_freq(x),peak_value(x))
return z

I want to simply apply a condition if y > thershold perform rms_freq(x) or else peak_value(x) and return that value. y is the value obtained from another function.

# given values
# Thershold = 10.69 
# x is defined as tf.Variable , dtype tf.float64
# y = 45.34 obtained from function
....
z = fe_extraction.req_value(x,y,Thershold)

I get error as TypeError:fn1 must be callable.

1 Answer 1

2

With rms_freq(x) and peak_value(x) you're calling the function rms_freq and peak_value respectively, passing x as argument.

Instead, you have to pass a callable or, in other words, a function, that tf.cond can execute.

Since you want x as a parameter for your functions, you can wrap them in a lambda that defines a callable object that captures the outside scope and thus sees the parameter x.

z = tf.cond(y>Thersh,lambda: rms_freq(x) ,lambda: peak_value(x))
Sign up to request clarification or add additional context in comments.

2 Comments

it gives me an error again 'TypeError: pred must not be a Python bool'
y>Thersh is a python boolean, this means that both y and Thersh are python variables, so tf.cond is useless in this case, you can just use a python if statement. By the way, cond should be a tensorflow boolean, you must use tf operations like tf.greater(y, Thersh, name=None)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.