Tensorflow.js是Google開發的一個開源庫,主要用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。
Tensorflow.js tf.getRegisteredOp()函數用於獲取TensorFlow中注冊的Ops(操作)的OpMapper對象。
用法:
tf.getRegisteredOp(name)
參數:以下是上述函數接受的參數,如下所示:
- name:這是字符串類型參數。此參數接受 Tensorflow Op 名稱。
返回值:如果存在,則返回 OpMapper 對象,否則返回未定義。
示例 1:獲取內置函數的 Opmapper 對象的示例。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs");
// Use of getRegisteredOp() function
const x = tf.getRegisteredOp(tf.add);
// Print OpMapper object if present.
console.log(x)輸出:
undefined
示例 2:獲取 Opmapper 對象以供用戶覆蓋 Op 的示例。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs");
// Try to override add Op with sub op
tf.registerOp(tf.add, tf.sub);
// Use of getRegisteredOp() function
const x = tf.getRegisteredOp(tf.add);
// Print OpMapper object if present
console.log(x)輸出:
{
tfOpName: [Function: add],
category: 'custom',
inputs: [],
attrs: [],
customExecutor: [Function: sub]
}
示例 3:獲取用戶定義的 user-registered Op 的 Opmapper 對象的示例。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs");
// Try to create a new Op
const customOp = (node) =>
tf.add(
node.inputs[0], node.inputs[1]
);
// Try to register a new Op NewOp
const x = tf.registerOp('NewOp', customOp);
// Use of getRegisteredOp() function
const name = tf.getRegisteredOp('NewOp');
// Print OpMapper object if present
console.log(name)輸出:
{
tfOpName: 'NewOp',
category: 'custom',
inputs: [],
attrs: [],
customExecutor: [Function: customOp]
}
參考:https://js.tensorflow.org/api/latest/#getRegisteredOp
相關用法
- Tensorflow.js tf.getBackend()用法及代碼示例
- Tensorflow.js tf.greater()用法及代碼示例
- Tensorflow.js tf.greaterEqual()用法及代碼示例
- Tensorflow.js tf.grads()用法及代碼示例
- Tensorflow.js tf.gatherND()用法及代碼示例
- Tensorflow.js tf.grad()用法及代碼示例
- Tensorflow.js tf.gather()用法及代碼示例
- Tensorflow.js tf.depthToSpace()用法及代碼示例
- Tensorflow.js tf.abs()用法及代碼示例
- Tensorflow.js tf.acos()用法及代碼示例
- Tensorflow.js tf.acosh()用法及代碼示例
- Tensorflow.js tf.asin()用法及代碼示例
- Tensorflow.js tf.asinh()用法及代碼示例
- Tensorflow.js tf.atan()用法及代碼示例
- Tensorflow.js tf.atan2()用法及代碼示例
- Tensorflow.js tf.atanh()用法及代碼示例
- Tensorflow.js tf.equal()用法及代碼示例
- Tensorflow.js tf.less()用法及代碼示例
- Tensorflow.js tf.lessEqual()用法及代碼示例
- Tensorflow.js tf.logicalAnd()用法及代碼示例
- Tensorflow.js tf.logicalNot()用法及代碼示例
- Tensorflow.js tf.logicalOr()用法及代碼示例
- Tensorflow.js tf.logicalXor()用法及代碼示例
- Tensorflow.js tf.onesLike()用法及代碼示例
- Tensorflow.js tf.print()用法及代碼示例
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Tensorflow.js tf.getRegisteredOp() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
