本文整理汇总了Python中object_detection.utils.ops.indices_to_dense_vector方法的典型用法代码示例。如果您正苦于以下问题:Python ops.indices_to_dense_vector方法的具体用法?Python ops.indices_to_dense_vector怎么用?Python ops.indices_to_dense_vector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类object_detection.utils.ops
的用法示例。
在下文中一共展示了ops.indices_to_dense_vector方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_indices_to_dense_vector_size_at_inference
# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import indices_to_dense_vector [as 别名]
def test_indices_to_dense_vector_size_at_inference(self):
size = 5000
num_indices = 250
all_indices = np.arange(size)
rand_indices = np.random.permutation(all_indices)[0:num_indices]
expected_output = np.zeros(size, dtype=np.float32)
expected_output[rand_indices] = 1.
tf_all_indices = tf.placeholder(tf.int32)
tf_rand_indices = tf.constant(rand_indices)
indicator = ops.indices_to_dense_vector(tf_rand_indices,
tf.shape(tf_all_indices)[0])
feed_dict = {tf_all_indices: all_indices}
with self.test_session() as sess:
output = sess.run(indicator, feed_dict=feed_dict)
self.assertAllEqual(output, expected_output)
self.assertEqual(output.dtype, expected_output.dtype)
示例2: test_indices_to_dense_vector_int
# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import indices_to_dense_vector [as 别名]
def test_indices_to_dense_vector_int(self):
size = 500
num_indices = 25
rand_indices = np.random.permutation(np.arange(size))[0:num_indices]
expected_output = np.zeros(size, dtype=np.int64)
expected_output[rand_indices] = 1
tf_rand_indices = tf.constant(rand_indices)
indicator = ops.indices_to_dense_vector(
tf_rand_indices, size, 1, dtype=tf.int64)
with self.test_session() as sess:
output = sess.run(indicator)
self.assertAllEqual(output, expected_output)
self.assertEqual(output.dtype, expected_output.dtype)
示例3: test_indices_to_dense_vector_custom_values
# 需要导入模块: from object_detection.utils import ops [as 别名]
# 或者: from object_detection.utils.ops import indices_to_dense_vector [as 别名]
def test_indices_to_dense_vector_custom_values(self):
size = 100
num_indices = 10
rand_indices = np.random.permutation(np.arange(size))[0:num_indices]
indices_value = np.random.rand(1)
default_value = np.random.rand(1)
expected_output = np.float32(np.ones(size) * default_value)
expected_output[rand_indices] = indices_value
tf_rand_indices = tf.constant(rand_indices)
indicator = ops.indices_to_dense_vector(
tf_rand_indices,
size,
indices_value=indices_value,
default_value=default_value)
with self.test_session() as sess:
output = sess.run(indicator)
self.assertAllClose(output, expected_output)
self.assertEqual(output.dtype, expected_output.dtype)