import * as tf from '@tensorflow/tfjs' ; import { SymbolicTensor , Tensor } from '@tensorflow/tfjs' ; import { DType } from '@tensorflow/tfjs-core/dist/types' ; import { InputLayer , Layer , LayerConfig } from '@tensorflow/tfjs-layers/dist/engine/topology' ; import { Initializer } from '@tensorflow/tfjs-layers/dist/initializers' ; import { onnx } from 'onnx-proto' ; import { ConstantCompat } from './compat/core' ; import { getCommonConfig } from './layer_util' ; import { OnnxModel } from './model' ; export type StaticThis < T > = { new ( model ) : T ; } ; export abstract class OnnxNode { protected constructor ( public model ) { } ; static from < T extends OnnxNode > ( this , model ) { const that = new this ( model ) ; return that ; } abstract getTfjsLayer ( node , input ? ) ; getTfjsLayerConfig ( node , input ? ) { return { } ; } getTfjsConfig ( node , input ? ) { const commonConfig = getCommonConfig ( node ) ; const layerConfig = this . getTfjsLayerConfig ( node , input ) ; return Object . assign ( { } , commonConfig , layerConfig ) ; } prepareInput ( input ? ) { return input ; } setup ( node , input ? ) { const layer = this . getTfjsLayer ( node , input ) ; if ( layer instanceof ConstantCompat || layer instanceof InputLayer ) { const outputs = layer . inboundNodes [ 0 ] . outputTensors ; return [ layer , outputs [ 0 ] ] ; } return [ layer , layer . apply ( this . prepareInput ( input ) ) as SymbolicTensor ] ; } } export class WeightInitializer extends Initializer { constructor ( protected weights ) { super ( ) ; } ; apply ( shape , dtype ? ) { return this . weights ; } getClassName ( ) { return 'WeightInitializer' ; } }