當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Tensorflow.js tf.enableDebugMode()用法及代碼示例

Tensorflow.js是由Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。

.enableDebugMode() 函數用於啟用調試模式,該模式將注冊有關每個執行的內核的數據,即內核實現的運行時間,包括結果張量的等級、大小和形狀。

注意:

  • 調試模式會大大降低我們軟件的速度,因為它會下載 CPU 中每個動作的最終結果,而這些動作不能在生產中使用。
  • Debug 模式不會影響內核性能的時序數據,因為這裏的下載時間不是在內核性能時間中評估的。

用法:

tf.enableDebugMode() 

Parameters: 該方法不持有任何參數。



返回值:它返回void。

範例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling enableDebugMode() method
await tf.enableDebugMode();
  
// Setting prod mode of the
// environment
tf.env().set('PROD', false);
  
// Printing output
console.log(tf.env().flags);

輸出:

{
  "IS_BROWSER":true,
  "IS_NODE":false,
  "DEBUG":true,
  "CPU_HANDOFF_SIZE_THRESHOLD":128,
  "PROD":false
}

範例2:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling enableDebugMode() method
await tf.enableDebugMode();
  
// Setting debug mode of the environment
tf.env().set("DEBUG", !0)
  
// Setting textures of the environment
tf.env().set('WEBGL_FORCE_F16_TEXTURES', true);
  
// Calling ready() method
await tf.ready();
  
// Printing output
console.log(tf.env().features);

輸出:

{
  "IS_BROWSER":true,
  "IS_NODE":false,
  "DEBUG":true,
  "CPU_HANDOFF_SIZE_THRESHOLD":128,
  "PROD":true,
  "WEBGL_FORCE_F16_TEXTURES":true,
  "WEBGL_VERSION":2,
  "HAS_WEBGL":true
}

參考:https://js.tensorflow.org/api/latest/#enableDebugMode




相關用法


注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Tensorflow.js tf.enableDebugMode() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。