Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit 8d4ac32

Browse files
committed
Resolve conflict
2 parents a824de6 + e4d7607 commit 8d4ac32

File tree

233 files changed

+16686
-2461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+16686
-2461
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ bazel-out/
1313
yalc.lock
1414
.rpt2_cache/
1515
package/
16+
17+
tfjs-backend-wasm/dist
18+
tfjs-backend-wasm/wasm-out

.npmignore

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
# Ignore other packages in the mono-repo.
2+
tfjs-webgpu/
3+
tfjs-backend-nodegl/
4+
tfjs-react-native/
5+
16
.vscode/
27
.rpt2_cache/
38
src/**/*_test.ts
49
integration_tests/
5-
src/backends/webgpu/
6-
dist/backends/webgpu/
10+
711
dist/backends/**/*_test.js
812
models/
913
coverage/
@@ -23,3 +27,5 @@ rollup.config.js
2327
tsconfig.json
2428
.yalc/
2529
yalc.lock
30+
tfjs-react-native/
31+
tfjs-backend-nodegl/

.vscode/c_cpp_properties.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"~/emsdk/fastcomp/emscripten/system/include/**"
8+
],
9+
"defines": [],
10+
"macFrameworkPath": [
11+
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
12+
],
13+
"compilerPath": "/usr/bin/clang",
14+
"cStandard": "c11",
15+
"cppStandard": "c++11",
16+
"intelliSenseMode": "clang-x64"
17+
}
18+
],
19+
"version": 4
20+
}

.vscode/settings.json

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"**/.rpt2_cache/": true,
99
"**/.yalc/**/*": true
1010
},
11-
"tslint.enable": true,
12-
"tslint.run": "onType",
1311
"tslint.configFile": "tslint.json",
1412
"files.trimTrailingWhitespace": true,
1513
"editor.tabSize": 2,

benchmarks/index.html

