diff --git a/examples/benchmark/config.vue b/examples/benchmark/config.vue index 04eb23eafe72775d735a57db60140152844efd63..f6bfed4de348f4c7853a27e43c00b9ab3d8973da 100644 --- a/examples/benchmark/config.vue +++ b/examples/benchmark/config.vue @@ -147,7 +147,7 @@ export default Vue.extend({ {name: 'preheat time', t: this.preheatT}, {name: 'subsequent average time', t: this.remainOthersT}, {name: 'best time', t: this.bestT}, - {name: 'op count', t: this.opCount} + {name: 'op count', t: this.opCount || '暂无'} ] } }, @@ -217,9 +217,23 @@ export default Vue.extend({ // this.remainOthersT = +(remainWholeT / (curTimes - 2).toFixed(4)); const {queryList} = this.paddle.model.graph; - const quertyResults = this.query(queryList); - if (!opCount) { - opCount = quertyResults.length; + + + if (queryList && queryList.length) { + const quertyResults = this.query(queryList); + + if (!opCount) { + opCount = quertyResults.length; + } + for (let item of quertyResults) { + progress.push({ + index: curTimes, + time: item.time, + name: item.name + }); + } + + ops.push(this.getOpPerf(quertyResults, this.aggregate, {}, true)); } progress.push({ @@ -228,18 +242,7 @@ export default Vue.extend({ name: 'total' }); - for (let item of quertyResults) { - progress.push({ - index: curTimes, - time: item.time, - name: item.name - }); - } - - totaltimeList.push(t); - - ops.push(this.getOpPerf(quertyResults, this.aggregate, {}, true)); curTimes++; } @@ -247,16 +250,20 @@ export default Vue.extend({ totaltimeList.sort((a, b) => a - b); this.bestT = totaltimeList[0]; - const opInfos = this.getOpPerf(ops, this.merge); - this.opCount = opCount; this.remainOthersT = (remainWholeT / this.times).toFixed(4); this.progress = progress; - this.ops = Object.keys(opInfos).map(opname => { - return { - name: opname, - time: opInfos[opname].time - }; - }); + + if (ops && ops.length) { + const opInfos = this.getOpPerf(ops, this.merge); + this.opCount = opCount; + this.ops = Object.keys(opInfos).map(opname => { + return { + name: opname, + time: opInfos[opname].time + }; + }); + } + this.stage = 4; }, async run() { diff --git a/examples/mobileNet/index.es6 b/examples/mobileNet/index.es6 index 7c4411f398827810c8f58eae50a3e2ef8653b821..86a0361d3c4c3f0d281ca693aa3be6c87114bca6 100644 --- a/examples/mobileNet/index.es6 +++ b/examples/mobileNet/index.es6 @@ -1,10 +1,10 @@ import 'babel-polyfill'; import Paddle from '../../src/paddle/paddle'; -import IO from '../../src/feed/imageFeed'; +import IO from '../../src/feed/ImageFeed'; import Utils from '../../src/utils/utils'; // 获取map表 -import Map from '../../test/data/map'; - +// import Map from '../../test/data/map'; +let map = {}; const fileDownload = require('js-file-download'); /** @@ -33,6 +33,9 @@ const outputShape = fetchShape[modelType]; let loaded = false; let model = {}; window.statistic = []; +let loading = document.getElementsByClassName('data-loading'); +let modelTxt = document.getElementById('model-txt'); + async function run(input) { // const input = document.getElementById('mobilenet'); const io = new IO(); @@ -54,19 +57,25 @@ async function run(input) { const path = 'https://paddlejs.cdn.bcebos.com/models/mobileNetV2'; if (!loaded) { + + fetch(path + '/map.json') + .then(response => response.json()) + .then(data => (map = data)); const MODEL_CONFIG = { dir: `${path}/`, // 存放模型的文件夹 main: 'model.json', // 主文件 }; loaded = true; + modelTxt.style.visibility = 'visible'; + loading[0].style.visibility = 'visible'; const paddle = new Paddle({ urlConf: MODEL_CONFIG, options: { multipart: true, dataType: 'binary', options: { - fileCount: 4, // 切成了多少文件 - getFileName(i) { // 获取第i个文件的名称 + // fileCount: 4, // 切成了多少文件 + getFileName(i) { // 自定义chunk文件名,获取第i个文件的名称 return 'chunk_' + i + '.dat'; } }, @@ -74,14 +83,20 @@ async function run(input) { } }); model = await paddle.load(); + loading[0].style.visibility = 'hidden'; + modelTxt.innerText = '模型加载完成!'; } - + loading[1].style.visibility = 'visible'; + loading[2].style.visibility = 'visible'; + window.statistic.startTime = (+new Date()); let inst = model.execute({ input: feed }); let result = await inst.read(); - + loading[1].style.visibility = 'hidden'; + loading[2].style.visibility = 'hidden'; + window.statistic.endTime = (+new Date()) - window.statistic.startTime; let N = outputShape[0]; let C = outputShape[1]; let H = outputShape[2]; @@ -98,8 +113,9 @@ async function run(input) { let maxItem = Utils.getMaxItem(nchwData); console.log(maxItem); - document.getElementById('txt').innerHTML = Map['' + maxItem.index]; - console.log('识别出的结果是' + Map['' + maxItem.index]); + document.getElementById('txt').innerHTML = map['' + maxItem.index]; + document.getElementById('all-performance-time').innerHTML = '计算时间是' + window.statistic.endTime; + console.log('识别出的结果是' + map['' + maxItem.index]); }; var image = ''; function selectImage(file) { diff --git a/examples/mobileNet/index.html b/examples/mobileNet/index.html index b7f89d39eacd0905b5226e79b438835a891a7365..fd2ea2048efea0074b1b16dd33a54027a2d1de60 100644 --- a/examples/mobileNet/index.html +++ b/examples/mobileNet/index.html @@ -3,12 +3,107 @@
点击按钮,选择图片触发计算.
+模型加载中.
+ +