config.vue 11.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
<template lang="pug">
    div
        el-row(type=flex justify="start" align="middle")
            el-col(:span="8")
                el-row.model-row(align="middle" type="flex")
                    el-col(:span="6")
                        div model:
                    el-col(:span="18")
                        el-select(v-model="modelSeleted" placeHolder="please selete" @change="changeModel")
                            el-option(v-for="(modelItem, index) in modelList" :key="index" :label="modelItem.name" :value="modelItem")
                el-row.model-row(align="middle" type="flex")
                    el-col(:span="6")
                        div run times:
                    el-col(:span="18")
                        el-input(v-model="times" placeHolde="请输入运行次数" @change="getTimes")
                el-button.model-row(type="primary" @click="run") run
            el-col.model-row.model-stage(:span="12")
                el-steps(align-center :space="200" :active="stage" finish-status="success")
                    el-step(title="start")
                    el-step(title="load model")
                    el-step(title="preheat")
                    el-step(title="run model")

        el-row.model-table(type=flex justify="space-between" :gutter="30")
            el-col(:span="7")
                header.model-header general data
                el-table.model-row(:data="tableData" max-height="100%" border)
                    el-table-column(prop="name" label="type")
                    el-table-column(prop="t" label="name")

            el-col(:span="7")
                header.model-header op data
                el-table.model-row(:data="ops" max-height="100%" border)
                    el-table-column(prop="name" label="type")
                    el-table-column(prop="time" label="time")
            el-col.model-detail(:span="7")
                header.model-header details
                //- el-divider(direction="vertical" content-position="left")
                el-table.model-row(:data="progress" max-height="1500" border :row-class-name="tableRowClassName")
                    el-table-column(prop="index" label="index")
                    el-table-column(prop="name" label="name")
                    el-table-column(prop="time" label="time")


</template>

