Skip to content

Commit 16848fe

Browse files
authored
upgrade deeplab to 3.0.0-rc.1 (#563)
1 parent 66dc36b commit 16848fe

12 files changed

+128
-457
lines changed

cloudbuild.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ steps:
3939
- name: 'gcr.io/cloud-builders/gcloud'
4040
entrypoint: 'bash'
4141
id: 'deeplab'
42-
args: ['./scripts/run-build.sh', 'deep-lab']
42+
args: ['./scripts/run-build.sh', 'deeplab']
4343
waitFor: ['diff']
4444

4545
# KNN Classifier.

deeplab/cloudbuild.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ steps:
88

99
# Install tfjs dependencies.
1010
- name: 'node:10'
11-
dir: 'universal-sentence-encoder'
11+
dir: 'deeplab'
1212
entrypoint: 'yarn'
1313
id: 'yarn'
1414
args: ['install']
@@ -24,15 +24,15 @@ steps:
2424

2525
# Build.
2626
- name: 'node:10'
27-
dir: 'universal-sentence-encoder'
27+
dir: 'deeplab'
2828
entrypoint: 'yarn'
2929
id: 'build'
3030
args: ['build']
3131
waitFor: ['yarn']
3232

3333
# Run tests.
3434
- name: 'node:10'
35-
dir: 'universal-sentence-encoder'
35+
dir: 'deeplab'
3636
entrypoint: 'yarn'
3737
id: 'test'
3838
args: ['test']

deeplab/demo/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This demo allows you to try out semantic segmentation on a couple of preset imag
44

55
## Setup
66

7+
Run `yarn build-npm` in the 'deeplab' folder.
8+
79
Change the directory to the `demo` folder:
810

911
```sh

deeplab/demo/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
"node": ">=8.9.0"
1010
},
1111
"dependencies": {
12-
"@tensorflow-models/deeplab": "0.1.0",
13-
"@tensorflow/tfjs-converter": "1.3.1",
14-
"@tensorflow/tfjs-core": "1.3.1",
12+
"@tensorflow-models/deeplab": "file:../dist",
13+
"@tensorflow/tfjs-converter": "^3.0.0-rc.1",
14+
"@tensorflow/tfjs-core": "^3.0.0-rc.1",
15+
"@tensorflow/tfjs-backend-webgl": "^3.0.0-rc.1",
1516
"bulma": "^0.7.5"
1617
},
1718
"scripts": {
18-
"watch": "cross-env NODE_ENV=development parcel src/index.html --no-hmr",
19+
"watch": "cross-env NODE_ENV=development parcel src/index.html --no-hmr --open",
1920
"build": "cross-env NODE_ENV=production parcel build src/index.html --no-minify --public-url ./",
2021
"lint": "eslint .",
2122
"link-local": "yalc add --link @tensorflow-models/deeplab"

deeplab/demo/src/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import 'bulma/css/bulma.css';
19+
import '@tensorflow/tfjs-backend-webgl';
1920

2021
import {load} from '@tensorflow-models/deeplab';
2122
import * as tf from '@tensorflow/tfjs-core';
@@ -134,7 +135,7 @@ const runPrediction = (modelName, input, initialisationStart) => {
134135
model.segment(input).then((output) => {
135136
displaySegmentationMap(modelName, output);
136137
status(`Ran in ${
137-
((performance.now() - initialisationStart) / 1000).toFixed(2)} s`);
138+
((performance.now() - initialisationStart) / 1000).toFixed(2)} s`);
138139
});
139140
});
140141
};
@@ -166,7 +167,7 @@ const runDeeplab = async (modelName) => {
166167
deeplab[modelName] = load({base: modelName, quantizationBytes});
167168
await deeplab[modelName];
168169
status(`Loaded the model in ${
169-
((performance.now() - loadingStart) / 1000).toFixed(2)} s`);
170+
((performance.now() - loadingStart) / 1000).toFixed(2)} s`);
170171
}
171172
const predictionStart = performance.now();
172173
if (input.complete && input.naturalHeight !== 0) {

deeplab/demo/yarn.lock

+39-22
Original file line numberDiff line numberDiff line change
@@ -887,26 +887,43 @@
887887
"@parcel/utils" "^1.11.0"
888888
physical-cpu-count "^2.0.0"
889889

890-
"@tensorflow-models/[email protected]":
891-
version "0.1.0"
892-
resolved "https://registry.yarnpkg.com/@tensorflow-models/deeplab/-/deeplab-0.1.0.tgz#79e492210d557acb1cd78bc267a25bb978116729"
893-
integrity sha512-duAOo9QiZrh0JnxGkojIyK5qU7j4XRZw7lC7kkLjuDPioe7kdGoXwGyj6WpcTWjyrzGZAvDxI0xBsC/PrgXQsA==
890+
"@tensorflow-models/deeplab@file:../dist":
891+
version "0.0.0"
894892

895-
"@tensorflow/[email protected]":
896-
version "1.3.1"
897-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-1.3.1.tgz#4e08e07621f43690a0b69c345cd63bc1f6974879"
898-
integrity sha512-8IHzcIZwqCofcRBhaCTN6W73m2RGdBDH6BEORf0KDdbgbz4DouItVcKX692PrA8gchY+Xy8ZHMpj93PcAOs17g==
893+
"@tensorflow/[email protected]":
894+
version "3.0.0-rc.1"
895+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-3.0.0-rc.1.tgz#b02e05706b2d91ab601e7eb397b6ea60ac0a9e2e"
896+
integrity sha512-9+13fs3vVpfOpDY+Aa/JXdda2SuBN/clxxoNYIX3pMY0GAGwpUaAkSECLuOOhnngHcl9pxuaJtgqrCcrq+A3/A==
897+
dependencies:
898+
"@types/seedrandom" "2.4.27"
899+
seedrandom "2.4.3"
899900

900-
"@tensorflow/[email protected]":
901-
version "1.3.1"
902-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-1.3.1.tgz#89e3253f320233120ee24d4ae62fca65c315580f"
903-
integrity sha512-X4MKhpg1gLEZetKUMeQNW6diP3gbFFddeF6UT816sH8jOenX/8x2HnVmANpNnUxCTPhDniY3V9zhBWwbl13+Yg==
901+
"@tensorflow/tfjs-backend-webgl@^3.0.0-rc.1":
902+
version "3.0.0-rc.1"
903+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-webgl/-/tfjs-backend-webgl-3.0.0-rc.1.tgz#21aacedcef687d2bb075c7951ac9e4f57faa79e6"
904+
integrity sha512-qEjtL/71HflBHJgWXhtj+8BVYB9Q+NHw282QGWi9QLA9SlWe3BRJhbGCaD28/Ddl+mSzBWFQnK+sKdZ04LL1Sg==
905+
dependencies:
906+
"@tensorflow/tfjs-backend-cpu" "3.0.0-rc.1"
907+
"@types/offscreencanvas" "~2019.3.0"
908+
"@types/seedrandom" "2.4.27"
909+
"@types/webgl-ext" "0.0.30"
910+
"@types/webgl2" "0.0.5"
911+
seedrandom "2.4.3"
912+
913+
"@tensorflow/tfjs-converter@^3.0.0-rc.1":
914+
version "3.0.0-rc.1"
915+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-3.0.0-rc.1.tgz#a15eb72ade80f7ae0e6403020763be0c5af6f2f7"
916+
integrity sha512-vVezwsDtrqM9CGDU+9c1WvPbLB5Odi9uiyEUHZEXMgNnPZ9Ix8a7RFOL7Y+8uBsI3B5wmLrWJuUNeyxUjA7yiA==
917+
918+
"@tensorflow/tfjs-core@^3.0.0-rc.1":
919+
version "3.0.0-rc.1"
920+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-3.0.0-rc.1.tgz#0b5316871eef2a4c8aa149d154e6ea6bbc7b631e"
921+
integrity sha512-h9a0TyWNJFqgmyfSklwI2q0SC93WFr8FBHwHorvsfm2mDK0ZrSs6bhWqa44tWRJjCrJNRq9J4GoTZQM292RTwg==
904922
dependencies:
905923
"@types/offscreencanvas" "~2019.3.0"
906924
"@types/seedrandom" "2.4.27"
907925
"@types/webgl-ext" "0.0.30"
908-
"@types/webgl2" "0.0.4"
909-
node-fetch "~2.1.2"
926+
node-fetch "~2.6.1"
910927
seedrandom "2.4.3"
911928

912929
"@types/offscreencanvas@~2019.3.0":
@@ -929,10 +946,10 @@
929946
resolved "https://registry.yarnpkg.com/@types/webgl-ext/-/webgl-ext-0.0.30.tgz#0ce498c16a41a23d15289e0b844d945b25f0fb9d"
930947
integrity sha512-LKVgNmBxN0BbljJrVUwkxwRYqzsAEPcZOe6S2T6ZaBDIrFp0qu4FNlpc5sM1tGbXUYFgdVQIoeLk1Y1UoblyEg==
931948

932-
"@types/[email protected].4":
933-
version "0.0.4"
934-
resolved "https://registry.yarnpkg.com/@types/webgl2/-/webgl2-0.0.4.tgz#c3b0f9d6b465c66138e84e64cb3bdf8373c2c279"
935-
integrity sha512-PACt1xdErJbMUOUweSrbVM7gSIYm1vTncW2hF6Os/EeWi6TXYAYMPp+8v6rzHmypE5gHrxaxZNXgMkJVIdZpHw==
949+
"@types/[email protected].5":
950+
version "0.0.5"
951+
resolved "https://registry.yarnpkg.com/@types/webgl2/-/webgl2-0.0.5.tgz#dd925e20ab8ace80eb4b1e46fda5b109c508fb0d"
952+
integrity sha512-oGaKsBbxQOY5+aJFV3KECDhGaXt+yZJt2y/OZsnQGLRkH6Fvr7rv4pCt3SRH1somIHfej/c4u7NSpCyd9x+1Ow==
936953

937954
abab@^2.0.0:
938955
version "2.0.0"
@@ -3805,10 +3822,10 @@ node-addon-api@^1.6.0:
38053822
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-1.7.1.tgz#cf813cd69bb8d9100f6bdca6755fc268f54ac492"
38063823
integrity sha512-2+DuKodWvwRTrCfKOeR24KIc5unKjOh8mz17NCzVnHWfjAdDqbfbjqh7gUT+BkXBRQM52+xCHciKWonJ3CbJMQ==
38073824

3808-
node-fetch@~2.1.2:
3809-
version "2.1.2"
3810-
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5"
3811-
integrity sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=
3825+
node-fetch@~2.6.1:
3826+
version "2.6.1"
3827+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
3828+
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
38123829

38133830
node-forge@^0.7.1:
38143831
version "0.7.6"

deeplab/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
"url": "https://github.com/tensorflow/tfjs-models"
1414
},
1515
"peerDependencies": {
16-
"@tensorflow/tfjs-converter": "^1.2.5",
17-
"@tensorflow/tfjs-core": "^1.2.5"
16+
"@tensorflow/tfjs-converter": "^3.0.0-rc.1",
17+
"@tensorflow/tfjs-core": "^3.0.0-rc.1"
1818
},
1919
"devDependencies": {
20-
"@tensorflow/tfjs-converter": "^1.3.1",
21-
"@tensorflow/tfjs-core": "^1.3.1",
20+
"@tensorflow/tfjs-converter": "^3.0.0-rc.1",
21+
"@tensorflow/tfjs-core": "^3.0.0-rc.1",
22+
"@tensorflow/tfjs-backend-cpu": "^3.0.0-rc.1",
2223
"@types/jasmine": "~3.3.15",
23-
"canvas": "^2.5.0",
2424
"clang-format": "^1.2.4",
2525
"jasmine": "^3.2.0",
2626
"jasmine-core": "~3.4.0",
@@ -29,14 +29,14 @@
2929
"rollup-plugin-node-resolve": "~5.2.0",
3030
"rollup-plugin-terser": "^5.1.1",
3131
"rollup-plugin-typescript2": "~0.22.0",
32-
"ts-node": "~8.3.0",
32+
"ts-node": "~5.0.0",
3333
"tslint": "~5.18.0",
3434
"typescript": "3.5.3",
3535
"yalc": "~1.0.0-pre.32"
3636
},
3737
"scripts": {
3838
"build": "rimraf dist && tsc",
39-
"test": "ts-node --project tsconfig.test.json run_tests.ts",
39+
"test": "ts-node --skip-ignore --project tsconfig.test.json run_tests.ts",
4040
"publish-local": "yarn build && rollup -c && yalc push",
4141
"build-npm": "yarn build && rollup -c",
4242
"lint": "tslint -p . -t verbose"

deeplab/run_tests.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
import * as jasmine_util from '@tensorflow/tfjs-core/dist/jasmine_util';
1919
import {runTests} from '../test_util';
2020

21+
import '@tensorflow/tfjs-backend-cpu';
22+
2123
runTests(jasmine_util);

deeplab/src/deeplab_test.ts

-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import * as tf from '@tensorflow/tfjs-core';
1818
// tslint:disable-next-line: no-imports-from-dist
1919
import {describeWithFlags, NODE_ENVS,} from '@tensorflow/tfjs-core/dist/jasmine_util';
20-
import {createCanvas} from 'canvas';
2120
import {load} from '.';
2221

2322
describeWithFlags('SemanticSegmentation', NODE_ENVS, () => {
@@ -46,12 +45,4 @@ describeWithFlags('SemanticSegmentation', NODE_ENVS, () => {
4645
expect(Object.keys(legend)).toContain('background');
4746
});
4847

49-
it('SemanticSegmentation produces a valid segmentation of an empty canvas',
50-
async () => {
51-
const model = await load();
52-
const x = createCanvas(200, 200);
53-
// tslint:disable-next-line: no-any
54-
const {legend} = await model.segment((x as any) as HTMLCanvasElement);
55-
expect(Object.keys(legend)).toContain('background');
56-
});
5748
});

deeplab/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class SemanticSegmentation {
119119
*/
120120
public predict(input: DeepLabInput): tf.Tensor2D {
121121
return tf.tidy(() => {
122-
const data = toInputTensor(input);
122+
const data = tf.cast(toInputTensor(input), 'int32');
123123
return tf.squeeze(this.model.execute(data) as tf.Tensor);
124124
});
125125
}

deeplab/src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ export function toInputTensor(input: DeepLabInput) {
138138
const resizeRatio = config['CROP_SIZE'] / Math.max(width, height);
139139
const targetHeight = Math.round(height * resizeRatio);
140140
const targetWidth = Math.round(width * resizeRatio);
141-
return tf.image.resizeBilinear(image, [targetHeight, targetWidth])
142-
.expandDims(0);
141+
return tf.expandDims(
142+
tf.image.resizeBilinear(image, [targetHeight, targetWidth]));
143143
});
144144
}
145145

0 commit comments

Comments
 (0)