+181-42
Original file line numberDiff line numberDiff line change
@@ -169,39 +169,160 @@ <h2>TensorFlow.js Model Benchmark</h2>
169169
<tbody></tbody>
170170
</table>
171171
</div>
172-
<script src="https://unpkg.com/@tensorflow/tfjs-core/dist/tf-core.js"></script>
173-
<script src="https://unpkg.com/@tensorflow/tfjs-layers/dist/tf-layers.js"></script>
174-
<script src="https://unpkg.com/@tensorflow/tfjs-converter/dist/tf-converter.js"></script>
175-
<script>
176-
'use strict';
177-
async function load() {
178-
//////////////////////////////////
179-
// Place model loading code here.
180-
//////////////////////////////////
181-
return await tf.loadGraphModel(
182-
'https://tfhub.dev/google/imagenet/mobilenet_v2_050_224/classification/2', { fromTFHub: true });
183-
}
184-
185-
const zeros = tf.zeros([1, 224, 224, 3]);
186-
function predict(model) {
187-
//////////////////////////////////
188-
// Place model prediction code here.
189-
//////////////////////////////////
190-
if (isAsync) {
191-
return model.executeAsync(zeros);
192-
}
193-
return model.predict(zeros);
194-
}
195-
</script>
172+
<script src="https://unpkg.com/@tensorflow/tfjs-core@latest/dist/tf-core.js"></script>
173+
<script src="https://unpkg.com/@tensorflow/tfjs-layers@latest/dist/tf-layers.js"></script>
174+
<script src="https://unpkg.com/@tensorflow/tfjs-converter@latest/dist/tf-converter.js"></script>
175+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/universal-sentence-encoder"></script>
176+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/[email protected]/dist/posenet.min.js"></script>
196177
<script>
197178
'use strict';
179+
180+
const sentences = [
181+
'add clem burke in my playlist Pre-Party R&B Jams',
182+
'Add Live from Aragon Ballroom to Trapeo',
183+
'add Unite and Win to my night out',
184+
'Add track to my Digster Future Hits',
185+
'add the piano bar to my Cindy Wilson',
186+
'Add Spanish Harlem Incident to cleaning the house',
187+
'add The Greyest of Blue Skies in Indie Español my playlist',
188+
'Add the name kids in the street to the plylist New Indie Mix',
189+
'add album radar latino',
190+
'Add Tranquility to the Latin Pop Rising playlist.',
191+
'play something from the twenties',
192+
'Play The View From The Afternoon by Malese Jow on Last Fm',
193+
'play songs by Sammy Fain',
194+
'Play music from the year 1964',
195+
'Play the heinz strobl ep from 2016 on Groove Shark',
196+
'Play me Leonid Soybelman on Vimeo.',
197+
'Play a song from my workout playlist on Groove Shark',
198+
'play some Alte Kameraden music',
199+
'Will it be warm 1 week from now in DC',
200+
'what is the forecast for temperate conditions in Thailand in Lopeno',
201+
'Is the weather colder in Costa Rica',
202+
'Will it be colder in Delaware?',
203+
'"I need to know the weather for Hamorton, TN"',
204+
'What will the weather be in Albania at 11:56.',
205+
'Is it going to hail in Mount San Jacinto State Park',
206+
'What\'s the forecast for Walker Bay Nature Reserve for next year ? ',
207+
'is it supposed to be sunny here?',
208+
'in California will it be cold in East Trenton Heights',
209+
'What is the weather like in Wallis and Futuna? What will the weather be in Romania at 4?',
210+
'What is the weather going to be like in Reidland New Mexico next Jun.?',
211+
'How cold is it in Cargray, Argentina?',
212+
'Is the forecast chillier in 1 hour in Mali',
213+
'Tell me if there will be wind in NE Will it be cloudy not far from Allenton Will there be a blizzard in AR what is the New Caledonia forecast for Bagnell on sep. the 5th Weather for apr. the thirteenth in Djibouti',
214+
'Can you give me the weather forecast in Tajikistan? How cold is it going to be in San Marcial, AK in one second? What will the weather be in a month from now at my current location?',
215+
'What is the weather like in IA in april How windy is it in Anderson Lake State Fish and Wildlife Area? Is it going to be stormy in Austin Creek State Recreation Area at 09:42?',
216+
'When will the weather be temperate like it is now in Stansbury Park in Tuvalu, What is the weather in neighboring OH, What\'s the weather forecast for Spain ? ',
217+
'Play the music Hands Up',
218+
'Play some twenties theme music on Google Music.',
219+
'How will the weather be in New Mexico around 00:09:07 am?',
220+
'What will the humidity be in AR in 49 weeks and a half from now',
221+
'Is it humid in Parc national de Killarney',
222+
'is it supposed to get colder here on 12/28/2019',
223+
'How is the forecast for OK?',
224+
'what is the Posey Island State Park forecast for colder temps at meal time',
225+
'Is it supposed to be chilly in Kuwait?',
226+
'Tell me if it\'ll be chilly here at 0 pm',
227+
'what is the forecast for colder conditions within the same area of this current place',
228+
'Will it hail today in West Point at 11:36:48',
229+
'Is it overcast in South Carolina',
230+
'Will the sun be out close-by Admiralty Island National Monument?',
231+
'What will the weather be in Wakarusa',
232+
'How temperate will it be here this week?',
233+
'what is the forecast for here at tea time',
234+
];
235+
236+
const benchmarks = {
237+
'mobilenet': {
238+
load: async () => {
239+
const url = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/2'
240+
return tf.loadGraphModel(url, { fromTFHub: true });
241+
},
242+
predictFunc: () => {
243+
const zeros = tf.zeros([1, 224, 224, 3]);
244+
return (model) => {
245+
if (isAsync) {
246+
return model.executeAsync(zeros);
247+
}
248+
return model.predict(zeros);
249+
}
250+
}
251+
},
252+
'USE - batchsize 30': {
253+
load: async () => {
254+
return use.load();
255+
},
256+
predictFunc: () => {
257+
const sentences30 = sentences.slice(0, 30);
258+
return async (model) => {
259+
const res = await model.embed(sentences30);
260+
return await res.data();
261+
}
262+
263+
}
264+
},
265+
'USE - batchsize 1': {
266+
load: async () => {
267+
return use.load();
268+
},
269+
predictFunc: () => {
270+
let nextIdx = 0;
271+
272+
return async () => {
273+
const next = [sentences[(nextIdx % sentences.length)]];
274+
const res = await model.embed(next);
275+
nextIdx += 1;
276+
return await res.data();
277+
}
278+
}
279+
},
280+
'posenet': {
281+
load: async () => {
282+
const imageBucket =
283+
'https://storage.googleapis.com/tfjs-models/assets/posenet/';
284+
285+
async function loadImage(imagePath) {
286+
const image = new Image();
287+
const promise = new Promise((resolve, reject) => {
288+
image.crossOrigin = '';
289+
image.onload = () => {
290+
resolve(image);
291+
};
292+
});
293+
294+
image.src = `${imageBucket}${imagePath}`;
295+
return promise;
296+
}
297+
298+
const posenetModel = await posenet.load();
299+
const image = await loadImage('tennis_standing.jpg');
300+
301+
posenetModel.benchmarkImage = image;
302+
return posenetModel;
303+
},
304+
predictFunc: () => {
305+
return async (model) => {
306+
const image = model.benchmarkImage;
307+
const pose = await model.estimateSinglePose(image);
308+
return pose;
309+
}
310+
}
311+
},
312+
};
313+
198314
const state = {
199315
numRuns: 50,
316+
benchmark: 'mobilenet',
317+
run: (v) => {
318+
runBenchmark();
319+
},
200320
};
321+
201322
const modalDiv = document.getElementById('modal-msg');
202323
const timeTable = document.querySelector('#timings tbody');
203324
const envDiv = document.getElementById('env');
204-
let model, isAsync;
325+
let model, isAsync, predict;
205326

