【发布时间】:2021-08-31 01:48:45
【问题描述】:
我一直试图让它工作一段时间,但我不知道如何。我尝试了十几种组合。
我要做的是获取输入数组,比较每个元素以查看其是正数还是负数。根据积极性或消极性应用独特的转换。取平均值并返回结果。这是我拥有的,但它不起作用。
编辑:我最近的尝试
@tf.function
def transform(x, y):
et = tf.math.subtract(x, y)
et_variable = tf.Variable(et)
max_loop = tf.shape(x)[0]
loss = tf.TensorArray(tf.float32, size=et.shape[0], clear_after_read=False)
loss = loss.unstack(et_variable)
i = tf.constant(0)
while tf.math.less(i, max_loop):
if loss.gather([i])[0] > 0:
val = 3 * loss.gather([i])[0]
else:
val = 2 * loss.gather([i])[0]
loss = loss.scatter([i], value=[val])
i = tf.Variable(i)
i = i + 1
i = tf.constant(i)
return(K.mean(loss.stack()))
我收到一个错误:
ValueError: condition of if statement expected to be `tf.bool` scalar, got Tensor("loss_funk/while/Greater:0", shape=(11,), dtype=bool); to check for None, use `is not None`
我尝试过使用 tf.Variable 和 tf.tensorarray,但都不能使用 tf.function。
【问题讨论】:
标签: python tensorflow tensor