Skip to content

Commit 2708d91

Browse files
committed
chore(core): del deprecated interface targetSize and rename modelConfig to runnerConfig
1 parent 7f3b23a commit 2708d91

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-29
lines changed

packages/paddlejs-benchmark/src/config.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<script lang="ts">
4848
import Vue from 'vue';
4949
import { Runner } from '@paddlejs/paddlejs-core';
50-
import { GLOBALS } from '@paddlejs/paddlejs-core/globals';
50+
import { GLOBALS } from '@paddlejs/paddlejs-core/src/globals';
5151
import '@paddlejs/paddlejs-backend-webgl';
5252
import Utils from './utils';
5353
@@ -64,7 +64,6 @@ export default Vue.extend({
6464
},
6565
fetchShape: [1, 1000, 10, 1],
6666
fill: '#fff',
67-
targetSize: { height: 224, width: 224 },
6867
needPreheat: false
6968
},
7069
{
@@ -75,7 +74,6 @@ export default Vue.extend({
7574
},
7675
fetchShape: [1, 1000, 10, 1],
7776
fill: '#fff',
78-
targetSize: { height: 224, width: 224 },
7977
needPreheat: false
8078
},
8179
{
@@ -86,7 +84,6 @@ export default Vue.extend({
8684
},
8785
fetchShape: [1, 40, 10, 1],
8886
fill: '#fff',
89-
targetSize: { height: 224, width: 224 },
9087
needPreheat: false
9188
},
9289
{
@@ -97,7 +94,6 @@ export default Vue.extend({
9794
},
9895
fetchShape: [1, 1920, 10 , 1],
9996
fill: '#fff',
100-
targetSize: { height: 256, width: 256 },
10197
needPreheat: false
10298
},
10399
{
@@ -108,7 +104,6 @@ export default Vue.extend({
108104
},
109105
fetchShape: [1, 9, 1, 1],
110106
fill: '#fff',
111-
targetSize: { height: 224, width: 224 },
112107
needPreheat: false
113108
},
114109
{
@@ -119,7 +114,6 @@ export default Vue.extend({
119114
},
120115
fetchShape: [1, 2, 192, 192],
121116
fill: '#fff',
122-
targetSize: { height: 224, width: 224 },
123117
needPreheat: false
124118
}
125119
],

packages/paddlejs-core/__tests__/spec/graph.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Graph from '../../src/graph';
2-
import { ModelConfig } from '../../src/commons/interface';
2+
import { RunnerConfig } from '../../src/commons/interface';
33
import modelInfo from '../env/mock/model.json';
44

55
describe('test graph', () => {
66

77
const graphGenerator = new Graph(modelInfo, {
88
type: 'single'
9-
} as ModelConfig);
9+
} as RunnerConfig);
1010
const weightMap = graphGenerator.createGraph();
1111

1212

packages/paddlejs-core/src/commons/interface.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,14 @@ export interface Model {
3838
multiOutputs?: ModelVar[]
3939
}
4040

41-
export interface ModelConfig {
41+
export interface RunnerConfig {
4242
modelPath: string;
4343
modelName?: string;
4444
feedShape: {
4545
fc?: number;
4646
fw: number;
4747
fh: number;
4848
};
49-
targetSize?: {
50-
height: number;
51-
width: number;
52-
};
5349
fill?: string; // 缩放后用什么颜色填充不足方形部分
5450
mean?: number[];
5551
std?: number[];

packages/paddlejs-core/src/graph.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file ModelGraph,graph 生成器
33
*/
44

5-
import { ModelOp, GraphType, Model, ModelVar, ModelConfig } from './commons/interface';
5+
import { ModelOp, GraphType, Model, ModelVar, RunnerConfig } from './commons/interface';
66
import OpExecutor from './opFactory/opExecutor';
77
import transformActions from './transform';
88

@@ -28,11 +28,11 @@ export default class ModelGraph {
2828
weightMap: OpExecutor[] = [];
2929
ops: ModelOp[] = [];
3030
vars: ModelVar[] = [];
31-
config: ModelConfig = {} as ModelConfig;
31+
config: RunnerConfig = {} as RunnerConfig;
3232
type: GraphType = GraphType.SingleOutput;
3333
plugins: GraphPlugins = null;
3434

35-
constructor(model: Model, config: ModelConfig) {
35+
constructor(model: Model, config: RunnerConfig) {
3636
this.ops = model.ops;
3737
this.vars = model.vars;
3838
this.type = config.type || this.type;

packages/paddlejs-core/src/mediaProcessor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ export default class MediaProcessor {
109109
*/
110110
allReshapeToRGB(imageData, opt) {
111111
// mean和std是介于0-1之间的
112-
const { mean, std, targetShape, bgr } = opt;
112+
const { mean, std, targetShape, bgr, normalizeType = 0 } = opt;
113113
const [, c, h, w] = targetShape;
114114
const data = imageData.data || imageData;
115115
const result = new Float32Array(h * w * c);
116116
let offset = 0;
117-
// 将数据映射为0~1, 1:映射为-1~1之间
118-
const normalizeType = 0;
119117
// h w c
120118
for (let i = 0; i < h; ++i) {
121119
const iw = i * w;

packages/paddlejs-core/src/runner.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Loader from './loader';
22
import Graph from './graph';
3-
import { Model, ModelConfig, InputFeed, ModelVar, GraphType } from './commons/interface';
3+
import { Model, RunnerConfig, InputFeed, ModelVar, GraphType } from './commons/interface';
44
import OpData from './opFactory/opDataBuilder';
55
import Tensor from './opFactory/tensor';
66
import { GLOBALS } from './globals';
@@ -14,7 +14,7 @@ import { accShape } from './opFactory/utils';
1414

1515
export default class Runner {
1616
// instance field
17-
modelConfig: ModelConfig = {} as ModelConfig;
17+
runnerConfig: RunnerConfig = {} as RunnerConfig;
1818
modelName: string;
1919
isPaused: boolean = false;
2020
model: Model = {} as Model;
@@ -25,8 +25,8 @@ export default class Runner {
2525
mediaProcessor: MediaProcessor | null = null;
2626
needPreheat: boolean = true;
2727

28-
constructor(options: ModelConfig | null) {
29-
this.modelConfig = Object.assign({}, options);
28+
constructor(options: RunnerConfig | null) {
29+
this.runnerConfig = Object.assign({}, options);
3030
this.needPreheat = options.needPreheat === undefined ? true : options.needPreheat;
3131
this.modelName = options.modelName || Date.now().toString();
3232
this.weightMap = [];
@@ -55,13 +55,13 @@ export default class Runner {
5555
}
5656

5757
async load() {
58-
const { modelPath } = this.modelConfig;
58+
const { modelPath } = this.runnerConfig;
5959
const loader = new Loader(modelPath);
6060
this.model = await loader.load();
6161
}
6262

6363
genGraph() {
64-
this.graphGenerator = new Graph(this.model, this.modelConfig);
64+
this.graphGenerator = new Graph(this.model, this.runnerConfig);
6565
this.weightMap = this.graphGenerator.createGraph();
6666
}
6767

@@ -115,7 +115,7 @@ export default class Runner {
115115
else {
116116
inputFeed = this.mediaProcessor.process(
117117
media,
118-
this.modelConfig
118+
this.runnerConfig
119119
);
120120
}
121121

@@ -126,7 +126,7 @@ export default class Runner {
126126
}
127127

128128
async predictWithFeed(data: number[] | InputFeed[] | ImageData, callback?, shape?: number[]) {
129-
const { fc = 3, fw, fh } = this.modelConfig.feedShape;
129+
const { fc = 3, fw, fh } = this.runnerConfig.feedShape;
130130
let inputFeed;
131131

132132
if (Array.isArray(data)) {
@@ -171,7 +171,7 @@ export default class Runner {
171171
}
172172

173173
genFeedData() {
174-
const { type, feedShape } = this.modelConfig;
174+
const { type, feedShape } = this.runnerConfig;
175175
const { fc = 3, fh, fw } = feedShape;
176176
const vars = this.model.vars;
177177
let preheatFeedData;

0 commit comments

Comments
 (0)