Tensorflow.js是Google開發的開放源代碼庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。
.image.nonMaxSuppressionWithScore() 函數用於在iou的基礎上對限製框進行非最大抑製,即交集。此外,此操作也有利於 Soft-NMS 模式,其中框降低了不同相交框的規定分數,從而支持高分之外的圖像的各個區域。為了啟用上述 Soft-NMS 模式,我們需要將 softNmsSigma 參數設置為大於零。
用法:
tf.image.nonMaxSuppressionWithScore(boxes, scores, maxOutputSize, iouThreshold?, scoreThreshold?, softNmsSigma?)
Parameters:
- 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
import * as tf from "@tensorflow/tfjs"
// Calling image.nonMaxSuppressionWithScore() method
const output = tf.image.nonMaxSuppressionWithScore(
tf.tensor2d([1, 2, 3, 4, 2, 4, 6, 7],
[2, 4]), [1, 1], 4
);
// Printing output
console.log(output);輸出:
{
"selectedIndices":{
"kept":false,
"isDisposedInternal":false,
"shape":[
2
],
"dtype":"int32",
"size":2,
"strides":[],
"dataId":{
"id":74
},
"id":74,
"rankType":"1",
"scopeId":35
},
"selectedScores":{
"kept":false,
"isDisposedInternal":false,
"shape":[
2
],
"dtype":"float32",
"size":2,
"strides":[],
"dataId":{
"id":75
},
"id":75,
"rankType":"1",
"scopeId":35
}
}範例2:在此示例中,我們將使用浮點數數組 iouThreshold、scoreThreshold 以及 softNmsSigma。
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.nonMaxSuppressionWithScore() method
const res = tf.image.nonMaxSuppressionWithScore(
arr, [2.1, 0], 100, 0.5, 1, 0.5);
// Printing output
console.log(res);輸出:
{
"selectedIndices":{
"kept":false,
"isDisposedInternal":false,
"shape":[
1
],
"dtype":"int32",
"size":1,
"strides":[],
"dataId":{
"id":84
},
"id":84,
"rankType":"1",
"scopeId":42
},
"selectedScores":{
"kept":false,
"isDisposedInternal":false,
"shape":[
1
],
"dtype":"float32",
"size":1,
"strides":[],
"dataId":{
"id":85
},
"id":85,
"rankType":"1",
"scopeId":42
}
}參考: https://js.tensorflow.org/api/latest/#image.nonMaxSuppressionWithScore
相關用法
- 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()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Tensorflow.js tf.image.nonMaxSuppressionWithScore() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
