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.
// 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) |
Output:
undefined
Example 2: Example to get Opmapper object for user override Op.
// 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) |
Output:
{ tfOpName: [Function: add], category: 'custom', inputs: [], attrs: [], customExecutor: [Function: sub] }
Example 3: Example to get Opmapper object for user-defined user-registered Op.
// 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) |
Output:
{ tfOpName: 'NewOp', category: 'custom', inputs: [], attrs: [], customExecutor: [Function: customOp] }
Reference: https://js.tensorflow.org/api/latest/#getRegisteredOp