Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8f6d3da
Upgrade typescript to 4.4.2
mattsoulanille Aug 27, 2021
9dc3322
[core] Upgrade typescript to 4.4.2
mattsoulanille Aug 27, 2021
24e9353
Install tslib
mattsoulanille Aug 27, 2021
ea630b5
[webgl] Upgrade typescript to 4.4.2
mattsoulanille Aug 27, 2021
add0110
[wasm] Upgrade typescript to 4.4.2
mattsoulanille Aug 27, 2021
973cb6b
[layers] Update typescript to 4.4.2
mattsoulanille Aug 27, 2021
3d95906
[data] Update typescript to 4.4.2
mattsoulanille Aug 30, 2021
f482727
[tfjs-automl] Update typescript to 4.4.2
mattsoulanille Aug 30, 2021
d6cc93a
[inference] Upgrade TypeScript to 4.4.2
mattsoulanille Aug 31, 2021
68b6898
[cpu] Update package.json with ts 4.4.2
mattsoulanille Aug 31, 2021
76fb265
[converter] Fix executor tests to work with ts 4
mattsoulanille Aug 31, 2021
a2ca980
[converter] Update kenrels_to_ops to work with new mocked tfOps
mattsoulanille Nov 3, 2021
ec8a585
[converter] Fix graph model tests by using spyOnAllFunctions
mattsoulanille Nov 3, 2021
e695e22
[converter] Fix executeOp tests by using a tfc.tidy spy
mattsoulanille Nov 3, 2021
1cf25af
Fix lint errors
mattsoulanille Nov 3, 2021
ea8fb41
[union] Upgrade typescript to 4.4.2
mattsoulanille Nov 4, 2021
a70df89
[node] Upgrade typescript to 4.4.2
mattsoulanille Nov 4, 2021
db2c0a2
[tflite] Upgrade typescript to 4.4.2
mattsoulanille Nov 4, 2021
a3dce77
[e2e] Upgrade typescript to 4.4.2
mattsoulanille Nov 4, 2021
2eee6ae
[vis] Set sort to null instead of false
mattsoulanille Nov 10, 2021
29e8a79
fixup! [converter] Fix executor tests to work with ts 4
mattsoulanille Nov 10, 2021
1722513
fixup! [data] Update typescript to 4.4.2
mattsoulanille Nov 11, 2021
cdfcc35
[converter] Fix Cumprod and ImageProjectiveTransformV3 tests
mattsoulanille Apr 22, 2022
295fac6
[react-native] Upgrade typescript to 4.4.2
mattsoulanille Apr 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix lint errors
  • Loading branch information
