MCPcopy Index your code
hub / github.com/apache/tvm / _conv3d_ndhwc_python

Function _conv3d_ndhwc_python

python/tvm/topi/testing/conv3d_ndhwc_python.py:26–87  ·  view source on GitHub ↗

Convolution 3D operator in NDHWC layout. Parameters ---------- a_np : numpy.ndarray 5-D with shape [batch, in_channel, in_depth, in_height, in_width] w_np : numpy.ndarray 5-D with shape [num_filter, in_channel, filter_depth, filter_height, filter_width] stride

(a_np, w_np, stride, padding)

Source from the content-addressed store, hash-verified

24
25
26def _conv3d_ndhwc_python(a_np, w_np, stride, padding):
27 """Convolution 3D operator in NDHWC layout.
28
29 Parameters
30 ----------
31 a_np : numpy.ndarray
32 5-D with shape [batch, in_channel, in_depth, in_height, in_width]
33
34 w_np : numpy.ndarray
35 5-D with shape [num_filter, in_channel, filter_depth, filter_height, filter_width]
36
37 stride : int or a list/tuple of three ints
38 Stride size, or [stride_depth, stride_height, stride_width]
39
40 padding : int or str or a list/tuple of three ints
41 Padding size, or ['VALID', 'SAME'], or [pad_depth, pad_height, pad_width]
42
43 Returns
44 -------
45 b_np : np.ndarray
46 5-D with shape [batch, out_channel, out_depth, out_height, out_width]
47 """
48 batch, in_depth, in_height, in_width, in_channel = a_np.shape
49 kernel_d, kernel_h, kernel_w, _, num_filter = w_np.shape
50 if isinstance(stride, int):
51 stride_d = stride_h = stride_w = stride
52 else:
53 stride_d, stride_h, stride_w = stride
54
55 pad_front, pad_top, pad_left, pad_back, pad_bottom, pad_right = get_pad_tuple3d(
56 padding, (kernel_d, kernel_h, kernel_w)
57 )
58 pad_d = pad_front + pad_back
59 pad_h = pad_top + pad_bottom
60 pad_w = pad_left + pad_right
61 # compute the output shape
62 out_channel = num_filter
63 out_depth = (in_depth - kernel_d + pad_d) // stride_d + 1
64 out_height = (in_height - kernel_h + pad_h) // stride_h + 1
65 out_width = (in_width - kernel_w + pad_w) // stride_w + 1
66 # change the layout from NHWC to NCHW
67 at = a_np.transpose((0, 4, 1, 2, 3))
68 wt = w_np.transpose((4, 3, 0, 1, 2))
69 bt = np.zeros((batch, out_channel, out_depth, out_height, out_width), dtype=a_np.dtype)
70 # computation
71 for n in range(batch):
72 for f in range(out_channel):
73 for c in range(in_channel):
74 if pad_d > 0 or pad_h > 0 or pad_w > 0:
75 apad = np.zeros(
76 (in_depth + pad_d, in_height + pad_h, in_width + pad_w), dtype=a_np.dtype
77 )
78 apad[
79 pad_front : pad_front + in_depth,
80 pad_top : pad_top + in_height,
81 pad_left : pad_left + in_width,
82 ] = at[n, c]
83 else:

Callers 1

conv3d_ndhwc_pythonFunction · 0.85

Calls 4

get_pad_tuple3dFunction · 0.90
flipMethod · 0.80
transposeMethod · 0.45
zerosMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…