Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Commit

Permalink
benchmarks: security fix and minor improvements (#363)
Browse files Browse the repository at this point in the history
- Upgrade parcel-bundler to fix security issue
- Add .babelrc
- Remove the loading of weights (just load topology)
- Add navigator.userAgent to benchmarks page

DEV
  • Loading branch information
caisq committed Nov 5, 2018
1 parent 5c170ba commit 7ce9ee4
Show file tree
Hide file tree
Showing 6 changed files with 1,623 additions and 1,281 deletions.
19 changes: 19 additions & 0 deletions integration_tests/benchmarks/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

{
"presets": [
[
"env",
{
"esmodules": false,
"targets": {
"browsers": [
"> 3%"
]
}
}
]
],
"plugins": [
"transform-runtime"
]
}
3 changes: 3 additions & 0 deletions integration_tests/benchmarks/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ <h1>TensorFlow.js Layers: Benchmarks Demo</h1>
<div>
Benchmark timestamp:<span class="metadata" id="benchmark-timestamp"></span>
</div>
<div>
navigator.userAgent:<span class="metadata" id="navigator-userAgent"></span>
</div>
<div>
TensorFlow.js Core version:<span class="metadata" id="tfjs-core-version"></span>
</div>
Expand Down
9 changes: 6 additions & 3 deletions integration_tests/benchmarks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import * as ui from './ui';
async function runBenchmark(artifactsDir, modelName, config) {
const modelPath = artifactsDir + modelName + '/';
console.log('Loading model "' + modelName + '" and benchmark data...');
const model = await tfl.loadModel(modelPath + 'model.json');
// Note: currently we load only the topology. The weight values don't matter
// for the benchmarks and are initialized according to the initializer.
const modelJSON = await (await fetch(modelPath + 'model.json')).json();
const model = await tfl.models.modelFromJSON(modelJSON['modelTopology']);
console.log('Done loading model "' + modelName + '" and benchmark data.');

const benchmarkData = await (await fetch(modelPath + 'data.json')).json();
Expand Down Expand Up @@ -140,7 +143,7 @@ function getRunAllBenchmarks(artifactsDir, benchmarks) {
ui.status(
'Running model (' + (i + 1) + ' of ' + benchmarks.models.length +
'): "' + modelName +
'" ... (Please wait patiently. Do NOT click anything.)');
'" ... (Please wait patiently. Do NOT click or scroll anything.)');
await tfc.nextFrame();
console.log('Benchmarking model: ' + modelName);
const result =
Expand All @@ -153,7 +156,7 @@ function getRunAllBenchmarks(artifactsDir, benchmarks) {
}

async function setupBenchmarks() {
const artifactsDir = './dist/data/';
const artifactsDir = 'data/';

console.log('Loading benchmarks...');
const url = 'http:' + artifactsDir + 'benchmarks.json';
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
},
"dependencies": {
"@tensorflow/tfjs-core": "^0.13.8",
"@tensorflow/tfjs-layers": "../../dist",
"vega-embed": "~3.0.0"
"@tensorflow/tfjs-layers": "../../dist"
},
"scripts": {
"build": "cross-env NODE_ENV=production parcel build index.html --no-minify --public-url ./",
"watch": "NODE_ENV=development parcel --no-hmr --open index.html",
"watch": "NODE_ENV=development parcel index.html --no-hmr --open",
"lint": "eslint ./*.js"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-plugin-transform-runtime": "~6.23.0",
"babel-polyfill": "~6.26.0",
"babel-preset-env": "~1.6.1",
"clang-format": "~1.2.2",
"cross-env": "^5.1.6",
"eslint": "~4.19.1",
"http-server": "~0.10.0",
"parcel-bundler": "~1.6.2"
"parcel-bundler": "~1.10.3"
},
"babel": {
"presets": [
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/benchmarks/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function status(statusText) {

export function setMetadata(metadata) {
document.getElementById('benchmark-timestamp').textContent = new Date().toISOString();
document.getElementById('navigator-userAgent').textContent = navigator.userAgent;
document.getElementById('pyKerasVersion').textContent = metadata.keras_version;
document.getElementById('tfVersion').textContent = metadata.tensorflow_version;
document.getElementById('tfUsesGPU').textContent = metadata.tensorflow_uses_gpu;
Expand All @@ -37,7 +38,7 @@ export function addResult(modelName, result) {
result.originalData.train_epochs > 0 ?
result.originalData.train_epochs : 'N/A';
row += '<td>' + trainEpochsStr + '</td>';
const originalTrainTimeStr =
const originalTrainTimeStr =
result.originalData.train_epochs > 0 ?
(result.originalData.train_time * 1e3).toFixed(1) : 'N/A';
row += '<td>' + originalTrainTimeStr + '</td>';
Expand Down
Loading

0 comments on commit 7ce9ee4

Please sign in to comment.