Skip to content

Commit e653b4c

Browse files
authored
align coco-ssd with 2.0.1 releases (#462)
* align coco-ssd with 2.0.1 releases * update dev deps versions * fix tests and updated rollup * fixed presubmit script * fix lint * update build-npm script
1 parent c37b119 commit e653b4c

16 files changed

+793
-874
lines changed

coco-ssd/demo/index.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ <h1>TensorFlow.js Object Detection</h1>
2424
</select>
2525
<button type="button" id="run">Run</button>
2626
<button type="button" id="toggle">Toggle Image</button>
27-
<div>
28-
<img id="image"/>
29-
<canvas id="canvas" width="600" height="399"></canvas>
30-
</div>
27+
<div>
28+
<img id="image" />
29+
<canvas id="canvas" width="600" height="399"></canvas>
30+
</div>
3131
</body>
32-
3332
<script src="index.js"></script>
34-
</html>
33+
34+
35+
</html>

coco-ssd/demo/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* limitations under the License.
1515
* =============================================================================
1616
*/
17-
1817
import * as cocoSsd from '@tensorflow-models/coco-ssd'
18+
import * as cpu from '@tensorflow/tfjs-backend-cpu'
19+
import * as webgl from '@tensorflow/tfjs-backend-webgl'
1920

2021
import imageURL from './image1.jpg';
2122
import image2URL from './image2.jpg';

coco-ssd/demo/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
"node": ">=8.9.0"
1010
},
1111
"dependencies": {
12-
"@tensorflow-models/coco-ssd": "2.0.2",
13-
"@tensorflow/tfjs-converter": "1.7.2",
14-
"@tensorflow/tfjs-core": "1.7.2",
12+
"@tensorflow-models/coco-ssd": "2.0.4",
13+
"@tensorflow/tfjs-converter": "2.0.1",
14+
"@tensorflow/tfjs-core": "2.0.1",
15+
"@tensorflow/tfjs-backend-cpu": "2.0.1",
16+
"@tensorflow/tfjs-backend-webgl": "2.0.1",
1517
"stats.js": "^0.17.0"
1618
},
1719
"scripts": {
@@ -55,4 +57,4 @@
5557
"eslintIgnore": [
5658
"dist/"
5759
]
58-
}
60+
}

coco-ssd/demo/yarn.lock

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -742,20 +742,40 @@
742742
"@parcel/utils" "^1.11.0"
743743
physical-cpu-count "^2.0.0"
744744

