license import { ENGINE } from '../engine' ; import { Dilation2D , Dilation2DAttrs , Dilation2DInputs } from '../kernel_names' ; import { NamedAttrMap } from '../kernel_registry' ; import { Tensor3D , Tensor4D } from '../tensor' ; import { NamedTensorMap } from '../tensor_types' ; import { convertToTensor } from '../tensor_util_env' ; import { TensorLike } from '../types' ; import * as util from '../util' ; import { op } from './operation' ; import { reshape } from './reshape' ; param x param filter param strides param pad param dataFormat param dilations doc function dilation2d_ < T extends Tensor3D | Tensor4D > ( x , filter , strides , pad , dilations = [ 1 , 1 ] , dataFormat = 'NHWC' ) { const $x = convertToTensor ( x , 'x' , 'dilation2d' ) ; const $filter = convertToTensor ( filter , 'filter' , 'dilation2d' ) ; util . assert ( $x . rank === 3 || $x . rank === 4 , ( ) => `Error in dilation2d: input must be rank 3 or 4, but got rank ` + `${ $x . rank }.` ) ; util . assert ( $filter . rank === 3 , ( ) => `Error in dilation2d: filter must be rank 3, but got rank ` + `${ $filter . rank }.` ) ; util . assert ( dataFormat === 'NHWC' , ( ) => `Error in dilation2d: Only NHWC is currently supported, ` + `but got dataFormat of ${ dataFormat }` ) ; let x4D = $x as Tensor4D ; let reshapedTo4D = false ; if ( $x . rank === 3 ) { x4D = reshape ( $x , [ 1 , $x . shape [ 0 ] , $x . shape [ 1 ] , $x . shape [ 2 ] ] ) ; reshapedTo4D = true ; } const inputs = { x : x4D , filter : $filter } ; const attrs = { strides , pad , dilations } ; const res = ENGINE . runKernel ( Dilation2D , inputs as { } as NamedTensorMap , attrs as { } as NamedAttrMap ) as T ; if ( reshapedTo4D ) { return reshape ( res , [ res . shape [ 1 ] , res . shape [ 2 ] , res . shape [ 3 ] ] ) as T ; } return res ; } export const dilation2d = op ( { dilation2d_ } ) ;