如何读取tensorflow非最大值抑制方法源代码?

如何读取tensorflow非最大值抑制方法源代码?,tensorflow,object-detection,object-detection-api,non-maximum-suppression,Tensorflow,Object Detection,Object Detection Api,Non Maximum Suppression,我正在阅读这篇文章中Tensorflow非最大值抑制方法的源代码。它是从gen\u image\u ops文件导入的,但是我在tensorflow源代码中的任何地方都找不到该文件 是否有任何来源可以获取此方法的代码?我也尝试过挖掘他们的回购协议,但运气不好,所以我最终只是从我的编辑器获得了代码 我使用了PyCharm,所以我只是从tensorflow.python.ops.gen_image_ops中执行了,然后单击它来获取代码 我已经添加了它的两个版本,所以给你 第一版 def _non_ma

我正在阅读这篇文章中Tensorflow非最大值抑制方法的源代码。它是从
gen\u image\u ops
文件导入的,但是我在tensorflow源代码中的任何地方都找不到该文件


是否有任何来源可以获取此方法的代码?

我也尝试过挖掘他们的回购协议,但运气不好,所以我最终只是从我的编辑器获得了代码

我使用了PyCharm,所以我只是从tensorflow.python.ops.gen_image_ops中执行了
,然后单击它来获取代码

我已经添加了它的两个版本,所以给你

第一版

