import ModelShape from '../modelspec/ModelShape' ; import ModelSpec from '../modelspec/ModelSpec' ; /**
 * A builder class to instantiate a model spec.
 */ export default class ModelSpecBuilder { private path : string = null ; private input : ModelShape = null ; private output : ModelShape = null ; static builder ( ) { return new ModelSpecBuilder ( ) ; } returns withDefaultModel ( ) { return this . withSelfieSegmentationDefaults ( ) ; } returns withSelfieSegmentationDefaults ( ) { const SELFIE_MODEL_INPUT_SHAPE = { height : 144 , width : 256 , range : [ 0 , 1 ] , channels : 3 , } ; const SELFIE_MODEL_OUTPUT_SHAPE = { height : 144 , width : 256 , range : [ 0 , 1 ] , channels : 1 , } ; const DEFAULT_SELFIE_MODEL_PATH = 'https://static.sdkassets.chime.aws/bgblur/models/selfie_segmentation_landscape.tflite' ; this . path = DEFAULT_SELFIE_MODEL_PATH ; this . input = SELFIE_MODEL_INPUT_SHAPE ; this . output = SELFIE_MODEL_OUTPUT_SHAPE ; return this ; } param path returns withPath ( path ) { this . path = path ; return this ; } param input returns withInput ( input ) { this . input = input ; return this ; } param input returns withOutput ( output ) { this . output = output ; return this ; } /**
     * Validate that inputs to the model spec are valid.
     */ private validate ( ) { if ( ! this . path ) { throw new Error ( 'model spec path is not set' ) ; } if ( ! this . input ) { throw new Error ( 'model spec input is not set' ) ; } if ( ! this . output ) { throw new Error ( 'model spec output is not set' ) ; } } returns build ( ) { this . validate ( ) ; return { path : this . path , input : this . input , output : this . output , } ; } }