找到两个张量的交点.返回两个输入张量中的排序后的唯一值 [英] Find the intersection of two tensors. Return the sorted, unique values that are in both of the input tensors

查看:73
本文介绍了找到两个张量的交点.返回两个输入张量中的排序后的唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是Tensorflow初学者,

Hi Tensorflow Beginner here,

我想在实现中删除任何numpy代码,仅使用tensorflow函数.目前,我正在尝试滤除背景边界框和置信度得分较低的框.为此,我需要一个名为 keep 的索引,该索引可用于跟踪要保留的框:

I want to remove any numpy code in implementation and only use tensorflow functions. Currently I'm trying to filter out Background Bounding Boxes and boxes with a low confidence score. For that I want a index called keep that I can use to keep track of which boxes to keep:

# Filter out background boxes
keep = np.where(class_ids > 0)[0]
# Filter out low confidence boxes
if config.DETECTION_MIN_CONFIDENCE:
    keep = np.intersect1d(
        keep, np.where(class_scores >= config.DETECTION_MIN_CONFIDENCE)[0])

class_ids是形状的张量(1000,),其中每个条目都是0到80之间的数字,具体取决于类别(总共81个类别).

class_ids is a tensor of shape (1000,) where each entry is a number between 0 and 80 depending on the class (81 classes in total).

class_scores是形状的张量(1000,),其中每个条目都是对应边界框类别的概率.

class_scores is a tensor of shape (1000,) where each entry is a probability for the class of the corresponding bounding box.

我知道np.where()很容易更改为tf.where,但是如何通过tensorflow获得与np.intersect1d()相同的功能?

I know that np.where() is easily changed to tf.where but how can I get the same functionality as np.intersect1d() with tensorflow?

感谢您的帮助.

推荐答案

这似乎重复了numpy.intersect1d示例.

This seems to duplicate the numpy.intersect1d example.

import tensorflow as tf

a = tf.constant([3, 1, 2, 1])
b = tf.constant([1, 3, 4, 3])

# This set appears to be sorted, but that is not documented behavior.
s = tf.sets.set_intersection(a[None,:], b[None, :])
fsort = tf.contrib.framework.sort(s.values)

with tf.Session() as sess:
    print(sess.run(s).values)
    print(sess.run(fsort))

此输出

[1 3]
[1 3]

通过一些测试示例,set函数似乎给出了有序的结果,但是我无法验证它是否总是可以做到这一点.因此,您可能只是想确保使用contrib函数.

With a few test examples, the set function seems to give ordered results, but I could not verify that it will always do that. So, you might want to use the contrib function just to be sure.

这篇关于找到两个张量的交点.返回两个输入张量中的排序后的唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