forked from PaddlePaddle/Paddle.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangjingyuan02
committed
Nov 25, 2020
1 parent
305e018
commit b8ea8e8
Showing
20 changed files
with
1,861 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
.DS_Store | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
export interface ModelOp { | ||
type: string; | ||
attrs?: OpAttrs; | ||
'sub-attrs'?: OpAttrs[]; | ||
inputs: OpInputs; | ||
outputs: OpOutputs; | ||
} | ||
|
||
export interface ModelVar { | ||
name: string; | ||
shape: number[]; | ||
data?: number[] | Float32Array; | ||
persistable?: boolean; | ||
needBatch?: boolean; | ||
tensorName?: string; | ||
} | ||
|
||
export interface Model { | ||
ops: ModelOp[]; | ||
vars: ModelVar[]; | ||
} | ||
|
||
export interface OpInputs { | ||
[key: string]: any[]; | ||
} | ||
|
||
export interface OpOutputs { | ||
[key: string]: any[] | ||
} | ||
|
||
export interface OpAttrs { | ||
[key: string]: any[] | ||
} | ||
|
||
export interface OpExecutor { | ||
id: string; | ||
type: string; | ||
inputs: OpInputs; | ||
outputs: OpOutputs; | ||
attrs: OpAttrs; | ||
subAttrs: OpAttrs[]; | ||
next: string | null; | ||
opData: OpData; | ||
isPacked: boolean; | ||
finish: boolean; | ||
inputsName: string[]; | ||
outputsName: string[]; | ||
execute: Function; | ||
} | ||
|
||
export interface Tensor { | ||
|
||
} | ||
|
||
interface Behavior { | ||
[key: string]: Function; | ||
} | ||
|
||
export interface OpInfo { | ||
name: string; | ||
conf: object; | ||
inputsName: string[]; | ||
outputsName: string[]; | ||
params: string; | ||
main: string; | ||
main_packed?: string; | ||
behavior?: Behavior; | ||
behaviors?: string[] | ||
} | ||
|
||
|
||
export interface OpData { | ||
name: string; | ||
isPackedOp: boolean; | ||
input: OpInputs; | ||
output: OpOutputs; | ||
attrs: any; | ||
data: AttrsData; | ||
inputTensors: any; | ||
outputTensors: any; | ||
fShaderParams: any; | ||
vars: ModelVar[]; | ||
iLayer: number; | ||
program: any; | ||
renderData: any[]; | ||
} | ||
|
||
|
||
export interface AttrsData { | ||
[key: string]: any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @file 数据处理 | ||
*/ | ||
|
||
|
||
export default { | ||
// 将nhwc排布数据转为nchw排布数据 | ||
nhwc2nchw(data: number[] | Float32Array, shape: number[]) { | ||
const N = shape[0]; | ||
const H = shape[1]; | ||
const W = shape[2]; | ||
const C = shape[3]; | ||
const WXC = W * C; | ||
const HXWXC = H * W * C; | ||
const nchwData: number[] | Float32Array = []; | ||
for (let n = 0; n < N; n++) { | ||
for (let c = 0; c < C; c++) { | ||
for (let h = 0; h < H; h++) { | ||
for (let w = 0; w < W; w++) { | ||
nchwData.push(data[n * HXWXC + h * WXC + w * C + c]); | ||
} | ||
} | ||
} | ||
} | ||
return nchwData; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { OpInfo } from './commons/interface'; | ||
|
||
interface OpRegistry { | ||
ops: { | ||
// key => backend_name | ||
[key: string]: OpInfo; | ||
}; | ||
opsBehavior?: { | ||
// key => backend_hehavior | ||
[key: string]: Function; | ||
}; | ||
} | ||
|
||
interface GLOBALS_INTERFACE { | ||
opRegistry: OpRegistry; | ||
backend: string; | ||
backend_version: number; | ||
backend_instance: any; // todo Class Backend | ||
} | ||
|
||
export const GLOBALS: GLOBALS_INTERFACE = { | ||
opRegistry: { | ||
ops: {} | ||
}, | ||
backend: 'webgl', | ||
backend_version: 2, | ||
backend_instance: null | ||
}; | ||
|
||
|
||
export function registerOpsBehaviors(opsBehavior) { | ||
GLOBALS.opRegistry.opsBehavior = opsBehavior; | ||
} | ||
|
||
export function registerOp(opInfo: OpInfo) { | ||
const { | ||
name, | ||
conf, | ||
params, | ||
main, | ||
inputsName, | ||
outputsName, | ||
main_packed = '', | ||
behaviors = [] | ||
} = opInfo; | ||
|
||
const opKey = `${GLOBALS.backend}_${name}`; | ||
if (GLOBALS.opRegistry.ops[opKey]) { | ||
return; | ||
} | ||
|
||
GLOBALS.opRegistry.ops[opKey] = { | ||
name, | ||
conf, | ||
inputsName, | ||
outputsName, | ||
params, | ||
main, | ||
main_packed, | ||
behaviors | ||
}; | ||
} | ||
|
||
export function registerBackend(backend: string, backendInstance: any, version?: number) { | ||
if (backend) { | ||
GLOBALS.backend = backend; | ||
} | ||
if (version) { | ||
GLOBALS.backend_version = version; | ||
} | ||
if (backendInstance) { | ||
GLOBALS.backend_instance = backendInstance; | ||
} | ||
} |
Oops, something went wrong.