Skip to content

Commit 40160ef

Browse files
ahmedsabiepyu10055
andauthored
Support initializer signature in tfjs-inference (#7100)
Co-authored-by: Ping Yu <4018+pyu10055@users.noreply.github.com>
1 parent 177a0b6 commit 40160ef

5 files changed

Lines changed: 38 additions & 43 deletions

File tree

tfjs-inference/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
},
1717
"license": "Apache-2.0",
1818
"devDependencies": {
19-
"@tensorflow/tfjs-core": "3.19.0",
20-
"@tensorflow/tfjs-converter": "3.19.0",
21-
"@tensorflow/tfjs-backend-cpu": "3.19.0",
22-
"@tensorflow/tfjs-backend-wasm": "3.19.0",
19+
"@tensorflow/tfjs-core": "4.1.0",
20+
"@tensorflow/tfjs-converter": "4.1.0",
21+
"@tensorflow/tfjs-backend-cpu": "4.1.0",
22+
"@tensorflow/tfjs-backend-wasm": "4.1.0",
2323
"@types/jasmine": "~3.0.0",
2424
"@types/rimraf": "~3.0.0",
2525
"clang-format": "~1.8.0",

tfjs-inference/src/file_handler.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ export class FileHandler implements tf.io.IOHandler {
7575
modelArtifacts.modelInitializer = modelJSON.modelInitializer;
7676
}
7777

78-
// TODO: Uncomment once table initializers are supported in TFJS.
79-
// if (modelJSON.initializerSignature != null) {
80-
// modelArtifacts.initializerSignature = modelJSON.initializerSignature;
81-
// }
78+
if (modelJSON.initializerSignature != null) {
79+
modelArtifacts.initializerSignature = modelJSON.initializerSignature;
80+
}
8281

8382
if (modelJSON.weightsManifest != null) {
8483
const [weightSpecs, weightData] =

tfjs-inference/src/file_handler_test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ describe('File Handler', () => {
101101
signature: {},
102102
userDefinedMetadata: {},
103103
modelInitializer: {},
104-
// TODO: Uncomment once table initializers are supported in TFJS.
105-
// initializerSignature: {}
104+
initializerSignature: {}
106105
};
107106

108107
// Write model.json file.
@@ -127,8 +126,7 @@ describe('File Handler', () => {
127126
expect(modelArtifacts.signature).toEqual({});
128127
expect(modelArtifacts.userDefinedMetadata).toEqual({});
129128
expect(modelArtifacts.modelInitializer).toEqual({});
130-
// TODO: Uncomment once table initializers are supported in TFJS.
131-
// expect(modelArtifacts.initializerSignature).toEqual({});
129+
expect(modelArtifacts.initializerSignature).toEqual({});
132130
expect(modelArtifacts.weightSpecs).toEqual([
133131
{
134132
name: 'dense/kernel',

tfjs-inference/src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,8 @@ async function main() {
160160
const namedInputs =
161161
createInputTensors(inputsData, inputsShape, inputsDtype, inputName);
162162

163-
// TODO: Change predict and execute to async versions once predictAsync is
164-
// supported in TFJS.
165-
const result = outputName == null ? model.predict(namedInputs) :
166-
model.execute(namedInputs, outputName);
163+
const result = outputName == null ? await model.predictAsync(namedInputs) :
164+
await model.executeAsync(namedInputs, outputName);
167165

168166
// execute can return a single tensor or an
169167
// array of tensors. predict can return a map as well.

tfjs-inference/yarn.lock

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,37 @@
5656
"@nodelib/fs.scandir" "2.1.4"
5757
fastq "^1.6.0"
5858

59-
"@tensorflow/tfjs-backend-cpu@3.19.0":
60-
version "3.19.0"
61-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-3.19.0.tgz#c7524ccdfded81df0c5cb53185b14e5222ac51e5"
62-
integrity sha512-02f+WkiL9gc9G7P8PwfsvuXREcAUdM/3uAL6fTle3xKEj7KOxX+E/mc3jxPY5UzjAsgHVBZrPJ2xi6AG16WPkQ==
59+
"@tensorflow/tfjs-backend-cpu@4.1.0":
60+
version "4.1.0"
61+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-4.1.0.tgz#6c1b058a63bdba748f6e13364ef01bd36f8d2301"
62+
integrity sha512-NqxrwpYa/hXGaBa1RzxfHsLAsaniIZryhF5CxQM9uSp1ny8wUJMH+Mda/Y8+llS3weHug8JDAbAW2cabn8l84A==
6363
dependencies:
6464
"@types/seedrandom" "^2.4.28"
6565
seedrandom "^3.0.5"
6666

67-
"@tensorflow/tfjs-backend-wasm@3.19.0":
68-
version "3.19.0"
69-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-wasm/-/tfjs-backend-wasm-3.19.0.tgz#742b94c63413a971983ac4ea6d6a306a54da2220"
70-
integrity sha512-qNvFi77BSvQiFxHFgWl6B3GJ8IbGVUn6jLfiHibqKI9dEmbVIN1dBiOJdbJT+lJZPlJv+vKyW9jgpVUM7QtfnQ==
67+
"@tensorflow/tfjs-backend-wasm@4.1.0":
68+
version "4.1.0"
69+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-wasm/-/tfjs-backend-wasm-4.1.0.tgz#131e876974c400d75a603bcf8c3dbd5769a42cff"
70+
integrity sha512-1bB+hsgRKywNa01shHRZm61UQbCSbRVS9EpJUv0HWcPnMQxKGGZ0L+Sc4lNbLutMHJtWtsEFgB3PifE7iubuWQ==
7171
dependencies:
72-
"@tensorflow/tfjs-backend-cpu" "3.19.0"
72+
"@tensorflow/tfjs-backend-cpu" "4.1.0"
7373
"@types/emscripten" "~0.0.34"
7474

75-
"@tensorflow/tfjs-converter@3.19.0":
76-
version "3.19.0"
77-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-3.19.0.tgz#701db7255ef45578811a191478db5a09bcca6dda"
78-
integrity sha512-B69HQq9/orsM8pGJPjNp1cV+hIcc90mxcRIsQSYGovTUNEcftmz2Sh+mqXDWysKUk0gRfx5CX6eJk6NaE55Xow==
75+
"@tensorflow/tfjs-converter@4.1.0":
76+
version "4.1.0"
77+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-4.1.0.tgz#c4c4ee70936e5f1d52adf6e1fcf5dd1eb8a984a4"
78+
integrity sha512-pR4TSUI949a/5uUWjHga8xzxD7Y9AbobHJtCmg86Bldfl2GV8aibz87cNjpoO+iUhH8WZo1TOJy8GpM+MPT2DA==
7979

80-
"@tensorflow/tfjs-core@3.19.0":
81-
version "3.19.0"
82-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-3.19.0.tgz#981c50bb38a6441a4375cfc8806784e7490f01bc"
83-
integrity sha512-znJ+TOJ3NdNL5yjw8M7dn2jO96sokiH1wfFuD7gglCkbZ4SXlFpFj2xelNdRHHmeYanMhJzqeyOW9whUnNcBqw==
80+
"@tensorflow/tfjs-core@4.1.0":
81+
version "4.1.0"
82+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-4.1.0.tgz#7a9eebc42a3853fd1457023fab306e0503adb310"
83+
integrity sha512-zERD4xtxNq3dV3+wPEMi2HWSV68FA8WucSAogzErp38/q98Byv9G1x8DhxQ+jowTcqN4srGWcBfK59jYwjlAvA==
8484
dependencies:
8585
"@types/long" "^4.0.1"
86-
"@types/offscreencanvas" "~2019.3.0"
86+
"@types/offscreencanvas" "~2019.7.0"
8787
"@types/seedrandom" "^2.4.28"
8888
"@types/webgl-ext" "0.0.30"
89-
"@webgpu/types" "0.1.16"
89+
"@webgpu/types" "0.1.21"
9090
long "4.0.0"
9191
node-fetch "~2.6.1"
9292
seedrandom "^3.0.5"
@@ -124,10 +124,10 @@
124124
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.36.tgz#5637905dbb15c30a33a3c65b9ef7c20e3c85ebad"
125125
integrity sha512-kjivUwDJfIjngzbhooRnOLhGYz6oRFi+L+EpMjxroDYXwDw9lHrJJ43E+dJ6KAd3V3WxWAJ/qZE9XKYHhjPOFQ==
126126

127-
"@types/offscreencanvas@~2019.3.0":
128-
version "2019.3.0"
129-
resolved "https://registry.yarnpkg.com/@types/offscreencanvas/-/offscreencanvas-2019.3.0.tgz#3336428ec7e9180cf4566dfea5da04eb586a6553"
130-
integrity sha512-esIJx9bQg+QYF0ra8GnvfianIY8qWB0GBx54PK5Eps6m+xTj86KLavHv6qDhzKcu5UUOgNfJ2pWaIIV7TRUd9Q==
127+
"@types/offscreencanvas@~2019.7.0":
128+
version "2019.7.0"
129+
resolved "https://registry.yarnpkg.com/@types/offscreencanvas/-/offscreencanvas-2019.7.0.tgz#e4a932069db47bb3eabeb0b305502d01586fa90d"
130+
integrity sha512-PGcyveRIpL1XIqK8eBsmRBt76eFgtzuPiSTyKHZxnGemp2yzGzWpjYKAfK3wIMiU7eH+851yEpiuP8JZerTmWg==
131131

132132
"@types/rimraf@~3.0.0":
133133
version "3.0.0"
@@ -159,10 +159,10 @@
159159
dependencies:
160160
"@types/yargs-parser" "*"
161161

162-
"@webgpu/types@0.1.16":
163-
version "0.1.16"
164-
resolved "https://registry.yarnpkg.com/@webgpu/types/-/types-0.1.16.tgz#1f05497b95b7c013facf7035c8e21784645f5cc4"
165-
integrity sha512-9E61voMP4+Rze02jlTXud++Htpjyyk8vw5Hyw9FGRrmhHQg2GqbuOfwf5Klrb8vTxc2XWI3EfO7RUHMpxTj26A==
162+
"@webgpu/types@0.1.21":
163+
version "0.1.21"
164+
resolved "https://registry.yarnpkg.com/@webgpu/types/-/types-0.1.21.tgz#b181202daec30d66ccd67264de23814cfd176d3a"
165+
integrity sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow==
166166

167167
ajv@^6.12.3:
168168
version "6.12.6"

0 commit comments

Comments
 (0)