UNPKG

2.14 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 */
17import { OpExecutor, OpMapper } from '../types';
18/**
19 * Register an Op for graph model executor. This allow you to register
20 * TensorFlow custom op or override existing op.
21 *
22 * Here is an example of registering a new MatMul Op.
23 * ```js
24 * const customMatmul = (node) =>
25 * tf.matMul(
26 * node.inputs[0], node.inputs[1],
27 * node.attrs['transpose_a'], node.attrs['transpose_b']);
28 *
29 * tf.registerOp('MatMul', customMatmul);
30 * ```
31 * The inputs and attrs of the node object is based on the TensorFlow op
32 * registry.
33 *
34 * @param name The Tensorflow Op name.
35 * @param opFunc An op function which is called with the current graph node
36 * during execution and needs to return a tensor or a list of tensors. The node
37 * has the following attributes:
38 * - attr: A map from attribute name to its value
39 * - inputs: A list of input tensors
40 *
41 * @doc {heading: 'Models', subheading: 'Op Registry'}
42 */
43export declare function registerOp(name: string, opFunc: OpExecutor): void;
44/**
45 * Retrieve the OpMapper object for the registered op.
46 *
47 * @param name The Tensorflow Op name.
48 *
49 * @doc {heading: 'Models', subheading: 'Op Registry'}
50 */
51export declare function getRegisteredOp(name: string): OpMapper;
52/**
53 * Deregister the Op for graph model executor.
54 *
55 * @param name The Tensorflow Op name.
56 *
57 * @doc {heading: 'Models', subheading: 'Op Registry'}
58 */
59export declare function deregisterOp(name: string): void;