license import { _FusedMatMul , _FusedMatMulAttrs , _FusedMatMulInputs , backend_util , TensorInfo } from '@tensorflow/tfjs-core' ; import { MathBackendCPU } from '../backend_cpu' ; import { elu } from '../kernels/Elu' ; import { identity } from '../kernels/Identity' ; import { leakyRelu } from '../kernels/LeakyRelu' ; import { prelu } from '../kernels/Prelu' ; import { relu } from '../kernels/Relu' ; import { relu6 } from '../kernels/Relu6' ; import { sigmoid } from '../kernels/Sigmoid' ; export function applyActivation ( backend , x , activation , preluActivationWeights ? , leakyreluAlpha ? ) { if ( activation === 'linear' ) { return identity ( { inputs : { x } , backend } ) ; } else if ( activation === 'relu' ) { return relu ( { inputs : { x } , backend } ) as TensorInfo ; } else if ( activation === 'elu' ) { return elu ( { inputs : { x } , backend } ) as TensorInfo ; } else if ( activation === 'relu6' ) { return relu6 ( { inputs : { x } , backend } ) as TensorInfo ; } else if ( activation === 'prelu' ) { return prelu ( { inputs : { x , alpha : preluActivationWeights } , backend } ) ; } else if ( activation === 'leakyrelu' ) { return leakyRelu ( { inputs : { x } , backend , attrs : { alpha : leakyreluAlpha } } ) ; } else if ( activation === 'sigmoid' ) { return sigmoid ( { inputs : { x } , backend } ) as TensorInfo ; } throw new Error ( `Activation ${ activation } has not been implemented for the CPU backend.` ) ; }