Tensorflow.js是Google开发的一个开源库,主要用于在浏览器或节点环境中运行机器学习模型和深度学习神经网络。
Tensorflow.js tf.deregisterOp() 函数用于从 TensorFlow 中注销图模型执行器的 Ops(操作)。它的行为与 Tensorflow.j tf.registerOp() 函数相反。
用法:
tf.deregisterOp(name)
参数:以下是上述函数接受的参数,如下所示:
- name:这是字符串类型参数。此参数接受 Tensorflow Op 名称。
返回值:该函数不返回任何值。
示例 1:使用检查代码注销新注册的 Op 的示例。
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
tf.registerOp('NewOp', customOp);
// Check registerOp NewOp
const x = tf.getRegisteredOp('NewOp');
console.log("Before deregister:", x)
// Try to deregister NewOp
tf.deregisterOp('NewOp');
// Check deregisterOp NewOp
const y = tf.getRegisteredOp('NewOp');
console.log("After deregister:", y)
// Check Op functioning after get deregistered
const a = tf.scalar(1);
const b = tf.tensor1d([1, 2, 3, 4]);
const ans = y.customExecutor({ "inputs": [a, b] });
console.log(ans.print())输出:
Before deregister: {
tfOpName: 'NewOp',
category: 'custom',
inputs: [],
attrs: [],
customExecutor: [Function: customOp]
}
After deregister: undefined
============================
tensorflow1.js:27
const ans = y.customExecutor({"inputs":[a,b]});
^
TypeError: Cannot read properties of undefined (reading 'customExecutor')
示例 2:使用检查代码注销新覆盖的 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);
const a = tf.tensor1d([10, 20, 30, 40]);
const b = tf.scalar(5);
// Check overridden Op
const x = tf.getRegisteredOp(tf.add);
console.log("Before deregister:", x)
// Check Op functioning before get deregistered
let ans = x.customExecutor(a, b);
console.log(ans.print());
// Try to deregister NewOp
tf.deregisterOp(tf.add);
// Check deregisterOp NewOp
const y = tf.getRegisteredOp(tf.add);
console.log("\nAfter deregister:", y)
// Check Op functioning after get deregistered
ans = y.customExecutor(a, b);
console.log(ans.print());输出:
Before deregister: {
tfOpName: [Function: add],
category: 'custom',
inputs: [],
attrs: [],
customExecutor: [Function: sub]
}
Tensor
[5, 15, 25, 35]
undefined
After deregister: undefined
============================
tensorflow1.js:26
ans = y.customExecutor(a,b);
^
TypeError: Cannot read properties of undefined (reading 'customExecutor')
示例 3:尝试使用检查代码取消注册内置函数的示例。
Javascript
// Importing the tensorflow.js library
const tf = require("@tensorflow/tfjs");
const a = tf.tensor1d([10, 20, 30, 40]);
const b = tf.scalar(5);
// Before get deregistered
console.log("Before deregister:")
let ans = tf.add(a, b);
console.log(ans.print());
// Try to deregister build-in
tf.deregisterOp(tf.add);
// After get deregistered
console.log("\nAfter deregister:")
ans = tf.add(a, b);
console.log(ans.print());输出:
Before deregister:
Tensor
[15, 25, 35, 45]
undefined
After deregister:
Tensor
[15, 25, 35, 45]
undefined
参考:https://js.tensorflow.org/api/latest/#deregisterOp
相关用法
- Tensorflow.js tf.depthToSpace()用法及代码示例
- Tensorflow.js tf.decodeString()用法及代码示例
- Tensorflow.js tf.depthwiseConv2d()用法及代码示例
- Tensorflow.js tf.denseBincount()用法及代码示例
- Tensorflow.js tf.dot()用法及代码示例
- Tensorflow.js tf.dispose()用法及代码示例
- Tensorflow.js tf.div()用法及代码示例
- Tensorflow.js tf.divNoNan()用法及代码示例
- Tensorflow.js tf.data.zip()用法及代码示例
- Tensorflow.js tf.data.webcam()用法及代码示例
- Tensorflow.js tf.data.generator()用法及代码示例
- Tensorflow.js tf.dropout()用法及代码示例
- Tensorflow.js tf.data.microphone()用法及代码示例
- Tensorflow.js tf.data.csv()用法及代码示例
- Tensorflow.js tf.data.Dataset.forEachAsync()用法及代码示例
- Tensorflow.js tf.data.Dataset.prefetch()用法及代码示例
- Tensorflow.js tf.data.Dataset.shuffle()用法及代码示例
- Tensorflow.js tf.data.Dataset.concatenate()用法及代码示例
- Tensorflow.js tf.data.Dataset.filter()用法及代码示例
- Tensorflow.js tf.data.Dataset.map()用法及代码示例
- Tensorflow.js tf.data.Dataset.skip()用法及代码示例
- Tensorflow.js tf.data.Dataset.batch()用法及代码示例
- Tensorflow.js tf.data.array()用法及代码示例
- Tensorflow.js tf.dilation2d()用法及代码示例
- Tensorflow.js tf.disposeVariables()用法及代码示例
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Tensorflow.js tf.deregisterOp() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