def _non_max_suppression(boxes, scores, max_output_size, iou_threshold=0.5, name=None):
  r"""Greedily selects a subset of bounding boxes in descending order of score,

  pruning away boxes that have high intersection-over-union (IOU) overlap
  with previously selected boxes.  Bounding boxes are supplied as
  [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any
  diagonal pair of box corners and the coordinates can be provided as normalized
  (i.e., lying in the interval [0, 1]) or absolute.  Note that this algorithm
  is agnostic to where the origin is in the coordinate system.  Note that this
  algorithm is invariant to orthogonal transformations and translations
  of the coordinate system; thus translating or reflections of the coordinate
  system result in the same boxes being selected by the algorithm.
  The output of this operation is a set of integers indexing into the input
  collection of bounding boxes representing the selected boxes.  The bounding
  box coordinates corresponding to the selected indices can then be obtained
  using the `tf.gather operation`.  For example:
    selected_indices = tf.image.non_max_suppression(
        boxes, scores, max_output_size, iou_threshold)
    selected_boxes = tf.gather(boxes, selected_indices)

  Args:
    boxes: A `Tensor` of type `float32`.
      A 2-D float tensor of shape `[num_boxes, 4]`.
    scores: A `Tensor` of type `float32`.
      A 1-D float tensor of shape `[num_boxes]` representing a single
      score corresponding to each box (each row of boxes).
    max_output_size: A `Tensor` of type `int32`.
      A scalar integer tensor representing the maximum number of
      boxes to be selected by non max suppression.
    iou_threshold: An optional `float`. Defaults to `0.5`.
      A float representing the threshold for deciding whether boxes
      overlap too much with respect to IOU.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int32`.
    A 1-D integer tensor of shape `[M]` representing the selected
    indices from the boxes tensor, where `M <= max_output_size`.
  """
  if iou_threshold is None:
    iou_threshold = 0.5
  iou_threshold = _execute.make_float(iou_threshold, "iou_threshold")
  _ctx = _context.context()
  if _ctx.in_graph_mode():
    _, _, _op = _op_def_lib._apply_op_helper(
        "NonMaxSuppression", boxes=boxes, scores=scores,
        max_output_size=max_output_size, iou_threshold=iou_threshold,
        name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("iou_threshold", _op.get_attr("iou_threshold"))
  else:
    boxes = _ops.convert_to_tensor(boxes, _dtypes.float32)
    scores = _ops.convert_to_tensor(scores, _dtypes.float32)
    max_output_size = _ops.convert_to_tensor(max_output_size, _dtypes.int32)
    _inputs_flat = [boxes, scores, max_output_size]
    _attrs = ("iou_threshold", iou_threshold)
    _result = _execute.execute(b"NonMaxSuppression", 1, inputs=_inputs_flat,
                               attrs=_attrs, ctx=_ctx, name=name)
  _execute.record_gradient(
      "NonMaxSuppression", _inputs_flat, _attrs, _result, name)
  _result, = _result
  return _result
def _non_max_suppression_v2(boxes, scores, max_output_size, iou_threshold, name=None):
  r"""Greedily selects a subset of bounding boxes in descending order of score,

  pruning away boxes that have high intersection-over-union (IOU) overlap
  with previously selected boxes.  Bounding boxes are supplied as
  [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any
  diagonal pair of box corners and the coordinates can be provided as normalized
  (i.e., lying in the interval [0, 1]) or absolute.  Note that this algorithm
  is agnostic to where the origin is in the coordinate system.  Note that this
  algorithm is invariant to orthogonal transformations and translations
  of the coordinate system; thus translating or reflections of the coordinate
  system result in the same boxes being selected by the algorithm.

  The output of this operation is a set of integers indexing into the input
  collection of bounding boxes representing the selected boxes.  The bounding
  box coordinates corresponding to the selected indices can then be obtained
  using the `tf.gather operation`.  For example:

    selected_indices = tf.image.non_max_suppression_v2(
        boxes, scores, max_output_size, iou_threshold)
    selected_boxes = tf.gather(boxes, selected_indices)

  Args:
    boxes: A `Tensor` of type `float32`.
      A 2-D float tensor of shape `[num_boxes, 4]`.
    scores: A `Tensor` of type `float32`.
      A 1-D float tensor of shape `[num_boxes]` representing a single
      score corresponding to each box (each row of boxes).
    max_output_size: A `Tensor` of type `int32`.
      A scalar integer tensor representing the maximum number of
      boxes to be selected by non max suppression.
    iou_threshold: A `Tensor` of type `float32`.
      A 0-D float tensor representing the threshold for deciding whether
      boxes overlap too much with respect to IOU.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int32`.
    A 1-D integer tensor of shape `[M]` representing the selected
    indices from the boxes tensor, where `M <= max_output_size`.
  """
  _ctx = _context.context()
  if _ctx.in_graph_mode():
    _, _, _op = _op_def_lib._apply_op_helper(
        "NonMaxSuppressionV2", boxes=boxes, scores=scores,
        max_output_size=max_output_size, iou_threshold=iou_threshold,
        name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
  else:
    boxes = _ops.convert_to_tensor(boxes, _dtypes.float32)
    scores = _ops.convert_to_tensor(scores, _dtypes.float32)
    max_output_size = _ops.convert_to_tensor(max_output_size, _dtypes.int32)
    iou_threshold = _ops.convert_to_tensor(iou_threshold, _dtypes.float32)
    _inputs_flat = [boxes, scores, max_output_size, iou_threshold]
    _attrs = None
    _result = _execute.execute(b"NonMaxSuppressionV2", 1, inputs=_inputs_flat,
                               attrs=_attrs, ctx=_ctx, name=name)
  _execute.record_gradient(
      "NonMaxSuppressionV2", _inputs_flat, _attrs, _result, name)
  _result, = _result
  return _result
def\u非最大值抑制(方框、分数、最大值输出大小、iou阈值=0.5、名称=无):
r“”“贪婪地按分数降序选择边界框的子集,
修剪掉在并集(IOU)重叠上具有高交集的框
使用以前选择的框。边界框作为
[y1,x1,y2,x2],其中(y1,x1)和(y2,x2)是任何
盒角的对角线对和坐标可作为标准化提供
(即位于区间[0,1])或绝对值。请注意,此算法
不知道原点在坐标系中的位置。请注意
该算法对正交变换和平移具有不变性
坐标系的;因此坐标的平移或反射
系统会导致算法选择相同的框。
此操作的输出是一组索引到输入的整数
表示所选框的边界框的集合。边界框
然后可以获得与所选索引对应的框坐标
使用“tf.gather操作”。例如:
所选索引=tf.image.non\u max\u抑制(
方框、分数、最大输出大小、iou阈值)
选定的_框=tf.gather(框、选定的_索引)
Args:
框:一个'float32'类型的'Tensor'。
形状为“[num_-box,4]”的二维浮点张量。
分数:一个'float32'类型的'Tensor'。
形状为“[num_-box]”的一维浮点张量表示单个
每个方框对应的分数(每行方框)。
最大输出大小:一个'int32'类型的'Tensor'。
一个标量整数张量,表示
要通过非最大抑制选择的框。
iou_阈值:可选的“float”。默认值为“0.5”。
一个浮点数,表示用于决定是否选择框的阈值
与借据重叠过多。
名称:操作的名称(可选)。
返回:
“int32”类型的“张量”。
形状为“[M]”的一维整数张量,表示选定的
来自Box张量的指数,其中`M


每当您看到“导入生成”_*Python OP定义中的行,他们正在导入一个自动生成的Python模块,并将绑定绑定到OPL的C++实现。如果您正在下载pip模块或其他预构建版本,则生成已经完成,您只需引用已编译的库

谢谢,这真的很有帮助。似乎他们调用
execute
\u apply\u op\u helper
来运行nms。你知道如何达到核心算法吗?就像我做的一样。从IDE打开它。对象检测API中使用的nms算法位于core/post_processing.py文件中。我想原始代码在这里。