gpt4 book ai didi

python - tensorflow 采样

转载 作者:行者123 更新时间:2023-12-01 09:19:39 28 4
gpt4 key购买 nike

我使用以下函数在每个图像中采样点。如果batch_size为None,tf.range会给出错误。如何在 tensorflow 中采样

def sampling(binary_selection,num_points, points):
"""
binary_selection: tensor of size (batch_size, points)
with values 1.0 or 0.0. Indicating positive and negative points.
We want to sample num_points from positive points of each image
points: tensor of size (batch_size, num_points_in_image)
num_points: number of points to sample for each image
"""
batch_size = points.get_shape()[0]
indices = tf.multinomial((tf.log(binary_selection)), num_points)
indices = tf.cast(tf.expand_dims(indices, axis=2), tf.int32)
batch_seq = tf.expand_dims(tf.range(batch_size), axis=1)
im_indices = tf.expand_dims(tf.tile(batch_seq, [1, num_points]), axis=2)
indices = tf.concat([im_indices, indices], axis=2)
return tf.gather_nd(points, indices)

我收到以下错误

_dimension_tensor_conversion_function raise ValueError("Cannot convert an unknown Dimension to a Tensor: %s" % d) ValueError: Cannot convert an unknown Dimension to a Tensor: ?

在测试和训练期间,我会将batch_size设置为一个整数,但是当我初始化时,我想将 None 作为输入,以便在测试和训练期间可以改变批量大小。

最佳答案

您需要为batch_size提供一个值。

需要初始化。

目前,它没有被赋予任何值(value)。

关于python - tensorflow 采样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50901790/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com