license import { FusedDepthwiseConv2D , FusedDepthwiseConv2DAttrs , FusedDepthwiseConv2DInputs , KernelConfig , KernelFunc , TensorInfo } from '@tensorflow/tfjs-core' ; import { MathBackendCPU } from '../backend_cpu' ; import { applyActivation } from '../utils/fused_utils' ; import { add } from './Add' ; import { depthwiseConv2dNative } from './DepthwiseConv2dNative' ; export function fusedDepthwiseConv2D ( args ) { const { inputs , backend , attrs } = args ; const { x , filter , bias , preluActivationWeights } = inputs ; const { strides , pad , dataFormat , dilations , dimRoundingMode , activation , leakyreluAlpha } = attrs ; let result = depthwiseConv2dNative ( { inputs : { x , filter } , backend , attrs : { strides , pad , dataFormat , dilations , dimRoundingMode } } ) ; if ( bias ) { const oldResult = result ; result = add ( { inputs : { a : result , b : bias } , backend } ) as TensorInfo ; backend . disposeIntermediateTensorInfo ( oldResult ) ; } if ( activation ) { const oldResult = result ; result = applyActivation ( backend , result , activation , preluActivationWeights , leakyreluAlpha ) ; backend . disposeIntermediateTensorInfo ( oldResult ) ; } return result ; } export const fusedDepthwiseConv2DConfig = { kernelName : FusedDepthwiseConv2D , backendName : 'cpu' , kernelFunc : fusedDepthwiseConv2D as { } as KernelFunc } ;