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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。