license import { add , backend_util , FusedDepthwiseConv2D , FusedDepthwiseConv2DAttrs , FusedDepthwiseConv2DInputs , KernelConfig , Tensor } from '@tensorflow/tfjs' ; import { NodeJSKernelBackend } from '../nodejs_kernel_backend' ; import { depthwiseConv2dNativeImpl } from './DepthwiseConv2dNative' ; export const fusedDepthwiseConv2DConfig = { kernelName : FusedDepthwiseConv2D , backendName : 'tensorflow' , kernelFunc : ( args ) => { const { x , filter , bias , preluActivationWeights } = args . inputs as FusedDepthwiseConv2DInputs ; const backend = args . backend as NodeJSKernelBackend ; const { strides , pad , dilations , dimRoundingMode , activation , leakyreluAlpha } = args . attrs as { } as FusedDepthwiseConv2DAttrs ; let $dilations = dilations ; if ( $dilations == null ) { $dilations = [ 1 , 1 ] ; } const convInfo = backend_util . computeConv2DInfo ( x . shape as [ number , number , number , number ] , filter . shape as [ number , number , number , number ] , strides , $dilations , pad , dimRoundingMode , true ) ; let result = depthwiseConv2dNativeImpl ( 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 ; } } ;