Skip to content

Commit 03c2776

Browse files
Lint tfjs-tflite-node
1 parent d5dbe1a commit 03c2776

File tree

9 files changed

+229
-231
lines changed

9 files changed

+229
-231
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/node_modules
1+
node_modules
22
*~
33
#*#
44
build/

tfjs-tflite-node/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"build": "node-gyp rebuild && tsc",
1717
"build-deps": "cd ../link-package && yarn build",
1818
"test-dev": "jasmine --config=jasmine.json",
19-
"test": "yarn build && yarn test-dev"
19+
"test": "yarn build && yarn test-dev",
20+
"lint": "tslint -p . -t verbose"
2021
},
2122
"dependencies": {
2223
"bindings": "^1.5.0",
@@ -33,6 +34,8 @@
3334
"jasmine": "^4.0.2",
3435
"jpeg-js": "^0.4.3",
3536
"node-gyp": "^8.4.1",
37+
"tslint": "^6.1.3",
38+
"tslint-no-circular-imports": "^0.7.0",
3639
"typescript": "^4.5.4"
3740
}
3841
}

tfjs-tflite-node/src/delegate_plugin.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
* =============================================================================
1616
*/
1717

18-
1918
// TODO(mattsoulanille): Move this to @tensorflow/tfjs-tflite
2019
export interface TFLiteDelegatePlugin {
2120
readonly name: string;
2221
readonly tfliteVersion: string;
23-
readonly options: [string, string][],
22+
readonly options: Array<[string, string]>;
2423
readonly node?: {
2524
path: string;
26-
},
25+
};
2726
readonly browser?: {
2827
url: string;
29-
},
28+
};
3029
}

tfjs-tflite-node/src/index.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ export * from './delegate_plugin';
2323
import {TFLiteDelegatePlugin} from './delegate_plugin';
2424
import fetch from 'node-fetch';
2525

26+
// tslint:disable-next-line:no-require-imports
2627
const addon = require('bindings')('node_tflite_binding');
2728

2829
interface InterpreterOptions {
2930
threads?: number;
3031
delegate?: {
3132
path: string;
32-
options: [string, string][];
33-
}
33+
options: Array<[string, string]>;
34+
};
3435
}
3536

37+
// tslint:disable-next-line:variable-name
3638
export const TFLiteNodeModelRunner = addon.Interpreter as {
3739
new(model: ArrayBuffer, options: InterpreterOptions): TFLiteWebModelRunner;
3840
};
3941

42+
// tslint:disable-next-line:variable-name
4043
export const TensorInfo = addon.TensorInfo as {
4144
new(): TFLiteWebModelRunnerTensorInfo;
4245
};
@@ -60,7 +63,7 @@ async function createModel(model: string | ArrayBuffer,
6063

6164
const interpreterOptions: InterpreterOptions = {
6265
threads: options?.numThreads ?? 4,
63-
}
66+
};
6467

6568
const firstDelegate = options?.delegates?.[0];
6669
if (options?.delegates?.length > 1) {
@@ -73,7 +76,7 @@ async function createModel(model: string | ArrayBuffer,
7376
interpreterOptions.delegate = {
7477
path: delegatePath,
7578
options: firstDelegate.options,
76-
}
79+
};
7780
}
7881
}
7982
return new TFLiteNodeModelRunner(modelData, interpreterOptions);

tfjs-tflite-node/src/index_test.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
* =============================================================================
1616
*/
1717

18-
import { loadTFLiteModel, TFLiteNodeModelRunner} from './index';
18+
import {loadTFLiteModel, TFLiteNodeModelRunner} from './index';
1919
import * as fs from 'fs';
20-
import { TFLiteWebModelRunner } from '@tensorflow/tfjs-tflite/dist/types/tflite_web_model_runner';
20+
import {TFLiteWebModelRunner} from '@tensorflow/tfjs-tflite/dist/types/tflite_web_model_runner';
2121
import '@tensorflow/tfjs-backend-cpu';
2222
import * as jpeg from 'jpeg-js';
2323

24-
//import * as SegfaultHandler from 'segfault-handler';
25-
//SegfaultHandler.registerHandler('crash.log');
26-
2724
describe('interpreter', () => {
2825
let model: ArrayBuffer;
2926
let modelRunner: TFLiteWebModelRunner;
@@ -51,7 +48,7 @@ describe('interpreter', () => {
5148
});
5249

5350
it('runs infer', () => {
54-
let outputs = modelRunner.getOutputs();
51+
const outputs = modelRunner.getOutputs();
5552
modelRunner.infer();
5653
expect(outputs[0].data()).toBeDefined();
5754
});
@@ -147,7 +144,8 @@ describe('float32 support', () => {
147144
let labels: string[];
148145

149146
beforeEach(() => {
150-
model = fs.readFileSync('./test_data/teachable_machine_float.tflite').buffer;
147+
model = fs.readFileSync('./test_data/teachable_machine_float.tflite')
148+
.buffer;
151149
modelRunner = new TFLiteNodeModelRunner(model, {});
152150
labels = ['class1', 'class2'];
153151

@@ -184,7 +182,8 @@ describe('float32 support', () => {
184182
// the web. Alternatively, serve the model locally.
185183
describe('loading model from the web', () => {
186184
it('loads a model from the web', async () => {
187-
const model = await loadTFLiteModel('https://tfhub.dev/sayakpaul/lite-model/cartoongan/fp16/1');
185+
const url = 'https://tfhub.dev/sayakpaul/lite-model/cartoongan/fp16/1';
186+
const model = await loadTFLiteModel(url);
188187
expect(model).toBeDefined();
189188
});
190189
});

tfjs-tflite-node/src/tflite_model.ts

-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ export class TFLiteModel implements InferenceModel {
312312
}
313313
}
314314

315-
316315
/**
317316
* Returns the compatible tfjs DataType from the given TFLite data type.
318317
*

tfjs-tflite-node/tslint.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../tslint.json"
3+
}

0 commit comments

Comments
 (0)