mattsoulanille committed Apr 22, 2022
commit 1cf25af556e45e5599cdb476d2b505c5ffc062da
20 changes: 11 additions & 9 deletions tfjs-converter/src/executor/graph_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ export class GraphModel implements InferenceModel {
*/
constructor(
private modelUrl: string|io.IOHandler,
private loadOptions: io.LoadOptions = {},
tfio = io) {
private loadOptions: io.LoadOptions = {}, tfio = io) {
this.io = tfio;
if (loadOptions == null) {
this.loadOptions = {};
Expand All @@ -105,13 +104,16 @@ export class GraphModel implements InferenceModel {
// Path is an IO Handler.
this.handler = path as io.IOHandler;
} else if (this.loadOptions.requestInit != null) {
this.handler = this.io.browserHTTPRequest(path as string, this.loadOptions);
this.handler =
this.io.browserHTTPRequest(path as string, this.loadOptions);
} else {
const handlers = this.io.getLoadHandlers(path as string, this.loadOptions);
const handlers =
this.io.getLoadHandlers(path as string, this.loadOptions);
if (handlers.length === 0) {
// For backward compatibility: if no load handler can be found,
// assume it is a relative http path.
handlers.push(this.io.browserHTTPRequest(path as string, this.loadOptions));
handlers.push(
this.io.browserHTTPRequest(path as string, this.loadOptions));
} else if (handlers.length > 1) {
throw new Error(
`Found more than one (${handlers.length}) load handlers for ` +
Expand Down Expand Up @@ -159,8 +161,8 @@ export class GraphModel implements InferenceModel {
this.signature = signature;

this.version = `${graph.versions.producer}.${graph.versions.minConsumer}`;
const weightMap =
this.io.decodeWeights(this.artifacts.weightData, this.artifacts.weightSpecs);
const weightMap = this.io.decodeWeights(
this.artifacts.weightData, this.artifacts.weightSpecs);
this.executor = new GraphExecutor(
OperationMapper.Instance.transformGraph(graph, this.signature));
this.executor.weightMap = this.convertTensorMapToTensorsMap(weightMap);
Expand Down Expand Up @@ -440,8 +442,8 @@ export class GraphModel implements InferenceModel {
* @doc {heading: 'Models', subheading: 'Loading'}
*/
export async function loadGraphModel(
modelUrl: string|io.IOHandler,
options: io.LoadOptions = {}, tfio = io): Promise<GraphModel> {
modelUrl: string|io.IOHandler, options: io.LoadOptions = {},
tfio = io): Promise<GraphModel> {
if (modelUrl == null) {
throw new Error(
'modelUrl in loadGraphModel() cannot be null. Please provide a url ' +
Expand Down
41 changes: 22 additions & 19 deletions tfjs-converter/src/operations/executors/basic_math_executor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import * as basic_math from '../op_list/basic_math';
import {Node} from '../types';

import {executeOp} from './basic_math_executor';
import {createNumberAttr, createNumberAttrFromIndex, createNumericArrayAttrFromIndex, createTensorAttr, uncapitalize, validateParam} from './test_helper';
import {RecursiveSpy, spyOnAllFunctions} from './spy_ops';
import {createNumberAttr, createNumberAttrFromIndex, createNumericArrayAttrFromIndex, createTensorAttr, uncapitalize, validateParam} from './test_helper';

describe('basic math', () => {
let node: Node;
Expand Down Expand Up @@ -53,24 +53,27 @@ describe('basic math', () => {
spyOpsAsTfOps = spyOps as unknown as typeof tfOps;
});

(['Abs', 'Acos', 'Asin', 'Atan', 'Ceil', 'Cos', 'Cosh', 'Elu', 'Exp',
'Floor', 'Log', 'Imag', 'Neg', 'Real', 'Relu', 'Selu', 'Sigmoid', 'Sin',
'Sinh', 'Sqrt', 'Square', 'Tanh', 'Tan', 'Sign', 'Round', 'Expm1', 'Log1p',
'Reciprocal', 'Softplus', 'Asinh', 'Acosh', 'Atanh', 'Erf'] as const)
.forEach(op => {
it('should call tfOps.' + op, () => {
node.op = op;
spyOps[uncapitalize(op)].and.returnValue({});
executeOp(node, {input1}, context, spyOpsAsTfOps);

expect(spyOps[uncapitalize(op)]).toHaveBeenCalledWith(input1[0]);
});
it('should match op def', () => {
node.op = op;

expect(validateParam(node, basic_math.json)).toBeTruthy();
});
});
([
'Abs', 'Acos', 'Asin', 'Atan', 'Ceil', 'Cos', 'Cosh',
'Elu', 'Exp', 'Floor', 'Log', 'Imag', 'Neg', 'Real',
'Relu', 'Selu', 'Sigmoid', 'Sin', 'Sinh', 'Sqrt', 'Square',
'Tanh', 'Tan', 'Sign', 'Round', 'Expm1', 'Log1p', 'Reciprocal',
'Softplus', 'Asinh', 'Acosh', 'Atanh', 'Erf'
] as const )
.forEach(op => {
it('should call tfOps.' + op, () => {
node.op = op;
spyOps[uncapitalize(op)].and.returnValue({});
executeOp(node, {input1}, context, spyOpsAsTfOps);

expect(spyOps[uncapitalize(op)]).toHaveBeenCalledWith(input1[0]);
});
it('should match op def', () => {
node.op = op;

expect(validateParam(node, basic_math.json)).toBeTruthy();
});
});
describe('Relu6', () => {
it('should call tfOps.relu6', () => {
node.op = 'Relu6';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import {ExecutionContext} from '../../executor/execution_context';
import {Node} from '../types';

import {executeOp} from './convolution_executor';
import {RecursiveSpy} from './spy_ops';
import {createNumberAttr, createNumericArrayAttr, createStrArrayAttr, createStrAttr, createTensorAttr, createTensorsAttr} from './test_helper';
import {createBoolAttr} from './test_helper';

import { RecursiveSpy } from './spy_ops';


describe('convolution', () => {
let node: Node;
const input = [tfOps.scalar(1)];
Expand All @@ -46,18 +44,20 @@ describe('convolution', () => {
attrParams: {},
children: []
};
spyOps = Object.fromEntries(
Object.keys(tfOps).map((op: keyof typeof tfOps) => {
if (op === 'fused') {
return [op, {
conv2d: jasmine.createSpy(op),
depthwiseConv2d: jasmine.createSpy(op),
matMul: jasmine.createSpy(op),
}];
}
const spy = jasmine.createSpy(op);
return [op, spy] as const;
})) as unknown as typeof spyOps;
spyOps =
Object.fromEntries(Object.keys(tfOps).map((op: keyof typeof tfOps) => {
if (op === 'fused') {
return [
op, {
conv2d: jasmine.createSpy(op),
depthwiseConv2d: jasmine.createSpy(op),
matMul: jasmine.createSpy(op),
}
];
}
const spy = jasmine.createSpy(op);
return [op, spy] as const ;
})) as unknown as typeof spyOps;
spyOpsAsTfOps = spyOps as unknown as typeof tfOps;
});

Expand Down Expand Up @@ -297,7 +297,7 @@ describe('convolution', () => {
node.attrParams['dataFormat'] = createStrAttr('NDHWC');
node.attrParams['includeBatchInIndex'] = createBoolAttr(true);
spyOps.maxPoolWithArgmax.and.returnValue(
{result: 'fake', indexes: 'fake'});
{result: 'fake', indexes: 'fake'});

executeOp(node, {input}, context, spyOpsAsTfOps);

Expand Down Expand Up @@ -384,7 +384,8 @@ describe('convolution', () => {
const input3 = [tfOps.scalar(3.0)];
const input4 = [tfOps.scalar(4.0)];
node.inputNames = ['input1', 'input2', 'input3', 'input4'];
executeOp(node, {input1, input2, input3, input4}, context, spyOpsAsTfOps);
executeOp(
node, {input1, input2, input3, input4}, context, spyOpsAsTfOps);

expect(spyOps.fused.conv2d).toHaveBeenCalledWith({
x: input1[0],
Expand Down Expand Up @@ -476,7 +477,9 @@ describe('convolution', () => {
const input3 = [tfOps.scalar(3.0)];

node.inputNames = ['input1', 'input2', 'input3'];
expect(() => executeOp(node, {input1, input2, input3}, context, spyOpsAsTfOps))
expect(
() => executeOp(
node, {input1, input2, input3}, context, spyOpsAsTfOps))
.toThrow();
});
});
Expand Down
42 changes: 20 additions & 22 deletions tfjs-converter/src/operations/executors/dynamic_executor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import * as dynamic from '../op_list/dynamic';
import {Node} from '../types';

import {executeOp} from './dynamic_executor';
import {RecursiveSpy, spyOnAllFunctions} from './spy_ops';
import {createBoolAttr, createNumberAttrFromIndex, createTensorAttr, validateParam} from './test_helper';
import {spyOnAllFunctions, RecursiveSpy} from './spy_ops';

describe('dynamic', () => {
let node: Node;
const input1 = [tfOps.tensor1d([1])];
const context = new ExecutionContext({}, {}, {});
let spyOps: RecursiveSpy<typeof tfOps>
let spyOps: RecursiveSpy<typeof tfOps>;
let spyOpsAsTfOps: typeof tfOps;

beforeEach(() => {
Expand Down Expand Up @@ -64,8 +64,9 @@ describe('dynamic', () => {
const input5 = [tfOps.tensor1d([1])];
spyOps.image.nonMaxSuppressionAsync.and.returnValue({});

const result =
executeOp(node, {input1, input2, input3, input4, input5}, context, undefined, spyOpsAsTfOps);
const result = executeOp(
node, {input1, input2, input3, input4, input5}, context, undefined,
spyOpsAsTfOps);
expect(spyOps.image.nonMaxSuppressionAsync)
.toHaveBeenCalledWith(input1[0], input2[0], 1, 1, 1);
expect(result instanceof Promise).toBeTruthy();
Expand Down Expand Up @@ -98,9 +99,9 @@ describe('dynamic', () => {
const input5 = [tfOps.tensor1d([1])];
spyOps.image.nonMaxSuppressionAsync.and.returnValue({});

const result =
executeOp(node, {input1, input2, input3, input4, input5}, context,
undefined, spyOpsAsTfOps);
const result = executeOp(
node, {input1, input2, input3, input4, input5}, context, undefined,
spyOpsAsTfOps);
expect(spyOps.image.nonMaxSuppressionAsync)
.toHaveBeenCalledWith(input1[0], input2[0], 1, 1, 1);
expect(result instanceof Promise).toBeTruthy();
Expand Down Expand Up @@ -136,9 +137,9 @@ describe('dynamic', () => {

spyOps.image.nonMaxSuppressionPaddedAsync.and.returnValue({});

const result =
executeOp(node, {input1, input2, input3, input4, input5}, context,
undefined, spyOpsAsTfOps);
const result = executeOp(
node, {input1, input2, input3, input4, input5}, context, undefined,
spyOpsAsTfOps);
expect(spyOps.image.nonMaxSuppressionPaddedAsync)
.toHaveBeenCalledWith(input1[0], input2[0], 1, 1, 1, true);
expect(result instanceof Promise).toBeTruthy();
Expand Down Expand Up @@ -203,17 +204,13 @@ describe('dynamic', () => {
node.op = 'Where';
node.inputParams = {'condition': createTensorAttr(0)};
const input1 = [tfOps.scalar(1)];
//spyOn(tfOps, 'whereAsync');
// spyOn(tfOps, 'whereAsync');

const result = executeOp(node, {input1}, context, undefined,
spyOpsAsTfOps);
expect(
spyOps.whereAsync.calls.mostRecent().args[0].dtype)
const result =
executeOp(node, {input1}, context, undefined, spyOpsAsTfOps);
expect(spyOps.whereAsync.calls.mostRecent().args[0].dtype)
.toEqual('bool');
expect(spyOps.whereAsync
.calls.mostRecent()
.args[0]
.arraySync())
expect(spyOps.whereAsync.calls.mostRecent().args[0].arraySync())
.toEqual(1);
expect(result instanceof Promise).toBeTruthy();
});
Expand Down Expand Up @@ -244,9 +241,10 @@ describe('dynamic', () => {
const input2 = [tfOps.scalar(1)];
spyOps.setdiff1dAsync.and.returnValue({});

const result = executeOp(node, {input1, input2}, context, undefined,
spyOpsAsTfOps);
expect(spyOps.setdiff1dAsync).toHaveBeenCalledWith(input1[0], input2[0]);
const result = executeOp(
node, {input1, input2}, context, undefined, spyOpsAsTfOps);
expect(spyOps.setdiff1dAsync)
.toHaveBeenCalledWith(input1[0], input2[0]);
expect(result instanceof Promise).toBeTruthy();
});
it('should match json def', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {ExecutionContext} from '../../executor/execution_context';
import {Node} from '../types';

import {executeOp} from './evaluation_executor';
import {RecursiveSpy, spyOnAllFunctions} from './spy_ops';
import {createBoolAttr, createNumberAttrFromIndex, createTensorAttr} from './test_helper';
import {spyOnAllFunctions, RecursiveSpy} from './spy_ops';

describe('evaluation', () => {
let node: Node;
Expand Down Expand Up @@ -79,7 +79,9 @@ describe('evaluation', () => {
node.inputParams['axis'] = createNumberAttrFromIndex(1);
const xInput = [tfOps.tensor2d([[1], [2]])];
const axisInput = [tfOps.scalar(1)];
executeOp(node, {'input1': xInput, 'input2': axisInput}, context, spyOpsAsTfOps);
executeOp(
node, {'input1': xInput, 'input2': axisInput}, context,
spyOpsAsTfOps);
expect(spyOps.unique).toHaveBeenCalledWith(xInput[0], 1);
});
});
Expand Down
25 changes: 14 additions & 11 deletions tfjs-converter/src/operations/executors/logical_executor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {ExecutionContext} from '../../executor/execution_context';
import {Node} from '../types';

import {executeOp} from './logical_executor';
import {RecursiveSpy, spyOnAllFunctions} from './spy_ops';
import {createTensorAttr, uncapitalize} from './test_helper';
import {spyOnAllFunctions, RecursiveSpy} from './spy_ops';

describe('logical', () => {
let node: Node;
Expand Down Expand Up @@ -52,17 +52,20 @@ describe('logical', () => {
spyOpsAsTfOps = spyOps as unknown as typeof tfOps;
});

(['Equal', 'NotEqual', 'Greater', 'GreaterEqual', 'Less', 'LessEqual',
'LogicalAnd', 'LogicalOr'] as const)
.forEach(op => {
it('should call tfOps.' + op, () => {
node.op = op;
spyOps[uncapitalize(op)].and.returnValue({});
executeOp(node, {input1, input2}, context, spyOpsAsTfOps);
([
'Equal', 'NotEqual', 'Greater', 'GreaterEqual', 'Less', 'LessEqual',
'LogicalAnd', 'LogicalOr'
] as const )
.forEach(op => {
it('should call tfOps.' + op, () => {
node.op = op;
spyOps[uncapitalize(op)].and.returnValue({});
executeOp(node, {input1, input2}, context, spyOpsAsTfOps);

expect(spyOps[uncapitalize(op)]).toHaveBeenCalledWith(input1[0], input2[0]);
});
});
expect(spyOps[uncapitalize(op)])
.toHaveBeenCalledWith(input1[0], input2[0]);
});
});
describe('LogicalNot', () => {
it('should call tfOps.logicalNot', () => {
node.op = 'LogicalNot';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {ExecutionContext} from '../../executor/execution_context';
import {Node} from '../types';

import {executeOp} from './matrices_executor';
import {createBoolAttr, createNumberAttr, createNumericArrayAttr, createStrArrayAttr, createStrAttr, createTensorAttr, createTensorsAttr} from './test_helper';
import {RecursiveSpy, spyOnAllFunctions} from './spy_ops';
import {createBoolAttr, createNumberAttr, createNumericArrayAttr, createStrArrayAttr, createStrAttr, createTensorAttr, createTensorsAttr} from './test_helper';

describe('matrices', () => {
let node: Node;
Expand Down Expand Up @@ -97,7 +97,8 @@ describe('matrices', () => {
const input4 = [tfOps.scalar(4.0)];
node.inputNames = ['input1', 'input2', 'input3', 'input4'];
spyOps.fused.matMul.and.returnValue({});
executeOp(node, {input1, input2, input3, input4}, context, spyOpsAsTfOps);
executeOp(
node, {input1, input2, input3, input4}, context, spyOpsAsTfOps);

expect(spyOps.fused.matMul).toHaveBeenCalledWith({
a: input1[0],
Expand Down
23 changes: 12 additions & 11 deletions tfjs-converter/src/operations/executors/reduction_executor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import * as reduction from '../op_list/reduction';
import {Node} from '../types';

import {executeOp} from './reduction_executor';
import { createBoolAttr, createNumberAttr, createNumberAttrFromIndex, createTensorAttr, validateParam, uncapitalize} from './test_helper';
import {RecursiveSpy, spyOnAllFunctions} from './spy_ops';
import {createBoolAttr, createNumberAttr, createNumberAttrFromIndex, createTensorAttr, uncapitalize, validateParam} from './test_helper';

describe('reduction', () => {
let node: Node;
Expand All @@ -48,18 +48,19 @@ describe('reduction', () => {
});

describe('executeOp', () => {
(['Max', 'Mean', 'Min', 'Sum', 'All', 'Any', 'Prod'] as const)
.forEach(op => {
it('should call tfOps.' + op, () => {
node.op = op;
node.attrParams.keepDims = createBoolAttr(true);
node.attrParams.axis = createNumberAttr(1);
spyOps[uncapitalize(op)].and.returnValue({});
executeOp(node, {input1}, context, spyOpsAsTfOps);
(['Max', 'Mean', 'Min', 'Sum', 'All', 'Any', 'Prod'] as const )
.forEach(op => {
it('should call tfOps.' + op, () => {
node.op = op;
node.attrParams.keepDims = createBoolAttr(true);
node.attrParams.axis = createNumberAttr(1);
spyOps[uncapitalize(op)].and.returnValue({});
executeOp(node, {input1}, context, spyOpsAsTfOps);

expect(spyOps[uncapitalize(op)]).toHaveBeenCalledWith(input1[0], 1, true);
expect(spyOps[uncapitalize(op)])
.toHaveBeenCalledWith(input1[0], 1, true);
});
});
});
describe('ArgMax', () => {
it('should call tfOps.argMax', () => {
node.op = 'ArgMax';
Expand Down
Loading