UNPKG

1.74 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2020 Google LLC. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * =============================================================================
16 */
17import { ENGINE } from '../engine';
18import { DepthwiseConv2dNativeBackpropInput } from '../kernel_names';
19import { op } from './operation';
20import { reshape } from './reshape';
21function depthwiseConv2dNativeBackpropInput_(xShape, dy, filter, strides, pad, dilations = [1, 1], dimRoundingMode) {
22 let dy4D = dy;
23 let reshapedTo4D = false;
24 if (dy.rank === 3) {
25 reshapedTo4D = true;
26 dy4D = reshape(dy, [1, dy.shape[0], dy.shape[1], dy.shape[2]]);
27 }
28 const inputs = { dy: dy4D, filter };
29 const attrs = { strides, pad, dimRoundingMode, dilations, inputShape: xShape };
30 const res =
31 // tslint:disable-next-line: no-unnecessary-type-assertion
32 ENGINE.runKernel(DepthwiseConv2dNativeBackpropInput, inputs, attrs);
33 if (reshapedTo4D) {
34 return reshape(res, [res.shape[1], res.shape[2], res.shape[3]]);
35 }
36 return res;
37}
38export const depthwiseConv2dNativeBackpropInput = op({ depthwiseConv2dNativeBackpropInput_ });
39//# sourceMappingURL=depthwise_conv2d_native_backprop_input.js.map
\No newline at end of file