【发布时间】:2023-01-29 22:05:09
【问题描述】:
我正在创建一个函数,该函数采用张量值并通过应用以下公式返回结果,有 3 个条件,所以我使用 @tf.functions。
def Spa(x):
x= tf.convert_to_tensor(float(x), dtype=tf.float32)
p= tf.convert_to_tensor(float(0.05), dtype=tf.float32)
p_dash=x
K = p*logp_dash
Ku=K.sum(Ku)
Ku= tf.convert_to_tensor(float(Ku), dtype=tf.float32)
y= tf.convert_to_tensor(float(0), dtype=tf.float32)
def a(): return tf.constant(0)
r = tf.case([(tf.less(x, y), a), (tf.greater(x, Ku), a)], default=x, exclusive=False)
return r
该代码生成以下错误:'false_fn' 必须是可调用的。我做了很多转换,int 到 float 和 float 到 int 但不知道是什么问题。
【问题讨论】:
-
must be callable意味着它必须是函数(或具有定义的()运算符的东西)。 -
def y(): return tf.constant(0) y = y() y = tf.convert_to_tensor(y, dtype=tf.int32)添加这个还是报错
标签: python tensorflow autoencoder activation-function relu