import * as tf from '@tensorflow/tfjs' ; import { Shape , SymbolicTensor } from '@tensorflow/tfjs' ; import { PaddingMode } from '@tensorflow/tfjs-layers/dist/common' ; import { Layer , LayerConfig } from '@tensorflow/tfjs-layers/dist/engine/topology' ; import { onnx } from 'onnx-proto' ; import { ConstantCompat } from './compat/core' ; import { AutoPad , ConvNodeConfig } from './layers/convolution' ; import { parseAttrOrDefault , parseShape } from './onnx_util' ; import { getLayerName , getNamedAttrs } from './util' ; export function getInputName ( graph ) { return getLayerName ( graph . input [ graph . input . length - 1 ] ) ; } export function input ( name , shape ) { const conf = { name : name , shape : shape } ; return tf . input ( conf ) ; } export function getInputShape ( shape ) { const outShape = parseShape ( shape ) ; return outShape . length == 4 ? outShape . slice ( 1 ) : outShape ; } export function isConstantLayer ( layer ) { return layer instanceof ConstantCompat && layer . outboundNodes . length > 0 ; } export function getCommonConfig ( node ) { return { name : node . name } ; } export function getTfjsPadding ( pads , auto_pad ) { const checkAutoPad = auto_pad !== null && auto_pad != 'VALID' ; const checkPads = pads !== null && pads . length > 0 && pads [ 0 ] != 0 ; return checkAutoPad || checkPads ? 'same' : 'valid' ; } export function getConvDim ( node ) { const conf = getNamedAttrs ( node . attribute ) as ConvNodeConfig ; return parseAttrOrDefault ( conf . kernel_shape , [ ] ) . length || 2 ; }