TensorFlow source

This commit is contained in:
Brenden Harrell committed 2021-05-25 09:27:30 -05:00
1 parent 12d53f218e
commit 938b5fbfb4
919 files changed
+85903

No files matched your search

@@ -0,0 +1,32 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {Exp, ExpInputs, KernelConfig, Tensor} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const expConfig: KernelConfig = {
kernelName: Exp,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as ExpInputs;
const backend = args.backend as NodeJSKernelBackend;
const xTensor = x.dtype === 'int32' ? (x as Tensor).toFloat() : x;
return backend.executeSingleInput(Exp, xTensor);
}
};
@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {ExpandDims, ExpandDimsAttrs, ExpandDimsInputs, KernelConfig, scalar} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const expandDimsConfig: KernelConfig = {
kernelName: ExpandDims,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {input} = args.inputs as ExpandDimsInputs;
const backend = args.backend as NodeJSKernelBackend;
const {dim} = args.attrs as {} as ExpandDimsAttrs;
const dimTensor = scalar(dim, 'int32');
const res = backend.executeSingleOutput(ExpandDims, [], [input, dimTensor]);
dimTensor.dispose();
return res;
}
};
@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {Expm1, Expm1Inputs, KernelConfig} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const expm1Config: KernelConfig = {
kernelName: Expm1,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as Expm1Inputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Expm1, x);
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {FFT, FFTInputs, KernelConfig} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
// tslint:disable-next-line: variable-name
export const FFTConfig: KernelConfig = {
kernelName: FFT,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {input} = args.inputs as FFTInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr('Tcomplex', input.dtype)];
return backend.executeSingleOutput(FFT, opAttrs, [input]);
}
};
@@ -0,0 +1,60 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {Fill, FillAttrs, KernelConfig, scalar, tensor1d} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const fillConfig: KernelConfig = {
kernelName: Fill,
backendName: 'tensorflow',
kernelFunc: (args) => {
const backend = args.backend as NodeJSKernelBackend;
const {shape, value} = args.attrs as {} as FillAttrs;
let {dtype} = args.attrs as {} as FillAttrs;
// TODO(cais, nkreeger): Investigate whether backend can be made into
// a dtype helper method. The underlying op kernel doesn't accept undefined
// or null dtype.
if (dtype == null) {
if (typeof value === 'number') {
dtype = 'float32';
} else {
dtype = 'string';
}
}
const shapeTensor = tensor1d(shape, 'int32');
const valueTensor = scalar(value, dtype);
const opAttrs = [
{
name: 'T',
type: backend.binding.TF_ATTR_TYPE,
value: backend.getDTypeInteger(dtype)
},
{
name: 'index_type',
type: backend.binding.TF_ATTR_TYPE,
value: backend.binding.TF_INT32
}
];
const res =
backend.executeSingleOutput(Fill, opAttrs, [shapeTensor, valueTensor]);
shapeTensor.dispose();
valueTensor.dispose();
return res;
}
};
@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {Floor, FloorInputs, KernelConfig} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const floorConfig: KernelConfig = {
kernelName: Floor,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as FloorInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Floor, x);
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, FloorDiv, FloorDivInputs, KernelConfig} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const floorDivConfig: KernelConfig = {
kernelName: FloorDiv,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as FloorDivInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(FloorDiv, opAttrs, [a, b]);
}
};
@@ -0,0 +1,70 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {add, fill, FusedBatchNorm, FusedBatchNormAttrs, FusedBatchNormInputs, KernelConfig, mul, Rank, rsqrt, scalar, sub, Tensor, Tensor4D, tidy} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const fusedBatchNormConfig: KernelConfig = {
kernelName: FusedBatchNorm,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x, mean, variance} = args.inputs as FusedBatchNormInputs;
let {scale, offset} = args.inputs as FusedBatchNormInputs;
const backend = args.backend as NodeJSKernelBackend;
const {varianceEpsilon} = args.attrs as {} as FusedBatchNormAttrs;
return tidy(() => {
if ((mean as Tensor).rank > 1) {
// Fused batch norm doesn't work with high-dim mean/var/scale/offset.
let inv = rsqrt(add(variance as Tensor, scalar(varianceEpsilon)));
if (scale != null) {
inv = mul(inv, scale as Tensor);
}
const xNorm: Tensor4D = mul(sub(x as Tensor, mean as Tensor), inv);
return offset != null ? add(xNorm, offset as Tensor) : xNorm;
}
const dataFormat = 'NHWC';
const depth = x.shape[3];
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
{
name: 'epsilon',
type: backend.binding.TF_ATTR_FLOAT,
value: varianceEpsilon
},
{
name: 'data_format',
type: backend.binding.TF_ATTR_STRING,
value: dataFormat
},
{name: 'is_training', type: backend.binding.TF_ATTR_BOOL, value: false},
];
const numOutputs = 5;
if (scale == null) {
scale = fill<Rank.R1>([depth], 1);
}
if (offset == null) {
offset = fill<Rank.R1>([depth], 0);
}
return backend.executeMultipleOutputs(
FusedBatchNorm, opAttrs, [x, scale, offset, mean, variance],
numOutputs)[0];
});
}
};
@@ -0,0 +1,65 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {add, backend_util, FusedConv2D, FusedConv2DAttrs, FusedConv2DInputs, KernelConfig, Tensor} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
import {conv2dImpl} from './Conv2D';
export const fusedConv2DConfig: KernelConfig = {
kernelName: FusedConv2D,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x, filter, bias, preluActivationWeights} =
args.inputs as FusedConv2DInputs;
const backend = args.backend as NodeJSKernelBackend;
const {
strides,
pad,
dataFormat,
dilations,
dimRoundingMode,
activation,
leakyreluAlpha
} = args.attrs as {} as FusedConv2DAttrs;
const $dataFormat = backend_util.convertConv2DDataFormat(dataFormat);
const convInfo = backend_util.computeConv2DInfo(
x.shape as [number, number, number, number],
filter.shape as [number, number, number, number], strides, dilations,
pad, dimRoundingMode, false /* depthwise */, $dataFormat);
let result = conv2dImpl(x, filter, convInfo, backend);
const toDispose = [];
if (bias != null) {
toDispose.push(result);
result = add(result, bias as Tensor);
}
const temp = result;
result = backend.applyActivation(
result, activation, preluActivationWeights as Tensor, leakyreluAlpha);
if (temp !== result) {
toDispose.push(temp);
}
toDispose.forEach(t => t.dispose());
return result;
}
};
@@ -0,0 +1,68 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {add, backend_util, FusedDepthwiseConv2D, FusedDepthwiseConv2DAttrs, FusedDepthwiseConv2DInputs, KernelConfig, Tensor} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
import {depthwiseConv2dNativeImpl} from './DepthwiseConv2dNative';
export const fusedDepthwiseConv2DConfig: KernelConfig = {
kernelName: FusedDepthwiseConv2D,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x, filter, bias, preluActivationWeights} =
args.inputs as FusedDepthwiseConv2DInputs;
const backend = args.backend as NodeJSKernelBackend;
const {
strides,
pad,
dilations,
dimRoundingMode,
activation,
leakyreluAlpha
} = args.attrs as {} as FusedDepthwiseConv2DAttrs;
let $dilations = dilations;
if ($dilations == null) {
$dilations = [1, 1];
}
const convInfo = backend_util.computeConv2DInfo(
x.shape as [number, number, number, number],
filter.shape as [number, number, number, number], strides, $dilations,
pad, dimRoundingMode, true /* depthwise */);
let result = depthwiseConv2dNativeImpl(x, filter, convInfo, backend);
const toDispose = [];
if (bias != null) {
toDispose.push(result);
result = add(result, bias as Tensor);
}
const temp = result;
result = backend.applyActivation(
result, activation, preluActivationWeights as Tensor, leakyreluAlpha);
if (temp !== result) {
toDispose.push(temp);
}
toDispose.forEach(t => t.dispose());
return result;
}
};
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {GatherNd, GatherNdInputs, KernelConfig} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const gatherNdConfig: KernelConfig = {
kernelName: GatherNd,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {params, indices} = args.inputs as GatherNdInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [
createTensorsTypeOpAttr('Tparams', params.dtype),
createTensorsTypeOpAttr('Tindices', 'int32')
];
return backend.executeSingleOutput(GatherNd, opAttrs, [params, indices]);
}
};
@@ -0,0 +1,47 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, GatherV2, GatherV2Attrs, GatherV2Inputs, KernelConfig, scalar, Tensor} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const gatherV2Config: KernelConfig = {
kernelName: GatherV2,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x, indices} = args.inputs as GatherV2Inputs;
const backend = args.backend as NodeJSKernelBackend;
const {axis, batchDims} = args.attrs as {} as GatherV2Attrs;
// validate the inputs
backend_util.segment_util.collectGatherOpShapeInfo(
x as Tensor, indices as Tensor, axis, batchDims);
const axisTensor = scalar(axis, 'int32');
const opAttrs = [
{name: 'batch_dims', type: backend.binding.TF_ATTR_INT, value: batchDims},
createTensorsTypeOpAttr('Tparams', x.dtype),
createTensorsTypeOpAttr('Tindices', indices.dtype),
createTensorsTypeOpAttr('Taxis', 'int32')
];
const res = backend.executeSingleOutput(
GatherV2, opAttrs, [x, indices, axisTensor]);
axisTensor.dispose();
return res;
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, Greater, GreaterInputs, KernelConfig} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const greaterConfig: KernelConfig = {
kernelName: Greater,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as GreaterInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(Greater, opAttrs, [a, b]);
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, GreaterEqual, GreaterEqualInputs, KernelConfig} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const greaterEqualConfig: KernelConfig = {
kernelName: GreaterEqual,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as GreaterEqualInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(GreaterEqual, opAttrs, [a, b]);
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {IFFT, IFFTInputs, KernelConfig} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
// tslint:disable-next-line: variable-name
export const IFFTConfig: KernelConfig = {
kernelName: IFFT,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {input} = args.inputs as IFFTInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr('Tcomplex', input.dtype)];
return backend.executeSingleOutput(IFFT, opAttrs, [input]);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {Identity, IdentityInputs, KernelConfig} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const identityConfig: KernelConfig = {
kernelName: Identity,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as IdentityInputs;
// Backend needs to track refCount for the dataId for identity op
(args.backend as NodeJSKernelBackend).incRef(x.dataId);
return {dataId: x.dataId, shape: x.shape, dtype: x.dtype};
}
};
@@ -0,0 +1,44 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {Imag, ImagInputs, KernelConfig} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const imagConfig: KernelConfig = {
kernelName: Imag,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {input} = args.inputs as ImagInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [
{
name: 'T',
type: backend.binding.TF_ATTR_TYPE,
value: backend.binding.TF_COMPLEX64
},
{
name: 'Tout',
type: backend.binding.TF_ATTR_TYPE,
value: backend.binding.TF_FLOAT
}
];
const inputs = [input];
return backend.executeSingleOutput(Imag, opAttrs, inputs);
}
};
@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {IsFinite, IsFiniteInputs, KernelConfig} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const isFiniteConfig: KernelConfig = {
kernelName: IsFinite,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as IsFiniteInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(IsFinite, x);
}
};
@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {IsInf, IsInfInputs, KernelConfig} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const isInfConfig: KernelConfig = {
kernelName: IsInf,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as IsInfInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(IsInf, x);
}
};
@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {IsNan, IsNanInputs, KernelConfig} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const isNanConfig: KernelConfig = {
kernelName: IsNan,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as IsNanInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(IsNan, x);
}
};
@@ -0,0 +1,44 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, LRN, LRNAttrs, LRNInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
// tslint:disable-next-line: variable-name
export const LRNConfig: KernelConfig = {
kernelName: LRN,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as LRNInputs;
const backend = args.backend as NodeJSKernelBackend;
const {depthRadius, bias, alpha, beta} = args.attrs as {} as LRNAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
{
name: 'depth_radius',
type: backend.binding.TF_ATTR_INT,
value: depthRadius
},
{name: 'bias', type: backend.binding.TF_ATTR_FLOAT, value: bias},
{name: 'alpha', type: backend.binding.TF_ATTR_FLOAT, value: alpha},
{name: 'beta', type: backend.binding.TF_ATTR_FLOAT, value: beta},
];
return backend.executeSingleOutput(LRN, opAttrs, [x]);
}
};
@@ -0,0 +1,44 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, LRNGrad, LRNGradAttrs, LRNGradInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
// tslint:disable-next-line: variable-name
export const LRNGradConfig: KernelConfig = {
kernelName: LRNGrad,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x, y, dy} = args.inputs as LRNGradInputs;
const backend = args.backend as NodeJSKernelBackend;
const {depthRadius, bias, alpha, beta} = args.attrs as {} as LRNGradAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', dy.dtype),
{
name: 'depth_radius',
type: backend.binding.TF_ATTR_INT,
value: depthRadius
},
{name: 'bias', type: backend.binding.TF_ATTR_FLOAT, value: bias},
{name: 'alpha', type: backend.binding.TF_ATTR_FLOAT, value: alpha},
{name: 'beta', type: backend.binding.TF_ATTR_FLOAT, value: beta},
];
return backend.executeSingleOutput(LRNGrad, opAttrs, [dy, x, y]);
}
};
@@ -0,0 +1,38 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, LeakyRelu, LeakyReluAttrs, LeakyReluInputs, Tensor} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const leakyReluConfig: KernelConfig = {
kernelName: LeakyRelu,
backendName: 'tensorflow',
kernelFunc: (args) => {
const inputs = args.inputs as LeakyReluInputs;
const attrs = args.attrs as {} as LeakyReluAttrs;
const backend = args.backend as NodeJSKernelBackend;
const x = inputs.x as Tensor;
const alpha = attrs.alpha;
const opAttrs = [
{name: 'alpha', type: backend.binding.TF_ATTR_FLOAT, value: alpha},
createTensorsTypeOpAttr('T', x.dtype)
];
return backend.executeSingleOutput(LeakyRelu, opAttrs, [x]);
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, Less, LessInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const lessConfig: KernelConfig = {
kernelName: Less,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as LessInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(Less, opAttrs, [a, b]);
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, LessEqual, LessEqualInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const lessEqualConfig: KernelConfig = {
kernelName: LessEqual,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as LessEqualInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(LessEqual, opAttrs, [a, b]);
}
};
@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, LinSpace, LinSpaceAttrs, scalar, tidy} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const linSpaceConfig: KernelConfig = {
kernelName: LinSpace,
backendName: 'tensorflow',
kernelFunc: (args) => {
const backend = args.backend as NodeJSKernelBackend;
const {start, stop, num} = args.attrs as {} as LinSpaceAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', 'float32'),
createTensorsTypeOpAttr('Tidx', 'int32')
];
return tidy(() => {
const inputs = [
scalar(start, 'float32'), scalar(stop, 'float32'), scalar(num, 'int32')
];
return backend.executeSingleOutput(LinSpace, opAttrs, inputs);
});
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Log, LogInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const logConfig: KernelConfig = {
kernelName: Log,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as LogInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Log, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Log1p, Log1pInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const log1pConfig: KernelConfig = {
kernelName: Log1p,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as Log1pInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Log1p, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, LogicalAnd, LogicalAndInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const logicalAndConfig: KernelConfig = {
kernelName: LogicalAnd,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as LogicalAndInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleOutput(LogicalAnd, [], [a, b]);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, LogicalNot, LogicalNotInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const logicalNotConfig: KernelConfig = {
kernelName: LogicalNot,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as LogicalNotInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleOutput(LogicalNot, [], [x]);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, LogicalOr, LogicalOrInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const logicalOrConfig: KernelConfig = {
kernelName: LogicalOr,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as LogicalOrInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleOutput(LogicalOr, [], [a, b]);
}
};
@@ -0,0 +1,37 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Max, MaxAttrs, MaxInputs, tensor1d, util} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const maxConfig: KernelConfig = {
kernelName: Max,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as MaxInputs;
const backend = args.backend as NodeJSKernelBackend;
const {reductionIndices, keepDims} = args.attrs as {} as MaxAttrs;
const axes = util.parseAxisParam(reductionIndices, x.shape);
const axesTensor = tensor1d(axes, 'int32');
const res = backend.executeSingleOutput(
Max, backend.createReductionOpAttrs(x, keepDims), [x, axesTensor]);
axesTensor.dispose();
return res;
}
};
@@ -0,0 +1,56 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, MaxPool, MaxPoolAttrs, MaxPoolInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const maxPoolConfig: KernelConfig = {
kernelName: MaxPool,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as MaxPoolInputs;
const backend = args.backend as NodeJSKernelBackend;
const {filterSize, strides, pad, dimRoundingMode} =
args.attrs as {} as MaxPoolAttrs;
const convInfo = backend_util.computePool2DInfo(
x.shape as [number, number, number, number], filterSize, strides,
1 /* dilations */, pad, dimRoundingMode);
if (convInfo.padInfo.type !== 'VALID' && convInfo.padInfo.type !== 'SAME') {
throw new Error(
`TF Backend supports only 'valid' and 'same' padding ` +
`while padding was ${convInfo.padInfo.type}`);
}
const ksize = [1, convInfo.filterHeight, convInfo.filterWidth, 1];
const $strides = [1, convInfo.strideHeight, convInfo.strideWidth, 1];
const padding = convInfo.padInfo.type;
const dataFormat = convInfo.dataFormat === 'channelsLast' ? 'NHWC' : 'NCHW';
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
{name: 'ksize', type: backend.binding.TF_ATTR_INT, value: ksize},
{name: 'strides', type: backend.binding.TF_ATTR_INT, value: $strides},
{name: 'padding', type: backend.binding.TF_ATTR_STRING, value: padding}, {
name: 'data_format',
type: backend.binding.TF_ATTR_STRING,
value: dataFormat
}
];
return backend.executeSingleOutput(MaxPool, opAttrs, [x]);
}
};
@@ -0,0 +1,60 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, MaxPool3D, MaxPool3DAttrs, MaxPool3DInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const maxPool3DConfig: KernelConfig = {
kernelName: MaxPool3D,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as MaxPool3DInputs;
const backend = args.backend as NodeJSKernelBackend;
const {filterSize, strides, pad, dataFormat, dimRoundingMode} =
args.attrs as {} as MaxPool3DAttrs;
const convInfo = backend_util.computePool3DInfo(
x.shape as [number, number, number, number, number], filterSize,
strides, 1 /* dilations */, pad, dimRoundingMode, dataFormat);
if (convInfo.padInfo.type !== 'VALID' && convInfo.padInfo.type !== 'SAME') {
throw new Error(
`TF Backend supports only 'valid' and 'same' padding ` +
`while padding was ${convInfo.padInfo.type}`);
}
const ksize = [
1, convInfo.filterDepth, convInfo.filterHeight, convInfo.filterWidth, 1
];
const $strides = [
1, convInfo.strideDepth, convInfo.strideHeight, convInfo.strideWidth, 1
];
const padding = convInfo.padInfo.type;
const $dataFormat =
convInfo.dataFormat === 'channelsLast' ? 'NDHWC' : 'NCDHW';
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
{name: 'ksize', type: backend.binding.TF_ATTR_INT, value: ksize},
{name: 'strides', type: backend.binding.TF_ATTR_INT, value: $strides},
{name: 'padding', type: backend.binding.TF_ATTR_STRING, value: padding}, {
name: 'data_format',
type: backend.binding.TF_ATTR_STRING,
value: $dataFormat
}
];
return backend.executeSingleOutput(MaxPool3D, opAttrs, [x]);
}
};
@@ -0,0 +1,63 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, MaxPool3DGrad, MaxPool3DGradAttrs, MaxPool3DGradInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const maxPool3DGradConfig: KernelConfig = {
kernelName: MaxPool3DGrad,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {dy, input, output} = args.inputs as MaxPool3DGradInputs;
const backend = args.backend as NodeJSKernelBackend;
const {filterSize, strides, pad, dimRoundingMode} =
args.attrs as {} as MaxPool3DGradAttrs;
const convInfo = backend_util.computePool3DInfo(
input.shape as [number, number, number, number, number], filterSize,
strides, 1 /* dilations */, pad, dimRoundingMode);
if (convInfo.padInfo.type !== 'VALID' && convInfo.padInfo.type !== 'SAME') {
throw new Error(
`TF Backend supports only 'valid' and 'same' padding ` +
`while padding type was ${convInfo.padInfo.type}`);
}
const ksize = [
1, convInfo.filterDepth, convInfo.filterHeight, convInfo.filterWidth, 1
];
const $strides = [
1, convInfo.strideDepth, convInfo.strideHeight, convInfo.strideWidth, 1
];
const padding = convInfo.padInfo.type;
const dataFormat =
convInfo.dataFormat === 'channelsLast' ? 'NDHWC' : 'NCDHW';
const opAttrs = [
createTensorsTypeOpAttr('T', input.dtype),
{name: 'ksize', type: backend.binding.TF_ATTR_INT, value: ksize},
{name: 'strides', type: backend.binding.TF_ATTR_INT, value: $strides},
{name: 'padding', type: backend.binding.TF_ATTR_STRING, value: padding},
{
name: 'data_format',
type: backend.binding.TF_ATTR_STRING,
value: dataFormat
},
];
return backend.executeSingleOutput(
MaxPool3DGrad, opAttrs, [input, output, dy]);
}
};
@@ -0,0 +1,58 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, MaxPoolGrad, MaxPoolGradAttrs, MaxPoolGradInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const maxPoolGradConfig: KernelConfig = {
kernelName: MaxPoolGrad,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {dy, input, output} = args.inputs as MaxPoolGradInputs;
const backend = args.backend as NodeJSKernelBackend;
const {filterSize, strides, pad, dimRoundingMode} =
args.attrs as {} as MaxPoolGradAttrs;
const convInfo = backend_util.computePool2DInfo(
input.shape as [number, number, number, number], filterSize, strides,
1 /* dilations */, pad, dimRoundingMode);
if (convInfo.padInfo.type !== 'VALID' && convInfo.padInfo.type !== 'SAME') {
throw new Error(
`TF Backend supports only 'valid' and 'same' padding ` +
`while padding type was ${convInfo.padInfo.type}`);
}
const ksize = [1, convInfo.filterHeight, convInfo.filterWidth, 1];
const $strides = [1, convInfo.strideHeight, convInfo.strideWidth, 1];
const padding = convInfo.padInfo.type;
const dataFormat = convInfo.dataFormat === 'channelsLast' ? 'NHWC' : 'NCHW';
const opAttrs = [
createTensorsTypeOpAttr('T', input.dtype),
{name: 'ksize', type: backend.binding.TF_ATTR_INT, value: ksize},
{name: 'strides', type: backend.binding.TF_ATTR_INT, value: $strides},
{name: 'padding', type: backend.binding.TF_ATTR_STRING, value: padding},
{
name: 'data_format',
type: backend.binding.TF_ATTR_STRING,
value: dataFormat
},
];
return backend.executeSingleOutput(
MaxPoolGrad, opAttrs, [input, output, dy]);
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, Maximum, MaximumInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const maximumConfig: KernelConfig = {
kernelName: Maximum,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as MaximumInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(Maximum, opAttrs, [a, b]);
}
};
@@ -0,0 +1,42 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {cast, KernelConfig, Mean, MeanAttrs, MeanInputs, Tensor, tensor1d, util} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const meanConfig: KernelConfig = {
kernelName: Mean,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as MeanInputs;
const backend = args.backend as NodeJSKernelBackend;
const {axis, keepDims} = args.attrs as {} as MeanAttrs;
const axes = util.parseAxisParam(axis, x.shape);
const axesTensor = tensor1d(axes, 'int32');
// Cast to float32 to match existing tfjs implementation/tests.
const asFloat32 = cast(x as Tensor, 'float32');
const res = backend.executeSingleOutput(
Mean, backend.createReductionOpAttrs(x, keepDims),
[asFloat32, axesTensor]);
asFloat32.dispose();
axesTensor.dispose();
return res;
}
};
@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Min, MinAttrs, MinInputs, tensor1d, util} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const minConfig: KernelConfig = {
kernelName: Min,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as MinInputs;
const backend = args.backend as NodeJSKernelBackend;
const {axis, keepDims} = args.attrs as {} as MinAttrs;
const axes = util.parseAxisParam(axis, x.shape);
const axesTensor = tensor1d(axes, 'int32');
const res = backend.executeSingleOutput(
Min, backend.createReductionOpAttrs(x, keepDims), [x, axesTensor]);
axesTensor.dispose();
return res;
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, Minimum, MinimumInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const minimumConfig: KernelConfig = {
kernelName: Minimum,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as MinimumInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(Minimum, opAttrs, [a, b]);
}
};
@@ -0,0 +1,49 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, MirrorPad, MirrorPadAttrs, MirrorPadInputs, tensor2d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const mirrorPadConfig: KernelConfig = {
kernelName: MirrorPad,
backendName: 'tensorflow',
kernelFunc: ({inputs, backend, attrs}) => {
const {x} = inputs as MirrorPadInputs;
const {paddings, mode} = attrs as {} as MirrorPadAttrs;
const nodeBackend = backend as NodeJSKernelBackend;
const paddingsTensor = tensor2d(paddings, [paddings.length, 2], 'int32');
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Tpaddings', paddingsTensor.dtype), {
name: 'mode',
type: nodeBackend.binding.TF_ATTR_STRING,
value: mode.toUpperCase()
}
];
const output = nodeBackend.executeSingleOutput(
'MirrorPad', opAttrs, [x, paddingsTensor]);
paddingsTensor.dispose();
return output;
}
};
@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Mod, ModInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const modConfig: KernelConfig = {
kernelName: Mod,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as ModInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr('T', a.dtype)];
return backend.executeSingleOutput('FloorMod', opAttrs, [a, b]);
}
};
@@ -0,0 +1,47 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Multinomial, MultinomialAttrs, MultinomialInputs, scalar} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const multinomialConfig: KernelConfig = {
kernelName: Multinomial,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {logits} = args.inputs as MultinomialInputs;
const backend = args.backend as NodeJSKernelBackend;
const {numSamples, seed, normalized} = args.attrs as {} as MultinomialAttrs;
if (normalized) {
throw new Error(
'TF Node backend does not support normalized logits ' +
'passed to multinomial');
}
const opAttrs = [
createTensorsTypeOpAttr('T', logits.dtype),
createTensorsTypeOpAttr('output_dtype', 'int32'),
{name: 'seed', type: backend.binding.TF_ATTR_INT, value: seed},
{name: 'seed2', type: backend.binding.TF_ATTR_INT, value: seed * seed},
];
const numSamplesTensor = scalar(numSamples, 'int32');
const res = backend.executeSingleOutput(
Multinomial, opAttrs, [logits, numSamplesTensor]);
numSamplesTensor.dispose();
return res;
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, Multiply, MultiplyInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const multiplyConfig: KernelConfig = {
kernelName: Multiply,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as MultiplyInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput('Mul', opAttrs, [a, b]);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Neg, NegInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const negConfig: KernelConfig = {
kernelName: Neg,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as NegInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Neg, x);
}
};
@@ -0,0 +1,45 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, NonMaxSuppressionV3, NonMaxSuppressionV3Attrs, NonMaxSuppressionV3Inputs, scalar} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const nonMaxSuppressionV3Config: KernelConfig = {
kernelName: NonMaxSuppressionV3,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {boxes, scores} = args.inputs as NonMaxSuppressionV3Inputs;
const backend = args.backend as NodeJSKernelBackend;
const {maxOutputSize, iouThreshold, scoreThreshold} =
args.attrs as {} as NonMaxSuppressionV3Attrs;
const opAttrs = [createTensorsTypeOpAttr('T', boxes.dtype)];
const maxOutputSizeTensor = scalar(maxOutputSize, 'int32');
const iouThresholdTensor = scalar(iouThreshold);
const scoreThresholdTensor = scalar(scoreThreshold);
const res = backend.executeSingleOutput(NonMaxSuppressionV3, opAttrs, [
boxes, scores, maxOutputSizeTensor, iouThresholdTensor,
scoreThresholdTensor
]);
maxOutputSizeTensor.dispose();
iouThresholdTensor.dispose();
scoreThresholdTensor.dispose();
return res;
}
};
@@ -0,0 +1,59 @@
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, NonMaxSuppressionV4, NonMaxSuppressionV4Attrs, NonMaxSuppressionV4Inputs, scalar, Tensor1D, Tensor2D} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
// TODO(nsthorat, dsmilkov): Remove dependency on tensors, use dataId.
export const nonMaxSuppressionV4Config: KernelConfig = {
kernelName: NonMaxSuppressionV4,
backendName: 'tensorflow',
kernelFunc: ({inputs, backend, attrs}) => {
const {boxes, scores} = inputs as NonMaxSuppressionV4Inputs;
const {maxOutputSize, iouThreshold, scoreThreshold, padToMaxOutputSize} =
attrs as {} as NonMaxSuppressionV4Attrs;
const maxOutputSizeTensor = scalar(maxOutputSize, 'int32');
const iouThresholdTensor = scalar(iouThreshold, 'float32');
const scoreThresholdTensor = scalar(scoreThreshold, 'float32');
const nodeBackend = backend as NodeJSKernelBackend;
const opAttrs = [
createTensorsTypeOpAttr('T', boxes.dtype),
createTensorsTypeOpAttr('T_threshold', 'float32'), {
name: 'pad_to_max_output_size',
type: nodeBackend.binding.TF_ATTR_BOOL,
value: padToMaxOutputSize
}
];
const [selectedIndices, validOutputs] = nodeBackend.executeMultipleOutputs(
'NonMaxSuppressionV4', opAttrs,
[
boxes as Tensor2D, scores as Tensor1D, maxOutputSizeTensor,
iouThresholdTensor, scoreThresholdTensor
],
2);
maxOutputSizeTensor.dispose();
iouThresholdTensor.dispose();
scoreThresholdTensor.dispose();
return [selectedIndices, validOutputs];
}
};
@@ -0,0 +1,67 @@
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, NamedAttrMap, NamedTensorInfoMap, scalar, Tensor1D, Tensor2D, TensorInfo} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
interface NonMaxSuppressionWithScoreInputs extends NamedTensorInfoMap {
boxes: TensorInfo;
scores: TensorInfo;
}
interface NonMaxSuppressionWithScoreAttrs extends NamedAttrMap {
maxOutputSize: number;
iouThreshold: number;
scoreThreshold: number;
softNmsSigma: number;
}
// TODO(nsthorat, dsmilkov): Remove dependency on tensors, use dataId.
export const nonMaxSuppressionV5Config: KernelConfig = {
kernelName: 'NonMaxSuppressionV5',
backendName: 'tensorflow',
kernelFunc: ({inputs, backend, attrs}) => {
const {boxes, scores} = inputs as NonMaxSuppressionWithScoreInputs;
const {maxOutputSize, iouThreshold, scoreThreshold, softNmsSigma} =
attrs as NonMaxSuppressionWithScoreAttrs;
const maxOutputSizeTensor = scalar(maxOutputSize, 'int32');
const iouThresholdTensor = scalar(iouThreshold);
const scoreThresholdTensor = scalar(scoreThreshold);
const softNmsSigmaTensor = scalar(softNmsSigma);
const opAttrs = [createTensorsTypeOpAttr('T', boxes.dtype)];
const nodeBackend = backend as NodeJSKernelBackend;
const [selectedIndices, selectedScores, validOutputs] =
nodeBackend.executeMultipleOutputs(
'NonMaxSuppressionV5', opAttrs,
[
boxes as Tensor2D, scores as Tensor1D, maxOutputSizeTensor,
iouThresholdTensor, scoreThresholdTensor, softNmsSigmaTensor
],
3);
maxOutputSizeTensor.dispose();
iouThresholdTensor.dispose();
scoreThresholdTensor.dispose();
softNmsSigmaTensor.dispose();
validOutputs.dispose();
return [selectedIndices, selectedScores];
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, NotEqual, NotEqualInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const notEqualConfig: KernelConfig = {
kernelName: NotEqual,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as NotEqualInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(NotEqual, opAttrs, [a, b]);
}
};
@@ -0,0 +1,47 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, OneHot, OneHotAttrs, OneHotInputs, scalar} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const oneHotConfig: KernelConfig = {
kernelName: OneHot,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {indices} = args.inputs as OneHotInputs;
const backend = args.backend as NodeJSKernelBackend;
const {depth, onValue, offValue} = args.attrs as {} as OneHotAttrs;
const depthTensor = scalar(depth, 'int32');
const onValueTensor = scalar(onValue, 'int32');
const offValueTensor = scalar(offValue, 'int32');
const opAttrs = [
{name: 'axis', type: backend.binding.TF_ATTR_INT, value: -1},
createTensorsTypeOpAttr('T', indices.dtype),
createTensorsTypeOpAttr('TI', indices.dtype)
];
const res = backend.executeSingleOutput(
OneHot, opAttrs, [indices, depthTensor, onValueTensor, offValueTensor]);
depthTensor.dispose();
onValueTensor.dispose();
offValueTensor.dispose();
return res;
}
};
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, OnesLike, OnesLikeInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const onesLikeConfig: KernelConfig = {
kernelName: OnesLike,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as OnesLikeInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [{
name: 'T',
type: backend.binding.TF_ATTR_TYPE,
value: backend.getDTypeInteger(x.dtype)
}];
return backend.executeSingleOutput(OnesLike, opAttrs, [x]);
}
};
@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, KernelFunc, Pack, PackAttrs, PackInputs, Tensor, TensorInfo} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export function pack(
args: {inputs: PackInputs, backend: NodeJSKernelBackend, attrs: PackAttrs}):
TensorInfo {
const {inputs, backend, attrs} = args;
const {axis} = attrs;
const opAttrs = [
{name: 'N', type: backend.binding.TF_ATTR_INT, value: inputs.length},
createTensorsTypeOpAttr('T', inputs as Tensor[]),
{name: 'axis', type: backend.binding.TF_ATTR_INT, value: axis}
];
const res = backend.executeSingleOutput(Pack, opAttrs, inputs);
return res;
}
export const packConfig: KernelConfig = {
kernelName: Pack,
backendName: 'tensorflow',
kernelFunc: pack as {} as KernelFunc
};
@@ -0,0 +1,47 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, PadV2, PadV2Attrs, PadV2Inputs, scalar, tensor2d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const padV2Config: KernelConfig = {
kernelName: PadV2,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as PadV2Inputs;
const backend = args.backend as NodeJSKernelBackend;
const {paddings, constantValue} = args.attrs as {} as PadV2Attrs;
// Bind tensor values
const paddingsTensor = tensor2d(paddings, [paddings.length, 2], 'int32');
const constantTensor = scalar(constantValue, x.dtype);
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Tpaddings', paddingsTensor.dtype)
];
const res = backend.executeSingleOutput(
PadV2, opAttrs, [x, paddingsTensor, constantTensor]);
paddingsTensor.dispose();
constantTensor.dispose();
return res;
}
};
@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, cast, KernelConfig, Pow, PowInputs, Tensor, tidy} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const powConfig: KernelConfig = {
kernelName: Pow,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as PowInputs;
const backend = args.backend as NodeJSKernelBackend;
const dtype = backend_util.upcastType(a.dtype, b.dtype);
const opAttrs = [createTensorsTypeOpAttr('T', dtype)];
return tidy(() => {
return backend.executeSingleOutput(
Pow, opAttrs, [cast(a as Tensor, dtype), cast(b as Tensor, dtype)]);
});
}
};
@@ -0,0 +1,34 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {abs, KernelConfig, Prelu, PreluInputs, relu, Tensor, tidy} from '@tensorflow/tfjs';
export const preluConfig: KernelConfig = {
kernelName: Prelu,
backendName: 'tensorflow',
kernelFunc: (args) => {
const inputs = args.inputs as PreluInputs;
const x = inputs.x as Tensor;
const alpha = inputs.alpha as Tensor;
return tidy(() => {
const pos = relu(x);
const neg = alpha.mul(x.sub(abs(x))).mul(0.5);
return pos.add(neg);
});
}
};
@@ -0,0 +1,40 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Prod, ProdAttrs, ProdInputs, tensor1d, util} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const prodConfig: KernelConfig = {
kernelName: Prod,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as ProdInputs;
const backend = args.backend as NodeJSKernelBackend;
const {axis, keepDims} = args.attrs as {} as ProdAttrs;
const axes = util.parseAxisParam(axis, x.shape);
const axesTensor = tensor1d(axes, 'int32');
const opAttrs = [
{name: 'keep_dims', type: backend.binding.TF_ATTR_BOOL, value: keepDims},
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Tidx', 'int32')
];
const res = backend.executeSingleOutput(Prod, opAttrs, [x, axesTensor]);
axesTensor.dispose();
return res;
}
};
@@ -0,0 +1,61 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Range, RangeAttrs, scalar, zeros} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const rangeConfig: KernelConfig = {
kernelName: Range,
backendName: 'tensorflow',
kernelFunc: (args) => {
const backend = args.backend as NodeJSKernelBackend;
const {start, stop, dtype} = args.attrs as {} as RangeAttrs;
let {step} = args.attrs as {} as RangeAttrs;
// TensorFlow.js specific allowances
const sameStartStop = start === stop;
const increasingRangeNegativeStep = start < stop && step < 0;
const decreasingRangePositiveStep = stop < start && step > 1;
if (sameStartStop || increasingRangeNegativeStep ||
decreasingRangePositiveStep) {
return zeros([0], dtype);
}
if (stop < start && step === 1) {
// Auto adjust the step's sign if it hasn't been set
// (or was set to 1)
step = -1;
}
const opAttrs = [createTensorsTypeOpAttr('Tidx', dtype)];
const startTensor = scalar(start);
const stopTensor = scalar(stop);
const stepTensor = scalar(step);
const res = backend.executeSingleOutput(
Range, opAttrs, [startTensor, stopTensor, stepTensor]);
const castedRes = res.cast(dtype);
startTensor.dispose();
stopTensor.dispose();
stepTensor.dispose();
res.dispose();
return castedRes;
}
};
@@ -0,0 +1,38 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Real, RealInputs, Tensor} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const realConfig: KernelConfig = {
kernelName: Real,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {input} = args.inputs as RealInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [
createTensorsTypeOpAttr('T', input as Tensor), {
name: 'Tout',
type: backend.binding.TF_ATTR_TYPE,
value: backend.binding.TF_FLOAT
}
];
const inputs = [input];
return backend.executeSingleOutput(Real, opAttrs, inputs);
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, RealDiv, RealDivInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const realDivConfig: KernelConfig = {
kernelName: RealDiv,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as RealDivInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(RealDiv, opAttrs, [a, b]);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Reciprocal, ReciprocalInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const reciprocalConfig: KernelConfig = {
kernelName: Reciprocal,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as ReciprocalInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Reciprocal, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Relu, ReluInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const reluConfig: KernelConfig = {
kernelName: Relu,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as ReluInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Relu, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Relu6, Relu6Inputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const relu6Config: KernelConfig = {
kernelName: Relu6,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as Relu6Inputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Relu6, x);
}
};
@@ -0,0 +1,40 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Reshape, ReshapeAttrs, ReshapeInputs, tensor1d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const reshapeConfig: KernelConfig = {
kernelName: Reshape,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as ReshapeInputs;
const backend = args.backend as NodeJSKernelBackend;
const {shape} = args.attrs as {} as ReshapeAttrs;
const shapeTensor = tensor1d(shape, 'int32');
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Tshape', shapeTensor.dtype)
];
const res = backend.executeSingleOutput(Reshape, opAttrs, [x, shapeTensor]);
shapeTensor.dispose();
return res;
}
};
@@ -0,0 +1,51 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, ResizeBilinear, ResizeBilinearAttrs, ResizeBilinearInputs, tensor1d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const resizeBilinearConfig: KernelConfig = {
kernelName: ResizeBilinear,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {images} = args.inputs as ResizeBilinearInputs;
const backend = args.backend as NodeJSKernelBackend;
const {alignCorners, halfPixelCenters, size} =
args.attrs as {} as ResizeBilinearAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', images.dtype),
{
name: 'align_corners',
type: backend.binding.TF_ATTR_BOOL,
value: alignCorners
},
{
name: 'half_pixel_centers',
type: backend.binding.TF_ATTR_BOOL,
value: halfPixelCenters
},
];
const [newHeight, newWidth] = size;
const sizeTensor = tensor1d([newHeight, newWidth], 'int32');
const ret = backend.executeSingleOutput(
ResizeBilinear, opAttrs, [images, sizeTensor]);
sizeTensor.dispose();
return ret;
}
};
@@ -0,0 +1,40 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, ResizeBilinearGrad, ResizeBilinearGradAttrs, ResizeBilinearGradInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const resizeBilinearGradConfig: KernelConfig = {
kernelName: ResizeBilinearGrad,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {images, dy} = args.inputs as ResizeBilinearGradInputs;
const backend = args.backend as NodeJSKernelBackend;
const {alignCorners} = args.attrs as {} as ResizeBilinearGradAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', images.dtype), {
name: 'align_corners',
type: backend.binding.TF_ATTR_BOOL,
value: alignCorners
}
];
return backend.executeSingleOutput(
ResizeBilinearGrad, opAttrs, [dy, images]);
}
};
@@ -0,0 +1,51 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, ResizeNearestNeighbor, ResizeNearestNeighborAttrs, ResizeNearestNeighborInputs, tensor1d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const resizeNearestNeighborConfig: KernelConfig = {
kernelName: ResizeNearestNeighbor,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {images} = args.inputs as ResizeNearestNeighborInputs;
const backend = args.backend as NodeJSKernelBackend;
const {alignCorners, halfPixelCenters, size} =
args.attrs as {} as ResizeNearestNeighborAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', images.dtype),
{
name: 'align_corners',
type: backend.binding.TF_ATTR_BOOL,
value: alignCorners
},
{
name: 'half_pixel_centers',
type: backend.binding.TF_ATTR_BOOL,
value: halfPixelCenters
},
];
const [newHeight, newWidth] = size;
const sizeTensor = tensor1d([newHeight, newWidth], 'int32');
const res = backend.executeSingleOutput(
ResizeNearestNeighbor, opAttrs, [images, sizeTensor]);
sizeTensor.dispose();
return res;
}
};
@@ -0,0 +1,44 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, ResizeNearestNeighborGrad, ResizeNearestNeighborGradAttrs, ResizeNearestNeighborGradInputs, tensor1d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const resizeNearestNeighborGradConfig: KernelConfig = {
kernelName: ResizeNearestNeighborGrad,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {images, dy} = args.inputs as ResizeNearestNeighborGradInputs;
const backend = args.backend as NodeJSKernelBackend;
const {alignCorners} = args.attrs as {} as ResizeNearestNeighborGradAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', images.dtype), {
name: 'align_corners',
type: backend.binding.TF_ATTR_BOOL,
value: alignCorners
}
];
const [, origHeight, origWidth, ] = images.shape;
const sizeTensor = tensor1d([origHeight, origWidth], 'int32');
const res = backend.executeSingleOutput(
ResizeNearestNeighborGrad, opAttrs, [dy, sizeTensor]);
sizeTensor.dispose();
return res;
}
};
@@ -0,0 +1,42 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Reverse, ReverseAttrs, ReverseInputs, tensor1d, util} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const reverseConfig: KernelConfig = {
kernelName: Reverse,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as ReverseInputs;
const backend = args.backend as NodeJSKernelBackend;
const {dims} = args.attrs as {} as ReverseAttrs;
const opAttrs = [
createTensorsTypeOpAttr('Tidx', 'int32'),
createTensorsTypeOpAttr('T', x.dtype)
];
const axes = util.parseAxisParam(dims, x.shape);
const axisTensor = tensor1d(axes, 'int32');
const res =
backend.executeSingleOutput('ReverseV2', opAttrs, [x, axisTensor]);
axisTensor.dispose();
return res;
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Round, RoundInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const roundConfig: KernelConfig = {
kernelName: Round,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as RoundInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Round, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Rsqrt, RsqrtInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const rsqrtConfig: KernelConfig = {
kernelName: Rsqrt,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as RsqrtInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Rsqrt, x);
}
};
@@ -0,0 +1,42 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, ScatterNd, ScatterNdAttrs, ScatterNdInputs, tensor1d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const scatterNdConfig: KernelConfig = {
kernelName: ScatterNd,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {indices, updates} = args.inputs as ScatterNdInputs;
const backend = args.backend as NodeJSKernelBackend;
const {shape} = args.attrs as {} as ScatterNdAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', updates.dtype),
createTensorsTypeOpAttr('Tindices', 'int32')
];
const shapeTensor = tensor1d(shape, 'int32');
const ret = backend.executeSingleOutput(
ScatterNd, opAttrs, [indices, updates, shapeTensor]);
shapeTensor.dispose();
return ret;
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, Select, SelectInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const selectConfig: KernelConfig = {
kernelName: Select,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {condition, t, e} = args.inputs as SelectInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(t.dtype, e.dtype))];
return backend.executeSingleOutput(Select, opAttrs, [condition, t, e]);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Selu, SeluInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const seluConfig: KernelConfig = {
kernelName: Selu,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SeluInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Selu, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Sigmoid, SigmoidInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const sigmoidConfig: KernelConfig = {
kernelName: Sigmoid,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SigmoidInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Sigmoid, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Sign, SignInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const signConfig: KernelConfig = {
kernelName: Sign,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SignInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Sign, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Sin, SinInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const sinConfig: KernelConfig = {
kernelName: Sin,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SinInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Sin, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Sinh, SinhInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const sinhConfig: KernelConfig = {
kernelName: Sinh,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SinhInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Sinh, x);
}
};
@@ -0,0 +1,48 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, Slice, SliceAttrs, SliceInputs, tensor1d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const sliceConfig: KernelConfig = {
kernelName: Slice,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SliceInputs;
const backend = args.backend as NodeJSKernelBackend;
const {begin, size} = args.attrs as {} as SliceAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Index', 'int32')
];
// Bind tensor values
const [begin_, size_] =
backend_util.slice_util.parseSliceParams(x, begin, size);
const beginTensor = tensor1d(begin_, 'int32');
const sizeTensor = tensor1d(size_, 'int32');
const res = backend.executeSingleOutput(
Slice, opAttrs, [x, beginTensor, sizeTensor]);
beginTensor.dispose();
sizeTensor.dispose();
return res;
}
};
@@ -0,0 +1,37 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, NamedTensorInfoMap, TensorInfo} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
interface SoftmaxInputs extends NamedTensorInfoMap {
logits: TensorInfo;
}
export const softmaxConfig: KernelConfig = {
kernelName: 'Softmax',
backendName: 'tensorflow',
kernelFunc: ({inputs, backend}) => {
const {logits} = inputs as SoftmaxInputs;
const opAttrs = [createTensorsTypeOpAttr('T', logits.dtype)];
const nodeBackend = backend as NodeJSKernelBackend;
return nodeBackend.executeSingleOutput('Softmax', opAttrs, [logits]);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Softplus, SoftplusInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const softplusConfig: KernelConfig = {
kernelName: Softplus,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SoftplusInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Softplus, x);
}
};
@@ -0,0 +1,46 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, SpaceToBatchND, SpaceToBatchNDAttrs, SpaceToBatchNDInputs, tensor1d, tensor2d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const spaceToBatchNDConfig: KernelConfig = {
kernelName: SpaceToBatchND,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SpaceToBatchNDInputs;
const backend = args.backend as NodeJSKernelBackend;
const {blockShape, paddings} = args.attrs as {} as SpaceToBatchNDAttrs;
const blockShapeTensor = tensor1d(blockShape, 'int32');
const paddingsTensor =
tensor2d(paddings, [paddings.length, paddings[0].length], 'int32');
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Tblock_shape', 'int32'),
createTensorsTypeOpAttr('Tpaddings', paddingsTensor.dtype)
];
const res = backend.executeSingleOutput(
SpaceToBatchND, opAttrs, [x, blockShapeTensor, paddingsTensor]);
blockShapeTensor.dispose();
paddingsTensor.dispose();
return res;
}
};
@@ -0,0 +1,47 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, SparseToDense, SparseToDenseAttrs, SparseToDenseInputs, tensor1d} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const sparseToDenseConfig: KernelConfig = {
kernelName: SparseToDense,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {sparseIndices, sparseValues, defaultValue} =
args.inputs as SparseToDenseInputs;
const backend = args.backend as NodeJSKernelBackend;
const {outputShape} = args.attrs as {} as SparseToDenseAttrs;
const opAttrs = [
{
name: 'validate_indices',
type: backend.binding.TF_ATTR_BOOL,
value: true
},
createTensorsTypeOpAttr('T', sparseValues.dtype),
createTensorsTypeOpAttr('Tindices', sparseIndices.dtype)
];
const outputShapeTensor = tensor1d(outputShape, 'int32');
const res = backend.executeSingleOutput(
SparseToDense, opAttrs,
[sparseIndices, outputShapeTensor, sparseValues, defaultValue]);
outputShapeTensor.dispose();
return res;
}
};
@@ -0,0 +1,53 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, scalar, SplitV, SplitVAttrs, SplitVInputs, Tensor, tensor1d, tidy, util} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const splitVConfig: KernelConfig = {
kernelName: SplitV,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SplitVInputs;
const backend = args.backend as NodeJSKernelBackend;
const {numOrSizeSplits, axis} = args.attrs as {} as SplitVAttrs;
const $axis = util.parseAxisParam(axis, x.shape)[0];
const splitSizes = backend_util.prepareSplitSize(x, numOrSizeSplits, $axis);
const opAttrs = [
{
name: 'num_split',
type: backend.binding.TF_ATTR_INT,
value: splitSizes.length
},
createTensorsTypeOpAttr('T', x as Tensor), {
name: 'Tlen',
type: backend.binding.TF_ATTR_TYPE,
value: backend.binding.TF_INT32
}
];
const inputs = [x];
return tidy(() => {
inputs.push(tensor1d(splitSizes, 'int32'));
inputs.push(scalar($axis, 'int32'));
return backend.executeMultipleOutputs(
SplitV, opAttrs, inputs, splitSizes.length);
});
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Sqrt, SqrtInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const sqrtConfig: KernelConfig = {
kernelName: Sqrt,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SqrtInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Sqrt, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Square, SquareInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const squareConfig: KernelConfig = {
kernelName: Square,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SquareInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Square, x);
}
};
@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, SquaredDifference, SquaredDifferenceInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const squaredDifferenceConfig: KernelConfig = {
kernelName: SquaredDifference,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as SquaredDifferenceInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr('T', a.dtype)];
return backend.executeSingleOutput(SquaredDifference, opAttrs, [a, b]);
}
};
@@ -0,0 +1,43 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, fill, greater, isNaN as tfIsNan, KernelConfig, ones, scalar, Step, StepAttrs, StepInputs, Tensor, tidy, where} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const stepConfig: KernelConfig = {
kernelName: Step,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as StepInputs;
const backend = args.backend as NodeJSKernelBackend;
const {alpha} = args.attrs as {} as StepAttrs;
const dtype = x.dtype;
return tidy(() => {
const nans = tfIsNan(x as Tensor);
const stepNoNans = where(
greater(x as Tensor, scalar(0, dtype)), ones(x.shape),
fill(x.shape, alpha, dtype));
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(x.dtype, stepNoNans.dtype))];
return backend.executeSingleOutput(
'Select', opAttrs, [nans, x, stepNoNans]);
});
}
};
@@ -0,0 +1,125 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, reshape, slice, StridedSlice, StridedSliceAttrs, StridedSliceInputs, Tensor, tensor1d, tidy} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const stridedSliceConfig: KernelConfig = {
kernelName: StridedSlice,
backendName: 'tensorflow',
kernelFunc: (args) => {
let {x} = args.inputs as StridedSliceInputs;
const backend = args.backend as NodeJSKernelBackend;
const {beginMask, endMask, ellipsisMask, newAxisMask, shrinkAxisMask} =
args.attrs as {} as StridedSliceAttrs;
let {begin, end, strides} = args.attrs as {} as StridedSliceAttrs;
// make a copy because it may be modified in-place further down.
begin = begin.slice();
end = end.slice();
if (strides == null) {
strides = new Array(begin.length);
}
const ellipsisAxes = backend_util.slice_util.maskToAxes(ellipsisMask);
if (ellipsisAxes.length > 1) {
throw new Error('Multiple ellipses in slice is not allowed.');
}
if (ellipsisMask !== 0 && newAxisMask !== 0) {
throw new Error(
'Using both ellipsisMask and newAxisMask is not yet supported.');
}
if (ellipsisMask !== 0 && shrinkAxisMask !== 0) {
throw new Error(
'Using both ellipsisMask and shrinkAxisMask is not yet supported.');
}
return tidy(() => {
const numInterpolatedAxes = (x as Tensor).rank - begin.length;
// Expand the dims of x based on the newAxisMask.
const expandAxes = backend_util.slice_util.maskToAxes(newAxisMask);
const newShape = x.shape.slice();
expandAxes.forEach(axis => {
begin[axis] = 0;
end[axis] = 1;
newShape.splice(axis, 0, 1);
});
x = reshape(x as Tensor, newShape);
const {
begin: normalizedBegin,
end: normalizedEnd,
strides: normalizedStrides
} =
backend_util.slice_util.getNormalizedAxes(
x.shape, ellipsisAxes, numInterpolatedAxes, begin, end, strides,
beginMask, endMask, ellipsisMask);
begin = normalizedBegin;
end = normalizedEnd;
strides = normalizedStrides;
const shrinkAxes = backend_util.slice_util.maskToAxes(shrinkAxisMask);
// Adjust the ends based on the shrink mask.
shrinkAxes.forEach(axis => {
end[axis] = begin[axis] + 1;
strides[axis] = 1;
});
// Figure out the output shape.
const size = backend_util.slice_util.computeOutShape(begin, end, strides);
// Remove the axes based on shrinkMask.
const outShape =
size.filter((_, axis) => shrinkAxes.indexOf(axis) === -1);
const nonStrided = strides.every(v => v === 1);
if (nonStrided) {
return reshape(slice(x as Tensor, begin, size), outShape);
}
const beginTensor = tensor1d(begin, 'int32');
for (let axis = 0; axis < end.length; axis++) {
// Unlike Numpy, when the strides are negative, TF C uses -n-1 instead
// of -1 as the "end" in order to include the first element.
if (strides[axis] < 0 && end[axis] === -1) {
end[axis] -= x.shape[axis];
}
}
const endTensor = tensor1d(end, 'int32');
const stridesTensor = tensor1d(strides, 'int32');
// Because tfjs allows begin, end and strides to be of different lengths
// It has custom code (see above to handle the masking), so we do not
// pass the mask info to the tensorflow backend.
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Index', 'int32'),
{name: 'begin_mask', type: backend.binding.TF_ATTR_INT, value: 0},
{name: 'end_mask', type: backend.binding.TF_ATTR_INT, value: 0},
{name: 'ellipsis_mask', type: backend.binding.TF_ATTR_INT, value: 0},
{name: 'new_axis_mask', type: backend.binding.TF_ATTR_INT, value: 0},
{name: 'shrink_axis_mask', type: backend.binding.TF_ATTR_INT, value: 0}
];
const res = backend.executeSingleOutput(
StridedSlice, opAttrs, [x, beginTensor, endTensor, stridesTensor]);
return reshape(res, outShape);
});
}
};
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {backend_util, KernelConfig, Sub, SubInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const subConfig: KernelConfig = {
kernelName: Sub,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {a, b} = args.inputs as SubInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [createTensorsTypeOpAttr(
'T', backend_util.upcastType(a.dtype, b.dtype))];
return backend.executeSingleOutput(Sub, opAttrs, [a, b]);
}
};
@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Sum, SumAttrs, SumInputs, tensor1d, util} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const sumConfig: KernelConfig = {
kernelName: Sum,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as SumInputs;
const backend = args.backend as NodeJSKernelBackend;
const {axis, keepDims} = args.attrs as {} as SumAttrs;
const axes = util.parseAxisParam(axis, x.shape);
const axisTensor = tensor1d(axes, 'int32');
const res = backend.executeSingleOutput(
Sum, backend.createReductionOpAttrs(x, keepDims), [x, axisTensor]);
axisTensor.dispose();
return res;
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Tan, TanInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const tanConfig: KernelConfig = {
kernelName: Tan,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as TanInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Tan, x);
}
};
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Tanh, TanhInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const tanhConfig: KernelConfig = {
kernelName: Tanh,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as TanhInputs;
const backend = args.backend as NodeJSKernelBackend;
return backend.executeSingleInput(Tanh, x);
}
};
@@ -0,0 +1,39 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, tensor1d, Tile, TileAttrs, TileInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const tileConfig: KernelConfig = {
kernelName: Tile,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as TileInputs;
const backend = args.backend as NodeJSKernelBackend;
const {reps} = args.attrs as {} as TileAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Tmultiples', 'int32')
];
const multiples = tensor1d(reps, 'int32');
const res = backend.executeSingleOutput(Tile, opAttrs, [x, multiples]);
multiples.dispose();
return res;
}
};
@@ -0,0 +1,46 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, scalar, TopK, TopKAttrs, TopKInputs} from '@tensorflow/tfjs';
import {isNullOrUndefined} from 'util';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const topKConfig: KernelConfig = {
kernelName: TopK,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as TopKInputs;
const backend = args.backend as NodeJSKernelBackend;
const {k, sorted} = args.attrs as {} as TopKAttrs;
const kCount = isNullOrUndefined(k) ? 1 : k;
const isSorted = isNullOrUndefined(sorted) ? true : sorted;
const opAttrs = [
{name: 'sorted', type: backend.binding.TF_ATTR_BOOL, value: isSorted},
createTensorsTypeOpAttr('T', x.dtype),
];
const kTensor = scalar(kCount, 'int32');
// 'TopKV2' has two-hard coded output attributes:
// TODO(yassogba) consider renamine constant in kernel names;
const res =
backend.executeMultipleOutputs('TopKV2', opAttrs, [x, kTensor], 2);
kTensor.dispose();
return res;
}
};
@@ -0,0 +1,40 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, tensor1d, Transpose, TransposeAttrs, TransposeInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const transposeConfig: KernelConfig = {
kernelName: Transpose,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as TransposeInputs;
const backend = args.backend as NodeJSKernelBackend;
const {perm} = args.attrs as {} as TransposeAttrs;
const permTensor = tensor1d(perm, 'int32');
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Tperm', 'int32')
];
const res =
backend.executeSingleOutput(Transpose, opAttrs, [x, permTensor]);
permTensor.dispose();
return res;
}
};
@@ -0,0 +1,46 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, Unpack, UnpackAttrs, UnpackInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const unpackConfig: KernelConfig = {
kernelName: Unpack,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {value} = args.inputs as UnpackInputs;
const backend = args.backend as NodeJSKernelBackend;
let {axis} = args.attrs as {} as UnpackAttrs;
if (axis < 0) {
axis += value.shape.length;
}
if (axis >= value.shape.length) {
throw new Error(
`Invalid axis supplied: ${axis} shape length: ${value.shape.length}`);
}
const num = value.shape[axis];
const opAttrs = [
{name: 'num', type: backend.binding.TF_ATTR_INT, value: num},
createTensorsTypeOpAttr('T', value.dtype),
{name: 'axis', type: backend.binding.TF_ATTR_INT, value: axis}
];
return backend.executeMultipleOutputs(Unpack, opAttrs, [value], num);
}
};
@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, scalar, UnsortedSegmentSum, UnsortedSegmentSumAttrs, UnsortedSegmentSumInputs} from '@tensorflow/tfjs';
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const unsortedSegmentSumConfig: KernelConfig = {
kernelName: UnsortedSegmentSum,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x, segmentIds} = args.inputs as UnsortedSegmentSumInputs;
const backend = args.backend as NodeJSKernelBackend;
const {numSegments} = args.attrs as {} as UnsortedSegmentSumAttrs;
const opAttrs = [
createTensorsTypeOpAttr('T', x.dtype),
createTensorsTypeOpAttr('Tindices', 'int32'),
createTensorsTypeOpAttr('Tnumsegments', 'int32')
];
const numSegmentsT = scalar(numSegments, 'int32');
const res = backend.executeSingleOutput(
UnsortedSegmentSum, opAttrs, [x, segmentIds, numSegmentsT]);
numSegmentsT.dispose();
return res;
}
};
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {KernelConfig, ZerosLike, ZerosLikeInputs} from '@tensorflow/tfjs';
import {NodeJSKernelBackend} from '../nodejs_kernel_backend';
export const zerosLikeConfig: KernelConfig = {
kernelName: ZerosLike,
backendName: 'tensorflow',
kernelFunc: (args) => {
const {x} = args.inputs as ZerosLikeInputs;
const backend = args.backend as NodeJSKernelBackend;
const opAttrs = [{
name: 'T',
type: backend.binding.TF_ATTR_TYPE,
value: backend.getDTypeInteger(x.dtype)
}];
return backend.executeSingleOutput(ZerosLike, opAttrs, [x]);
}
};
@@ -0,0 +1,360 @@
// api.proto
// Definition of various TensorFlow protobuf messages for use with the TensorFlow API.
//
// Assembled from these relevant proto sources:
// https://github.com/google/protobuf/blob/master/src/google/protobuf/any.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/types.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/tensor.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/tensor_shape.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/attr_value.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/versions.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/graph.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/node_def.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/op_def.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/protobuf/saver.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/protobuf/meta_graph.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/protobuf/saved_model.proto
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/function.proto
// This file is used to generate the api_pb.js file with the JavaScript Protocol
// Buffers runtime library (https://github.com/protocolbuffers/protobuf/tree/master/js).
// The protocol compiler (https://github.com/protocolbuffers/protobuf/releases)
// translated this file (same as proto file in tfjs-converter:
// https://github.com/tensorflow/tfjs/blob/master/tfjs-converter/src/data/api.proto)
// into the api_pb.js file with command:
//
// ```
// $ protoc --js_out=import_style=commonjs,binary:. api.proto
// ```
syntax = "proto3";
package tensorflow;
message Any {
string type_url = 1;
bytes value = 2;
}
enum DataType {
// Not a legal value for DataType. Used to indicate a DataType field
// has not been set.
DT_INVALID = 0;
// Data types that all computation devices are expected to be
// capable to support.
DT_FLOAT = 1;
DT_DOUBLE = 2;
DT_INT32 = 3;
DT_UINT8 = 4;
DT_INT16 = 5;
DT_INT8 = 6;
DT_STRING = 7;
DT_COMPLEX64 = 8; // Single-precision complex
DT_INT64 = 9;
DT_BOOL = 10;
DT_QINT8 = 11; // Quantized int8
DT_QUINT8 = 12; // Quantized uint8
DT_QINT32 = 13; // Quantized int32
DT_BFLOAT16 = 14; // Float32 truncated to 16 bits. Only for cast ops.
// Do not use! These are only for parameters. Every enum above
// should have a corresponding value below (verified by types_test).
DT_FLOAT_REF = 101;
DT_DOUBLE_REF = 102;
DT_INT32_REF = 103;
DT_UINT8_REF = 104;
DT_INT16_REF = 105;
DT_INT8_REF = 106;
DT_STRING_REF = 107;
DT_COMPLEX64_REF = 108;
DT_INT64_REF = 109;
DT_BOOL_REF = 110;
DT_QINT8_REF = 111;
DT_QUINT8_REF = 112;
DT_QINT32_REF = 113;
DT_BFLOAT16_REF = 114;
}
message TensorShape {
// One dimension of the tensor.
message Dim {
// Size of the tensor in that dimension.
int64 size = 1;
// Optional name of the tensor dimension.
string name = 2;
}
// Dimensions of the tensor, such as {"input", 30}, {"output", 40} for a 30 x
// 40 2D tensor. The names are optional.
//
// The order of entries in "dim" matters: It indicates the layout of the
// values in the tensor in-memory representation.
//
// The first entry in "dim" is the outermost dimension used to layout the
// values, the last entry is the innermost dimension. This matches the
// in-memory layout of RowMajor Eigen tensors.
repeated Dim dim = 2;
bool unknown_rank = 3;
}
message Tensor {
DataType dtype = 1;
// Shape of the tensor. TODO(touts): sort out the 0-rank issues.
TensorShape tensor_shape = 2;
// Only one of the representations below is set, one of "tensor_contents" and
// the "xxx_val" attributes. We are not using oneof because as oneofs cannot
// contain repeated fields it would require another extra set of messages.
// Version number.
//
// In version 0, if the "repeated xxx" representations contain only one
// element, that element is repeated to fill the shape. This makes it easy
// to represent a constant Tensor with a single value.
int32 version_number = 3;
// Serialized content from TensorBase::Serialize() This representation can be
// used for all tensor types.
bytes tensor_content = 4;
// Type specific representations that make it easy to create tensor protos in
// all languages. Only the representation corresponding to "dtype" can
// be set. The values hold the flattened representation of the tensor in
// row major order.
// DT_FLOAT.
repeated float float_val = 5 [packed = true];
// DT_DOUBLE.
repeated double double_val = 6 [packed = true];
// DT_INT32, DT_INT16, DT_INT8, DT_UINT8.
repeated int32 int_val = 7 [packed = true];
// DT_STRING
repeated bytes string_val = 8;
// DT_COMPLEX64. scomplex_val(2*i) and scomplex_val(2*i+1) are real
// and imaginary parts of i-th single precision complex.
repeated float scomplex_val = 9 [packed = true];
// DT_INT64
repeated int64 int64_val = 10 [packed = true];
// DT_BOOL
repeated bool bool_val = 11 [packed = true];
// DT_UINT32
repeated uint32 uint32_val = 16 [packed = true];
// DT_UINT64
repeated uint64 uint64_val = 17 [packed = true];
}
message AttrValue {
message ListValue {
repeated bytes s = 2;
repeated int64 i = 3 [packed = true];
repeated float f = 4 [packed = true];
repeated bool b = 5 [packed = true];
repeated DataType type = 6 [packed = true];
repeated TensorShape shape = 7;
repeated Tensor tensor = 8;
repeated NameAttrList func = 9;
}
oneof value {
ListValue list = 1;
bytes s = 2;
int64 i = 3;
float f = 4;
bool b = 5;
DataType type = 6;
TensorShape shape = 7;
Tensor tensor = 8;
string placeholder = 9;
NameAttrList func = 10;
}
}
message NameAttrList {
string name = 1;
map<string, AttrValue> attr = 2;
}
message NodeDef {
string name = 1;
string op = 2;
repeated string input = 3;
string device = 4;
map<string, AttrValue> attr = 5;
}
message VersionDef {
int32 producer = 1;
int32 min_consumer = 2;
repeated int32 bad_consumers = 3;
}
message GraphDef {
repeated NodeDef node = 1;
VersionDef versions = 4;
FunctionDefLibrary library = 2;
}
message CollectionDef {
message NodeList {
repeated string value = 1;
}
message BytesList {
repeated bytes value = 1;
}
message Int64List {
repeated int64 value = 1 [packed = true];
}
message FloatList {
repeated float value = 1 [packed = true];
}
message AnyList {
repeated Any value = 1;
}
oneof kind {
NodeList node_list = 1;
BytesList bytes_list = 2;
Int64List int64_list = 3;
FloatList float_list = 4;
AnyList any_list = 5;
}
}
message SaverDef {
string filename_tensor_name = 1;
string save_tensor_name = 2;
string restore_op_name = 3;
int32 max_to_keep = 4;
bool sharded = 5;
float keep_checkpoint_every_n_hours = 6;
enum CheckpointFormatVersion {
LEGACY = 0;
V1 = 1;
V2 = 2;
}
CheckpointFormatVersion version = 7;
}
message TensorInfo {
message CooSparse {
string values_tensor_name = 1;
string indices_tensor_name = 2;
string dense_shape_tensor_name = 3;
}
oneof encoding {
string name = 1;
CooSparse coo_sparse = 4;
}
DataType dtype = 2;
TensorShape tensor_shape = 3;
}
message SignatureDef {
map<string, TensorInfo> inputs = 1;
map<string, TensorInfo> outputs = 2;
string method_name = 3;
}
message AssetFileDef {
TensorInfo tensor_info = 1;
string filename = 2;
}
message OpDef {
string name = 1;
message ArgDef {
string name = 1;
string description = 2;
DataType type = 3;
string type_attr = 4; // if specified, attr must have type "type"
string number_attr = 5; // if specified, attr must have type "int"
string type_list_attr = 6;
bool is_ref = 16;
}
repeated ArgDef input_arg = 2;
repeated ArgDef output_arg = 3;
message AttrDef {
string name = 1;
string type = 2;
AttrValue default_value = 3;
string description = 4;
bool has_minimum = 5;
int64 minimum = 6;
AttrValue allowed_values = 7;
}
repeated AttrDef attr = 4;
message OpDeprecation {
int32 version = 1;
string explanation = 2;
}
OpDeprecation deprecation = 8;
string summary = 5;
string description = 6;
bool is_commutative = 18;
bool is_aggregate = 16; // for things like add
bool is_stateful = 17; // for things like variables, queue
bool allows_uninitialized_input = 19; // for Assign, etc.
}
message OpList {
repeated OpDef op = 1;
}
message MetaGraphDef {
message MetaInfoDef {
string meta_graph_version = 1;
OpList stripped_op_list = 2;
Any any_info = 3;
repeated string tags = 4;
string tensorflow_version = 5;
string tensorflow_git_version = 6;
}
MetaInfoDef meta_info_def = 1;
GraphDef graph_def = 2;
SaverDef saver_def = 3;
map<string, CollectionDef> collection_def = 4;
map<string, SignatureDef> signature_def = 5;
repeated AssetFileDef asset_file_def = 6;
}
message SavedModel {
int64 saved_model_schema_version = 1;
repeated MetaGraphDef meta_graphs = 2;
}
message FunctionDefLibrary {
repeated FunctionDef function = 1;
repeated GradientDef gradient = 2;
}
message FunctionDef {
OpDef signature = 1;
map<string, AttrValue> attr = 5;
reserved 2;
repeated NodeDef node_def = 3;
map<string, string> ret = 4;
}
message GradientDef {
string function_name = 1; // The function name.
string gradient_func = 2; // The gradient function's name.
}
Loaded 100 of 919 files, more files were not shown because too many files have changed in this diff. Show more