簡介:Tensorflow.js 是 Google 開發的一個開源庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。
.nextFrame() 函數用於返回確定 requestAnimationFrame 已終止的承諾。
注意:
- 在 Node.js 中,此方法應用 setImmediate 代替 requestAnimationFrame。
- 此外,它是一種基本的糖方法,用戶可以執行以下操作:await tf.nextFrame()。
用法:
tf.nextFrame()
參數:該方法不持有任何參數。
返回值:它返回無效的承諾。
範例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Using for loop
for(let i = 0; i < 5; i++){
// Calling nextFrame() method
await tf.nextFrame();
// Printing output
console.log('*****');
}
輸出:在這裏,由於 nextFrame 方法,星星被一一打印。
***** ***** ***** ***** *****
範例2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Using for loop
for(let i = 0; i < 3; i++){
// Calling randomNormal() method
const x = tf.randomNormal([2, 3]);
// Calling nextFrame() method
await tf.nextFrame();
// Printing output
console.log(x);
}
輸出:在這裏,如果您多次快速運行程序,那麽在處理張量時會發生錯誤。
Tensor [[-1.2814652, 0.0379729, 1.4826748], [1.5050254 , 0.0769796, 0.5443317]] Tensor [[-1.9229894, 0.2478886 , 0.6501164], [0.3088476 , -1.0728339, 0.8636787]] Tensor [[-0.2324371, -1.2162384, 0.3193687], [0.0266885 , 1.3987972 , 0.4429231]]
參考:https://js.tensorflow.org/api/latest/#nextFrame
相關用法
- 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.nextFrame() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。