license import { backend_util , KernelConfig , MaxPool3DGrad , MaxPool3DGradAttrs , MaxPool3DGradInputs } from '@tensorflow/tfjs' ; import { createTensorsTypeOpAttr , NodeJSKernelBackend } from '../nodejs_kernel_backend' ; export const maxPool3DGradConfig = { kernelName : MaxPool3DGrad , backendName : 'tensorflow' , kernelFunc : ( args ) => { const { dy , input , output } = args . inputs as MaxPool3DGradInputs ; const backend = args . backend as NodeJSKernelBackend ; const { filterSize , strides , pad , dimRoundingMode } = args . attrs as { } as MaxPool3DGradAttrs ; const convInfo = backend_util . computePool3DInfo ( input . shape as [ number , number , number , number , number ] , filterSize , strides , 1 , pad , dimRoundingMode ) ; if ( convInfo . padInfo . type !== 'VALID' && convInfo . padInfo . type !== 'SAME' ) { throw new Error ( `TF Backend supports only 'valid' and 'same' padding ` + `while padding type was ${ convInfo . padInfo . type }` ) ; } const ksize = [ 1 , convInfo . filterDepth , convInfo . filterHeight , convInfo . filterWidth , 1 ] ; const $strides = [ 1 , convInfo . strideDepth , convInfo . strideHeight , convInfo . strideWidth , 1 ] ; const padding = convInfo . padInfo . type ; const dataFormat = convInfo . dataFormat === 'channelsLast' ? 'NDHWC' : 'NCDHW' ; const opAttrs = [ createTensorsTypeOpAttr ( 'T' , input . dtype ) , { name : 'ksize' , type : backend . binding . TF_ATTR_INT , value : ksize } , { name : 'strides' , type : backend . binding . TF_ATTR_INT , value : $strides } , { name : 'padding' , type : backend . binding . TF_ATTR_STRING , value : padding } , { name : 'data_format' , type : backend . binding . TF_ATTR_STRING , value : dataFormat } , ] ; return backend . executeSingleOutput ( MaxPool3DGrad , opAttrs , [ input , output , dy ] ) ; } } ;