745-
"@tensorflow-models/[email protected]":
745+
"@tensorflow-models/[email protected]":
746+
version "2.0.2"
747+
resolved "https://registry.yarnpkg.com/@tensorflow-models/coco-ssd/-/coco-ssd-2.0.2.tgz#4fc546f880a72546c5eaf089e8c57f771a4bff62"
748+
integrity sha512-c7qoZ0VNL29nFXJyDRS6pGWK4AdxJRipie04Nwp6XGAiDaC0FK8QUHamlKOavE1xDDvHb1d5OQNkHGiCWzWLbQ==
749+
750+
"@tensorflow/[email protected]":
751+
version "2.0.1"
752+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-2.0.1.tgz#959a5bbc7f956ff37c4fbced2db75cd299ce76c4"
753+
integrity sha512-ZTDdq+O6AgeOrkek42gmPWz2T0r8Y6dBGjEFWkCMLI/5v3KnkodUkHRQOUoIN5hiaPXnBp6425DpwT9CfxxJOg==
754+
dependencies:
755+
"@types/seedrandom" "2.4.27"
756+
seedrandom "2.4.3"
757+
758+
"@tensorflow/[email protected]":
759+
version "2.0.1"
760+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-webgl/-/tfjs-backend-webgl-2.0.1.tgz#08eaff7fe9a7533b4d62475ec6220e843962af89"
761+
integrity sha512-Z0MNsbHyRBr2lHu4FKtmBgGGfmBOqB0zwN69d2uSEEvy/IsgtrGAwBVbB/Vv3hEK35RmgsaknKGergNugm23FQ==
762+
dependencies:
763+
"@tensorflow/tfjs-backend-cpu" "2.0.1"
764+
"@types/offscreencanvas" "~2019.3.0"
765+
"@types/seedrandom" "2.4.27"
766+
"@types/webgl-ext" "0.0.30"
767+
"@types/webgl2" "0.0.4"
768+
seedrandom "2.4.3"
769+
770+
"@tensorflow/[email protected]":
771+
version "2.0.1"
772+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-2.0.1.tgz#0696455e6b6ed14e6f5f9cd937f8f2015a16569f"
773+
integrity sha512-AI4oUZ3Tv8l7fXeuLNJ3/vIp8shMo/VmtBlhIJye8i5FwMqSlZf984q3Jk6ES4lOxUdkmDehILf7uVNQX2Yb/w==
774+
775+
"@tensorflow/[email protected]":
746776
version "2.0.1"
747-
resolved "https://registry.yarnpkg.com/@tensorflow-models/coco-ssd/-/coco-ssd-2.0.1.tgz#99b90d18821ae42caa9c3e6c2dad912f91282287"
748-
integrity sha512-+mh5eYXSK7WnQmxVbgFoClwMoQ0Vu8Ac2gyXREaNqpsLTqc2z+ZhcltEXdtHhbL8ZC6eCM7Uq3I9MXzomNsB7w==
749-
750-
"@tensorflow/[email protected]":
751-
version "1.7.2"
752-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-1.7.2.tgz#a2bb479f271aa9a5bb2909b3b8d90c431996893d"
753-
integrity sha512-6ckNQ3n36X20/+YDCTictfKftPH3urf5I+wc0QNlsSJhik3QiliYJy+v5hmjQGSJ4ow2oyW5T2lUsy9aNoNaTg==
754-
755-
"@tensorflow/[email protected]":
756-
version "1.7.2"
757-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-1.7.2.tgz#c7b4ac37a7b8bd7226766ee9bcd930274bf8e019"
758-
integrity sha512-2o5jjXLHrMY4f+r7aOfJZbKqrchEYrRk2mhlFD3RgKqtSKUpfv15YLQr4uc0uMbNSwuZbjWwrmaL9yyaBWYSAQ==
777+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-2.0.1.tgz#c64928423028e9e1821f7205367b1ff1f57ae3af"
778+
integrity sha512-LCmEXeGFgR3ai+ywGDYBqt4aCOSzEBlVKEflF1gAT22YcQuYh+/X4f58jY3yXfC+cn/FfIJFc2uj8b+D0MNWLQ==
759779
dependencies:
760780
"@types/offscreencanvas" "~2019.3.0"
761781
"@types/seedrandom" "2.4.27"

coco-ssd/package.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tensorflow-models/coco-ssd",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "Object detection model (coco-ssd) in TensorFlow.js",
55
"main": "dist/index.js",
66
"unpkg": "dist/coco-ssd.min.js",
@@ -13,32 +13,34 @@
1313
"url": "https://github.com/tensorflow/tfjs-models.git"
1414
},
1515
"peerDependencies": {
16-
"@tensorflow/tfjs-converter": "^1.2.5",
17-
"@tensorflow/tfjs-core": "^1.2.6"
16+
"@tensorflow/tfjs-converter": "^2.0.1",
17+
"@tensorflow/tfjs-core": "^2.0.1"
1818
},
1919
"devDependencies": {
20-
"@tensorflow/tfjs-converter": "^1.2.5",
21-
"@tensorflow/tfjs-core": "^1.2.6",
20+
"@rollup/plugin-commonjs": "^11.0.2",
21+
"@rollup/plugin-node-resolve": "^7.1.1",
22+
"@rollup/plugin-typescript": "^3.0.0",
23+
"@tensorflow/tfjs-backend-cpu": "^2.0.1",
24+
"@tensorflow/tfjs-converter": "^2.0.1",
25+
"@tensorflow/tfjs-core": "^2.0.1",
2226
"@types/jasmine": "~2.8.8",
2327
"babel-core": "~6.26.0",
2428
"babel-plugin-transform-runtime": "~6.23.0",
25-
"jasmine": "~3.3.1",
26-
"jasmine-core": "~3.3.0",
27-
"rollup": "~0.60.7",
28-
"rollup-plugin-node-resolve": "~3.3.0",
29-
"rollup-plugin-typescript2": "~0.15.0",
30-
"rollup-plugin-uglify": "~3.0.0",
31-
"ts-node": "~5.0.0",
29+
"jasmine-core": "~3.5.0",
30+
"rollup": "~2.3.2",
31+
"rollup-plugin-terser": "~5.3.0",
32+
"rollup-plugin-visualizer": "~3.3.2",
33+
"ts-node": "~8.8.2",
3234
"tslint": "~5.18.0",
33-
"typescript": "3.3.3333",
35+
"typescript": "~3.5.3",
3436
"yalc": "~1.0.0-pre.21"
3537
},
3638
"scripts": {
3739
"build": "rimraf dist && tsc",
3840
"lint": "tslint -p . -t verbose",
3941
"publish-local": "yarn build && rollup -c && yalc push",
40-
"build-npm": "yarn build && rollup -c",
41-
"test": "yarn build && ts-node run_tests.ts"
42+
"build-npm": "yarn build && rollup -c --visualize --npm",
43+
"test": "yarn build && ts-node --skip-ignore -P tsconfig.test.json run_tests.ts"
4244
},
4345
"license": "Apache-2.0"
4446
}

