Tensorflow.js tf.getRegisteredOp() Function
Last Updated :
06 Oct, 2022
Tensorflow.js is an open-source library developed by Google for mainly running machine learning models and deep learning neural networks in the browser or node environment.
Tensorflow.js tf.getRegisteredOp() function is used to get the OpMapper object of the registered an Ops(operations) in TensorFlow.
Syntax:
tf.getRegisteredOp(name)
Parameters: Following are the parameters accepted by the above function and the same are illustrated below:
- name: This is the string type parameter. This parameter accepts the Tensorflow Op name.
Return Value: It returns the OpMapper object if present or else undefined.
Example 1: Example to get Opmapper object for build-in function.
Javascript
const tf = require( "@tensorflow/tfjs" );
const x = tf.getRegisteredOp(tf.add);
console.log(x)
|
Output:
undefined
Example 2: Example to get Opmapper object for user override Op.
Javascript
const tf = require( "@tensorflow/tfjs" );
tf.registerOp(tf.add, tf.sub);
const x = tf.getRegisteredOp(tf.add);
console.log(x)
|
Output:
{
tfOpName: [Function: add],
category: 'custom',
inputs: [],
attrs: [],
customExecutor: [Function: sub]
}
Example 3: Example to get Opmapper object for user-defined user-registered Op.
Javascript
const tf = require( "@tensorflow/tfjs" );
const customOp = (node) =>
tf.add(
node.inputs[0], node.inputs[1]
);
const x = tf.registerOp( 'NewOp' , customOp);
const name = tf.getRegisteredOp( 'NewOp' );
console.log(name)
|
Output:
{
tfOpName: 'NewOp',
category: 'custom',
inputs: [],
attrs: [],
customExecutor: [Function: customOp]
}
Reference: https://js.tensorflow.org/api/latest/#getRegisteredOp
Share your thoughts in the comments
Please Login to comment...