当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Tensorflow.js tf.image.nonMaxSuppression()用法及代码示例


Tensorflow.js是Google开发的开放源代码库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。

.image.nonMaxSuppression() 函数用于在iou的基础上对限制框进行非最大抑制,即交集。

用法:

tf.image.nonMaxSuppression(boxes, scores, 
    maxOutputSize, iouThreshold?, scoreThreshold?)

参数:

  • boxes:所述的二维张量,其配置为 [numBoxes, 4]。并且每次访问都是 [y1, x1, y2, x2],允许 (y1, x1) 和 (y2, x2) 是限制框的边。它可以是 tf.Tensor2D、TypedArray 或 Array 类型。
  • scores:规定的一维张量,前提是框得分是配置 [numBoxes]。它是 tf.Tensor2D、TypedArray 或 Array 类型。
  • maxOutputSize:它是要拣选的指定箱子的最大数量。它是类型号。
  • iouThreshold:规定的浮点数表示阈值,以决定规定的框是否与 IOU 相交太多。它应该在 [0, 1] 的中间。默认值为 0.5,即 50% 的框相交。它是可选的,类型为 number。
  • scoreThreshold:这是规定的阈值,以便根据规定的分数决定在哪些时间删除框。默认值为 -inf,即允许每个分数。它是可选的,类型为 number。

返回值:它返回 tf.Tensor1D。



范例1:在此示例中,我们将使用 2d 张量、分数和 maxOutputSize 参数。

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling image.nonMaxSuppression() method and
// Printing output
tf.image.nonMaxSuppression(tf.tensor2d(
    [1, 2, 3, 4, 2, 4, 6, 7], 
    [2, 4]), [1, 1], 4).print();

输出:

Tensor
    [0, 1]

范例2:在此示例中,我们将使用浮点数组 iouThreshold 和 scoreThreshold。

Javascript


// Importing the tensorflow.js library
//import * as tf from "@tensorflow/tfjs"
  
// Defining an array of floats
const arr = [[11.1, 2.3, 7.3, 6.4], [3, 6]]
  
// Calling image.nonMaxSuppression() method and
// Printing output
tf.image.nonMaxSuppression(arr, [2.1, 0], 100, 0.5, 1).print();

输出:

Tensor
    [0]

参考: https://js.tensorflow.org/api/latest/#image.nonMaxSuppression

相关用法


注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Tensorflow.js tf.image.nonMaxSuppression() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。