coco-ssd/rollup.config.js

Lines changed: 133 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,82 +15,153 @@
1515
* =============================================================================
1616
*/
1717

18-
import node from 'rollup-plugin-node-resolve';
19-
import typescript from 'rollup-plugin-typescript2';
20-
import uglify from 'rollup-plugin-uglify';
18+
import commonjs from '@rollup/plugin-commonjs';
19+
import resolve from '@rollup/plugin-node-resolve';
20+
import typescript from '@rollup/plugin-typescript';
21+
import {terser} from 'rollup-plugin-terser';
22+
import visualizer from 'rollup-plugin-visualizer';
2123

2224
const PREAMBLE = `/**
23-
* @license
24-
* Copyright ${(new Date).getFullYear()} Google LLC. All Rights Reserved.
25-
* Licensed under the Apache License, Version 2.0 (the "License");
26-
* you may not use this file except in compliance with the License.
27-
* You may obtain a copy of the License at
28-
*
29-
* http://www.apache.org/licenses/LICENSE-2.0
30-
*
31-
* Unless required by applicable law or agreed to in writing, software
32-
* distributed under the License is distributed on an "AS IS" BASIS,
33-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34-
* See the License for the specific language governing permissions and
35-
* limitations under the License.
36-
* =============================================================================
37-
*/`;
25+
* @license
26+
* Copyright ${(new Date).getFullYear()} Google LLC. All Rights Reserved.
27+
* Licensed under the Apache License, Version 2.0 (the "License");
28+
* you may not use this file except in compliance with the License.
29+
* You may obtain a copy of the License at
30+
*
31+
* http://www.apache.org/licenses/LICENSE-2.0
32+
*
33+
* Unless required by applicable law or agreed to in writing, software
34+
* distributed under the License is distributed on an "AS IS" BASIS,
35+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36+
* See the License for the specific language governing permissions and
37+
* limitations under the License.
38+
* =============================================================================
39+
*/`;
3840

39-
function minify() {
40-
return uglify({
41-
output: {
42-
preamble: PREAMBLE,
43-
}
44-
});
45-
}
41+
function config({
42+
plugins = [],
43+
output = {},
44+
external = [],
45+
visualize = false,
46+
tsCompilerOptions = {}
47+
}) {
48+
if (visualize) {
49+
const filename = output.file + '.html';
50+
plugins.push(visualizer({sourcemap: true, filename}));
51+
console.log(`Will output a bundle visualization in ${filename}`);
52+
}
53+
54+
const defaultTsOptions = {
55+
include: ['src/**/*.ts'],
56+
module: 'ES2015',
57+
};
58+
const tsoptions = Object.assign({}, defaultTsOptions, tsCompilerOptions);
4659

47-
function config({plugins = [], output = {}}) {
4860
return {
4961
input: 'src/index.ts',
5062
plugins: [
51-
typescript({
52-
tsconfigOverride: {
53-
compilerOptions: {module: 'ES2015'},
63+
typescript(tsoptions), resolve(),
64+
// Polyfill require() from dependencies.
65+
commonjs({
66+
ignore: ['crypto', 'node-fetch', 'util'],
67+
include: 'node_modules/**',
68+
namedExports: {
69+
'./node_modules/seedrandom/index.js': ['alea'],
5470
},
5571
}),
56-
node(), ...plugins
72+
...plugins
5773
],
5874
output: {
5975
banner: PREAMBLE,
60-
globals: {
61-
'@tensorflow/tfjs-core': 'tf',
62-
'@tensorflow/tfjs-converter': 'tf',
63-
},
64-
...output
76+
sourcemap: true,
77+
...output,
6578
},
66-
external: [
67-
'@tensorflow/tfjs-core',
68-
'@tensorflow/tfjs-converter',
69-
]
79+
external:
80+
['@tensorflow/tfjs-core', '@tensorflow/tfjs-converter', , ...external],
81+
onwarn: warning => {
82+
let {code} = warning;
83+
if (code === 'CIRCULAR_DEPENDENCY' || code === 'CIRCULAR' ||
84+
code === 'THIS_IS_UNDEFINED') {
85+
return;
86+
}
87+
console.warn('WARNING: ', warning.toString());
88+
}
7089
};
7190
}
7291

73-
export default [
74-
config({
75-
output: {
76-
format: 'umd',
77-
name: 'cocoSsd',
78-
file: 'dist/coco-ssd.js',
79-
}
80-
}),
81-
config({
82-
plugins: [minify()],
83-
output: {
84-
format: 'umd',
85-
name: 'cocoSsd',
86-
file: 'dist/coco-ssd.min.js',
87-
}
88-
}),
89-
config({
90-
plugins: [minify()],
92+
module.exports = cmdOptions => {
93+
const bundles = [];
94+
95+
const terserPlugin = terser({output: {preamble: PREAMBLE, comments: false}});
96+
const name = 'cocoSsd';
97+
const extend = true;
98+
const browserFormat = 'umd';
99+
const fileName = 'coco-ssd';
100+
101+
// Node
102+
bundles.push(config({
91103
output: {
92-
format: 'es',
93-
file: 'dist/coco-ssd.esm.js',
94-
}
95-
})
96-
];
104+
format: 'cjs',
105+
name,
106+
extend,
107+
file: `dist/${fileName}.node.js`,
108+
freeze: false
109+
},
110+
tsCompilerOptions: {target: 'es5'}
111+
}));
112+
113+
if (cmdOptions.ci || cmdOptions.npm) {
114+
// Browser default minified (ES5)
115+
bundles.push(config({
116+
plugins: [terserPlugin],
117+
output: {
118+
format: browserFormat,
119+
name,
120+
extend,
121+
file: `dist/${fileName}.min.js`,
122+
freeze: false
123+
},
124+
tsCompilerOptions: {target: 'es5'},
125+
visualize: cmdOptions.visualize
126+
}));
127+
}
128+
129+
if (cmdOptions.npm) {
130+
// Browser default unminified (ES5)
131+
bundles.push(config({
132+
output: {
133+
format: browserFormat,
134+
name,
135+
extend,
136+
file: `dist/${fileName}.js`,
137+
freeze: false
138+
},
139+
tsCompilerOptions: {target: 'es5'}
140+
}));
141+
142+
// Browser ES2017
143+
bundles.push(config({
144+
output: {
145+
format: browserFormat,
146+
name,
147+
extend,
148+
file: `dist/${fileName}.es2017.js`
149+
},
150+
tsCompilerOptions: {target: 'es2017'}
151+
}));
152+
153+
// Browser ES2017 minified
154+
bundles.push(config({
155+
plugins: [terserPlugin],
156+
output: {
157+
format: browserFormat,
158+
name,
159+
extend,
160+
file: `dist/${fileName}.es2017.min.js`
161+
},
162+
tsCompilerOptions: {target: 'es2017'}
163+
}));
164+
}
165+
166+
return bundles;
167+
};

0 commit comments

Comments
 (0)