UNPKG

2.23 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2019 Google LLC. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * =============================================================================
16 */
17/// <amd-module name="@tensorflow/tfjs-converter/dist/operations/custom_op/register" />
18import { OpExecutor, OpMapper } from '../types';
19/**
20 * Register an Op for graph model executor. This allow you to register
21 * TensorFlow custom op or override existing op.
22 *
23 * Here is an example of registering a new MatMul Op.
24 * ```js
25 * const customMatmul = (node) =>
26 * tf.matMul(
27 * node.inputs[0], node.inputs[1],
28 * node.attrs['transpose_a'], node.attrs['transpose_b']);
29 *
30 * tf.registerOp('MatMul', customMatmul);
31 * ```
32 * The inputs and attrs of the node object is based on the TensorFlow op
33 * registry.
34 *
35 * @param name The Tensorflow Op name.
36 * @param opFunc An op function which is called with the current graph node
37 * during execution and needs to return a tensor or a list of tensors. The node
38 * has the following attributes:
39 * - attr: A map from attribute name to its value
40 * - inputs: A list of input tensors
41 *
42 * @doc {heading: 'Models', subheading: 'Op Registry'}
43 */
44export declare function registerOp(name: string, opFunc: OpExecutor): void;
45/**
46 * Retrieve the OpMapper object for the registered op.
47 *
48 * @param name The Tensorflow Op name.
49 *
50 * @doc {heading: 'Models', subheading: 'Op Registry'}
51 */
52export declare function getRegisteredOp(name: string): OpMapper;
53/**
54 * Deregister the Op for graph model executor.
55 *
56 * @param name The Tensorflow Op name.
57 *
58 * @doc {heading: 'Models', subheading: 'Op Registry'}
59 */
60export declare function deregisterOp(name: string): void;