206327
async function showMsg(message) {
207328
if (message != null) {
@@ -248,7 +369,7 @@ <h2>TensorFlow.js Model Benchmark</h2>
248369
if (c instanceof HTMLElement) {
249370
td.appendChild(c);
250371
} else {
251-
td.textContent = c;
372+
td.innerHTML = c;
252373
}
253374
tr.appendChild(td);
254375
});
@@ -276,14 +397,19 @@ <h2>TensorFlow.js Model Benchmark</h2>
276397
return new Promise(resolve => setTimeout(resolve, timeMs));
277398
}
278399

279-
async function loadAndRecordTime() {
400+
async function loadAndRecordTime(benchmark) {
280401
await showMsg('Loading the model');
281402
const start = performance.now();
282-
model = await load();
403+
model = await benchmark.load();
404+
predict = benchmark.predictFunc();
283405
isAsync = model.executor != null && model.executor.isControlFlowModel;
284406

285407
const elapsed = performance.now() - start;
286408
await showMsg(null);
409+
410+
appendRow(timeTable, `<b>Benchmark:</b> ${state.benchmark}`,
411+
`<b>Runs:</b> ${state.numRuns}`);
412+
287413
appendRow(timeTable, 'Model load', printTime(elapsed));
288414
}
289415

@@ -300,7 +426,7 @@ <h2>TensorFlow.js Model Benchmark</h2>
300426
const start = performance.now();
301427
let res = predict(model);
302428
if (res instanceof Promise) {
303-
res = await res;
429+
await res;
304430
}
305431

306432
if (res instanceof tf.Tensor) {
@@ -354,7 +480,7 @@ <h2>TensorFlow.js Model Benchmark</h2>
354480

355481
async function profileKernelTime() {
356482
await showMsg('Profiling kernels');
357-
tf.ENV.set('DEBUG', true);
483+
_tfengine.ENV.set('DEBUG', true);
358484
const oldLog = console.log;
359485
let kernels = [];
360486
console.log = msg => {
@@ -393,25 +519,23 @@ <h2>TensorFlow.js Model Benchmark</h2>
393519
await sleep(10);
394520
kernels = kernels.sort((a, b) => b.time - a.time);
395521
appendRow(timeTable, 'Number of kernels', kernels.length);
522+
523+
// Add an empty row at the end of a benchmark run
524+
appendRow(timeTable, '', '');
396525
showKernelTime(kernels);
397-
tf.ENV.set('DEBUG', false);
526+
_tfengine.ENV.set('DEBUG', false);
398527
// Switch back to the old log;
399528
console.log = oldLog;
400529
}
401530

402531
function queryTimerIsEnabled() {
403-
return tf.ENV.getNumber('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0;
532+
return _tfengine.ENV.getNumber('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0;
404533
}
405534

406-
async function onPageLoad() {
407-
var gui = new dat.gui.GUI();
408-
//gui.remember(obj);
409-
gui.add(state, 'numRuns').onChange(v => {
410-
measureAveragePredictTime();
411-
});
412-
showVersions();
413-
await showEnvironment();
414-
await loadAndRecordTime();
535+
536+
async function runBenchmark() {
537+
const benchmark = benchmarks[state.benchmark];
538+
await loadAndRecordTime(benchmark);
415539
await warmUpAndRecordTime();
416540
await showMsg('Waiting for GC');
417541
await sleep(1000);
@@ -426,8 +550,23 @@ <h2>TensorFlow.js Model Benchmark</h2>
426550
'available. <br/> Use Chrome 70+.');
427551
};
428552
}
553+
554+
async function onPageLoad() {
555+
var gui = new dat.gui.GUI();
556+
557+
gui.add(state, 'numRuns');
558+
gui.add(state, 'benchmark', ['', ...Object.keys(benchmarks)]);
559+
gui.add(state, 'run');
560+
561+
showVersions();
562+
await showEnvironment();
563+
564+
// Run first benchmark by default on page load.
565+
runBenchmark();
566+
}
567+
429568
onPageLoad();
430569
</script>
431570
</body>
432571

433-
</html>
572+
</html>

0 commit comments

Comments
 (0)