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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。