Tensorflow.js是Google开发的开放源代码库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。
.image.nonMaxSuppressionWithScoreAsync() 函数用于基于iou(即联合上的交集)异步执行限制框的非极大值抑制。此外,此操作也有利于 Soft-NMS 模式,其中框降低了不同相交框的规定分数,从而支持除了高分之外的图像的各个区域。为了启用前面提到的 Soft-NMS 模式,我们需要将 softNmsSigma 参数设置为大于零。
用法:
tf.image.nonMaxSuppressionWithScoreAsync(boxes, scores, maxOutputSize, iouThreshold?, scoreThreshold?, softNmsSigma?)
参数:此方法接受以下参数:
- 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。
- softNmsSigma:它是类型为 number 的可选参数。它是规定的浮点数,表示支持 Soft NMS 的 sigma 参数。此外,如果 sigma 为零,则返回到 nonMaxSuppression。
返回值:它返回 {[name:string]:tf.Tensor} 的承诺。
范例1:使用 2d 张量、分数和 maxOutputSize 参数。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs")
// Calling image.nonMaxSuppressionWithScoreAsync() method
const output = tf.image.nonMaxSuppressionWithScoreAsync(
tf.tensor2d([1, 2, 3, 4, 2, 4, 6, 7], [2, 4]), [1, 1], 4);
// Printing output
console.log(output.then((result) => console.log(result)));
输出:
{ selectedIndices:Tensor { kept:false, isDisposedInternal:false, shape:[ 2 ], dtype:'int32', size:2, strides:[], dataId:{ id:2 }, id:2, rankType:'1' }, selectedScores:Tensor { kept:false, isDisposedInternal:false, shape:[ 2 ], dtype:'float32', size:2, strides:[], dataId:{ id:3 }, id:3, rankType:'1' } }
范例2:使用浮点数数组 iouThreshold、scoreThreshold 和 softNmsSigma。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs")
// Defining an array of floats
const arr = [[11.1, 2.3, 7.3, 6.4], [3, 6]]
// Calling image.nonMaxSuppressionWithScoreAsync() method
const output = tf.image.nonMaxSuppressionWithScoreAsync(
arr, [2.1, 0], 100, 0.5, 1, 0.5);
// Printing output
console.log(output.then((result) => console.log(result)));
输出:
{ selectedIndices:Tensor { kept:false, isDisposedInternal:false, shape:[ 1 ], dtype:'int32', size:1, strides:[], dataId:{ id:2 }, id:2, rankType:'1' }, selectedScores:Tensor { kept:false, isDisposedInternal:false, shape:[ 1 ], dtype:'float32', size:1, strides:[], dataId:{ id:3 }, id:3, rankType:'1' } }
参考: https://js.tensorflow.org/api/latest/#image.nonMaxSuppressionWithScoreAsync
相关用法
- PHP imagecreatetruecolor()用法及代码示例
- p5.js year()用法及代码示例
- d3.js d3.utcTuesdays()用法及代码示例
- PHP ImagickDraw getTextAlignment()用法及代码示例
- PHP Ds\Sequence last()用法及代码示例
- PHP Imagick floodFillPaintImage()用法及代码示例
- PHP geoip_continent_code_by_name()用法及代码示例
- d3.js d3.map.set()用法及代码示例
- PHP GmagickPixel setcolor()用法及代码示例
- Tensorflow.js tf.layers.embedding()用法及代码示例
- PHP opendir()用法及代码示例
- PHP cal_to_jd()用法及代码示例
注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Tensorflow.js tf.image.nonMaxSuppressionWithScoreAsync() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。