-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(modelService): add factory method to create model service
Signed-off-by: Bill ZHANG <[email protected]>
- Loading branch information
Showing
5 changed files
with
73 additions
and
64 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
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,48 @@ | ||
import { type Vector2 } from 'three'; | ||
import { TfjsService } from './TfjsService'; | ||
import ONNXService from './ONNXService'; | ||
|
||
export interface ModelService { | ||
startSimulation: () => void; | ||
pauseSimulation: () => void; | ||
bindOutput: (callback: (data: Float32Array) => void) => void; | ||
getInputTensor: () => Float32Array; | ||
updateForce: (pos: Vector2, forceDelta: Vector2) => void; | ||
loadDataArray: (array: number[][][][]) => void; | ||
} | ||
|
||
// a simple factory function to create a model service | ||
export async function createModelService( | ||
modelPath: string, | ||
gridSize: [number, number] = [64, 64], | ||
batchSize = 1, | ||
channelSize = 5, | ||
outputChannelSize = 3, | ||
fpsLimit = 15, | ||
): Promise<ModelService> { | ||
// detect the model type | ||
// TODO: read the model type from the model definition file | ||
const modelType = modelPath.split('.').pop(); | ||
switch (modelType) { | ||
case 'json': | ||
return TfjsService.createService( | ||
modelPath, | ||
gridSize, | ||
batchSize, | ||
channelSize, | ||
outputChannelSize, | ||
fpsLimit, | ||
); | ||
case 'onnx': | ||
return ONNXService.createService( | ||
modelPath, | ||
gridSize, | ||
batchSize, | ||
channelSize, | ||
outputChannelSize, | ||
fpsLimit, | ||
); | ||
default: | ||
throw new Error('Invalid model type'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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