license import { ENGINE } from '../engine' ; import { Conv3DBackpropInputV2 , Conv3DBackpropInputV2Attrs , Conv3DBackpropInputV2Inputs } from '../kernel_names' ; import { NamedAttrMap } from '../kernel_registry' ; import { Tensor4D , Tensor5D } from '../tensor' ; import { NamedTensorMap } from '../tensor_types' ; import * as util from '../util' ; import { op } from './operation' ; import { reshape } from './reshape' ; param xShape param dy param filter param strides param pad function conv3DBackpropInput_ < T extends Tensor4D | Tensor5D > ( xShape , dy , filter , strides , pad ) { util . assert ( xShape . length === dy . rank , ( ) => `Length of inShape ` + `(${ xShape . length }) and rank of dy (${ dy . rank }) must match` ) ; let xShape5D = xShape as [ number , number , number , number , number ] ; let dy5D = dy as Tensor5D ; let reshapedTo5D = false ; if ( dy . rank === 4 ) { reshapedTo5D = true ; dy5D = reshape ( dy , [ 1 , dy . shape [ 0 ] , dy . shape [ 1 ] , dy . shape [ 2 ] , dy . shape [ 3 ] ] ) ; xShape5D = [ 1 , xShape [ 0 ] , xShape [ 1 ] , xShape [ 2 ] , xShape [ 3 ] ] ; } const inDepth = xShape5D [ 4 ] ; const outDepth = dy5D . shape [ 4 ] ; util . assert ( xShape5D . length === 5 , ( ) => `Error in conv3dDerInput: inShape must be length 5, but got length ` + `${ xShape5D . length }.` ) ; util . assert ( dy5D . rank === 5 , ( ) => `Error in conv3dDerInput: dy must be rank 5, but got ` + `rank ${ dy5D . rank }` ) ; util . assert ( filter . rank === 5 , ( ) => `Error in conv3dDerInput: filter must be rank 5, but got ` + `rank ${ filter . rank }` ) ; util . assert ( inDepth === filter . shape [ 3 ] , ( ) => `Error in conv3dDerInput: depth of input (${ inDepth }) must ` + `match input depth for filter ${ filter . shape [ 3 ] }.` ) ; util . assert ( outDepth === filter . shape [ 4 ] , ( ) => `Error in conv3dDerInput: depth of output (${ outDepth }) must ` + `match output depth for filter ${ filter . shape [ 4 ] }.` ) ; const inputs = { dy : dy5D , filter } ; const attrs = { pad , strides , inputShape : xShape5D } ; const res = ENGINE . runKernel ( Conv3DBackpropInputV2 , inputs as { } as NamedTensorMap , attrs as { } as NamedAttrMap ) as T ; if ( reshapedTo5D ) { return reshape ( res , [ res . shape [ 1 ] , res . shape [ 2 ] , res . shape [ 3 ] , res . shape [ 4 ] ] ) as T ; } return res ; } export const conv3DBackpropInput = op ( { conv3DBackpropInput_ } ) ;