license import { add , backend_util , FusedConv2D , FusedConv2DAttrs , FusedConv2DInputs , KernelConfig , Tensor } from '@tensorflow/tfjs' ; import { NodeJSKernelBackend } from '../nodejs_kernel_backend' ; import { conv2dImpl } from './Conv2D' ; export const fusedConv2DConfig = { kernelName : FusedConv2D , backendName : 'tensorflow' , kernelFunc : ( args ) => { const { x , filter , bias , preluActivationWeights } = args . inputs as FusedConv2DInputs ; const backend = args . backend as NodeJSKernelBackend ; const { strides , pad , dataFormat , dilations , dimRoundingMode , activation , leakyreluAlpha } = args . attrs as { } as FusedConv2DAttrs ; const $dataFormat = backend_util . convertConv2DDataFormat ( dataFormat ) ; const convInfo = backend_util . computeConv2DInfo ( x . shape as [ number , number , number , number ] , filter . shape as [ number , number , number , number ] , strides , dilations , pad , dimRoundingMode , false , $dataFormat ) ; let result = conv2dImpl ( x , filter , convInfo , backend ) ; const toDispose = [ ] ; if ( bias != null ) { toDispose . push ( result ) ; result = add ( result , bias as Tensor ) ; } const temp = result ; result = backend . applyActivation ( result , activation , preluActivationWeights as Tensor , leakyreluAlpha ) ; if ( temp !== result ) { toDispose . push ( temp ) ; } toDispose . forEach ( t => t . dispose ( ) ) ; return result ; } } ;