<script>
import Vue from 'vue';
import 'regenerator-runtime/runtime'
import 'babel-polyfill'
import Paddle from '../../src/executor/runner';
import Utils from '../../src/utils/utils';
export default Vue.extend({
    data() {
        return {
            modelList:  [
                {
                    name: 'mobileNetV2',
                    fileCount: 4,
                    feedShape: {
                        fw: 224,
                        fh: 224
                    },
                    fetchShape: [1, 1000, 10, 1],
                    fill: '#fff',
                    targetSize: { height: 224, width: 224 },
                },
                {
                    name: 'mobileNetV2Opt',
                    fileCount: 4,
                    feedShape: {
                        fw: 224,
                        fh: 224
                    },
                    fetchShape: [1, 1000, 10, 1],
                    fill: '#fff',
                    targetSize: { height: 224, width: 224 },
                },
                {
                    name: 'wine',
                    fileCount: 3,
                    feedShape: {
                        fw: 224,
                        fh: 224
                    },
                    fetchShape: [1, 40, 10, 1],
                    fill: '#fff',
                    targetSize: { height: 224, width: 224 },
                },
                {
                    name: 'gesture_detect',
                    fileCount: 2,
                    feedShape: {
                        fw: 256,
                        fh: 256
                    },
                    fetchShape: [1, 1920, 10 , 1],
                    fill: '#fff',
                    targetSize: { height: 256, width: 256 },
                },
                {
                    name: 'gesture_rec',
                    fileCount: 1,
                    feedShape: {
                        fw: 224,
                        fh: 224
                    },
                    fetchShape: [1, 9, 1, 1],
                    fill: '#fff',
                    targetSize: { height: 224, width: 224 },
                },
                {
                    name: 'humanseg',
                    fileCount: 1,
                    feedShape: {
                        fw: 192,
                        fh: 192
                    },
                    fetchShape: [1, 2, 192, 192],
                    fill: '#fff',
                    targetSize: { height: 224, width: 224 },
                }
            ],
            modelSeleted: '',
            modelPathPrefix: 'https://paddlejs.cdn.bcebos.com/models/',
            modelPath: '',
            curModel: null,
            progressText: '',
            times: null,
            stage: null,
            loadT: '--',
            preheatT: '--',
            remainOthersT: '--',
            bestT: '--',
            progress: [],
            ops: [],
            paddle: null,
            gl: null,
            test: null,
            opCount: '--'
        }
    },
    computed: {
        tableData() {
            return [
                {name: 'load time', t: this.loadT},
                {name: 'preheat time', t: this.preheatT},
                {name: 'subsequent average time', t: this.remainOthersT},
                {name: 'best time', t: this.bestT},
W
wangqun 已提交
150
                {name: 'op count', t: this.opCount || '暂无'}
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
            ]
        }
    },
    methods: {
        tableRowClassName({row}) {
            return row.name === 'total' && 'detail-index-row';
        },
        // arraySpanMethod({row, columnIndex}) {
        //     return [row.name === 'total' && columnIndex === 0 ? this.opCount: 1, 1];
        // },
        changeModel(value) {
            console.log(value);
            this.modelSeleted = value.name;
            this.modelPath = this.modelPathPrefix + value.name;
            console.log(this.modelPath);
            this.curModel = {...value, modelPath: this.modelPath};
        },
        async loadModel() {
            this.stage = 1;
            this.progressText = '模型加载中';
            const paddle = this.paddle = new Paddle({
                ...this.curModel,
                needPostProcess: false,
                needPreheat: false,
                fileDownload: false,
            });
            const start = Date.now();
            await paddle.loadModel();
            this.loadT = Date.now() - start;
            this.stage = 2;

            this.gl = paddle.model.graph.inst.gpu.gl;
        },
        async preheat() {
            const start = Date.now();
            await this.paddle.preheat();
            this.preheatT = Date.now() - start;
            this.stage = 3;
        },
        getTimes(val) {
            if (!val || !this.curModel) {
                return;
            }
        },
        clear() {
            this.loadT = '--' ;
            this.preheatT = '--' ;
            this.remainOthersT = '--' ;
            this.bestT = '--' ;
            this.progress = [] ;
            this.ops = [] ;
            this.opCount = '--';
        },
        async predict() {
            const totalTimes = +this.times;
            let curTimes = 1;
            let remainWholeT = 0;
            let progress = [];
            let totaltimeList = [];
            let opCount = 0;
            const ops = [];
            while(curTimes <= totalTimes) {
                const start = Date.now();
                await this.paddle.runWithFeed(this.paddle.preheatFeed);
                const t = Date.now() - start;
                remainWholeT += t;
                    // this.remainOthersT = +(remainWholeT / (curTimes - 2).toFixed(4));

                const {queryList} = this.paddle.model.graph;
W
wangqun 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236


                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));
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
                }

                progress.push({
                    index: curTimes,
                    time: t,
                    name: 'total'
                });

                totaltimeList.push(t);
                curTimes++;
            }

            const len = totaltimeList.length;
            totaltimeList.sort((a, b) => a - b);
            this.bestT = totaltimeList[0];

            this.remainOthersT = (remainWholeT / this.times).toFixed(4);
            this.progress = progress;
W
wangqun 已提交
255 256 257 258 259 260 261 262 263 264 265 266

            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
                    };
                });
            }

267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
            this.stage = 4;
        },
        async run() {
            this.clear();
            await this.loadModel();
            await this.preheat();
            await this.predict();
        },
        query(queryList) {
            const result =  queryList.map(item => {
                const {name, query, count} = item;
                const time = Utils.getQueryTime(this.gl, query) / 1000000;
                return {name, count, time: +(time.toFixed(4))};
            })
            return result.filter(item => item.name !== 'feed');
        },
        aggregate(acc, cur) {
            const {name, time, count} = cur;
            let now = {...acc};
            if (!acc[name]) {
                now[name] = {time, count};
                return now;
            }

            const item = now[cur.name];
            item.time += time;
            item.count++;
            return now;
        },
296
        getOpPerf(queryList, reduceF, acc, needNoMean) {
297 298 299 300 301 302 303
            let timeRes = acc ? queryList.reduce(reduceF, acc) : queryList.reduce(reduceF);
            for(let key of Object.keys(timeRes)) {
                const item = timeRes[key];
                const {time, count, name} = item;
                if (name === 'feed') {
                    return item;
                }
304
                item.time = needNoMean ? time : +(time / count).toFixed(4);
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
                item.count = 1;
            }
            return timeRes;
        },
        merge(acc, cur) {
            for (let name of Object.keys(cur)) {
                const {time, count} = cur[name];
                acc[name].time += time;
                acc[name].count += count;
            }
            return acc;
        }
    }
})
</script>

<style lang="less" scoped>
.model-row {
    margin-top: 20px;
}
.model-stage {
    margin-top: 50px;
}
.model-header {
    text-align: center;
}
.model-table {
    margin-top: 50px;
}
</style>
<style>
.el-table .detail-index-row {
    background-color: #f0f9eb;
}
</style>