如何使用尺寸为无的tf.nn.top_k

时间:2017-01-12 07:54:07

标签: python machine-learning tensorflow neural-network

我想使用tf.nn.top k替换argsortnumpy
但似乎tf.nn.top_k不接受None维度 这是我的代码

cond1 = tf.greater_equal(ws, min_size) # assume shape is (100,)
cond2 = tf.greater_equal(hs, min_size) # assume shape is (100,)
cond = cond1 & cond2 # shape is (100)

# cause I don't give x and y, so tf.where return index of True element
# but number of True is unknow now
keep = tf.where(cond) # so shape is (?,1)
keep = tf.reshape(keep, [-1]) # shape is (?,)

val = tf.gather(val, keep) # shpae is (?,)
argsort = tf.nn.top_k(val, val.get_shape()[0]) 
# ValueError: Cannot convert an unknown Dimension to a Tensor: ?

1 个答案:

答案 0 :(得分:0)

here找到答案 维度仍然没有,但它的工作,惊讶

{{1}}