module onnxrt.ops_cpu.op_conv_helper
#
Short summary#
module mlprodict.onnxrt.ops_cpu.op_conv_helper
Helpers for operators Conv, ConvTranspose.
Functions#
function |
truncated documentation |
---|---|
Source im2col.py. |
|
C implementation of a partial col2im. |
|
Source im2col.py. |
|
Returns the result of im2col on a image NHCW where N is 1. The function is equivalent to |
|
Source im2col.py. |
|
Computes the ouput shape of im2col. |
|
Naive implementation for im2col or |
|
C implementation of a partial im2col. |
|
Functions |
|
Recursive implementation, falls back to |
|
Creates a new empty array. |
|
C++ implementation for col2im or |
|
C++ implementation for im2col or |
Documentation#
Helpers for operators Conv, ConvTranspose.
- mlprodict.onnxrt.ops_cpu.op_conv_helper._get_indices(i, shape)#
- mlprodict.onnxrt.ops_cpu.op_conv_helper._is_out(ind, shape)#
- mlprodict.onnxrt.ops_cpu.op_conv_helper.col2im_indices(cols, x_shape, field_height=3, field_width=3, padding=0, stride=1)#
Source im2col.py.
- mlprodict.onnxrt.ops_cpu.op_conv_helper.col2im_nchw(data_col, image_shape, kernel_shape, padding, dilations)#
C implementation of a partial col2im.
- Parameters:
data_col – image (float)
image_shape – expected image shape
kernel_shape – kernel shape
padding – padding
dilations – dilations
- Returns:
result
- mlprodict.onnxrt.ops_cpu.op_conv_helper.get_im2col_indices(x_shape, field_height, field_width, padding=1, stride=1)#
Source im2col.py.
- mlprodict.onnxrt.ops_cpu.op_conv_helper.im2col(data, kernel_shape=None, fill_value=0)#
Returns the result of im2col on a image NHCW where N is 1. The function is equivalent to
torch.nn.Unfold()
(but with padding=1 on all dimensions).- Parameters:
image – image (float)
kernel_shape – kernel shape
fill_value – fill value
- Returns:
result
This function is equivalent to function
torch.nn.Unfold()
with padding=kernel_shape / 2 followed by a reshape and a transpose.import numpy from numpy.testing import assert_almost_equal import torch data = (numpy.arange(20).astype(numpy.float64) + 10).reshape((4, 5)) expected = im2col_recursive(data, (3, 3), fill_value=0) unfold = torch.nn.Unfold(kernel_size=(3, 3), padding=1) input = torch.from_numpy(data.reshape((1, 1) + data.shape)) output = unfold(input) mat = output.numpy() tr = numpy.transpose(mat, [0, 2, 1]) resh = tr.reshape(expected.shape) assert_almost_equal(expected, resh)
- mlprodict.onnxrt.ops_cpu.op_conv_helper.im2col_indices(x, field_height, field_width, padding=0, stride=1)#
Source im2col.py.
- mlprodict.onnxrt.ops_cpu.op_conv_helper.im2col_infer_output_shape(input_shape, kernel_shape, strides, dilations, padding, auto_padding='NOTSET')#
Computes the ouput shape of im2col.
- Parameters:
input_shape – input _shape
kernel_shape – kernel shape
strides – strides
dilations – dilations
padding – padding
auto_padding – among NOTSET, VALID, SAME_UPPER, SAME_LOWER
:return output_shape, modified padding
- mlprodict.onnxrt.ops_cpu.op_conv_helper.im2col_naive_implementation(data, kernel_shape, fill_value=0)#
Naive implementation for im2col or
torch.nn.Unfold()
(but with padding=1).- Parameters:
image – image (float)
kernel_shape – kernel shape
fill_value – fill value
- Returns:
result
- mlprodict.onnxrt.ops_cpu.op_conv_helper.im2col_nchw(image_id, group_id, group, image, kernel_shape, padding, dilations)#
C implementation of a partial im2col.
- Parameters:
image – image (float)
kernel_shape – kernel shape
padding – padding
dilations – dilations
- Returns:
result
- mlprodict.onnxrt.ops_cpu.op_conv_helper.im2col_nn(res)#
Functions
nn_im2col_2d
andim2col()
returns the same results but with different shapes. This function converts a result fromnn_im2col_2d
into the same shape as a return fromnn_im2col_2d
.
- mlprodict.onnxrt.ops_cpu.op_conv_helper.im2col_recursive(data, kernel_shape, fill_value=0, fall_back_dim=2)#
Recursive implementation, falls back to
im2col_naive_implementation
for dimension <= fall_back_dim. The function is equivalent totorch.nn.Unfold()
(but with padding=1 on all dimensions).- Parameters:
image – image (float)
kernel_shape – kernel shape
fill_value – fill value
fall_back_dim – below that threshold, switches to
im2col_naive_implementation
.
- Returns:
result
- mlprodict.onnxrt.ops_cpu.op_conv_helper.new_array(shape, dtype=<class 'numpy.float32'>)#
Creates a new empty array.
- Parameters:
shape – shape
dtype – dtype
- Returns:
new array
- mlprodict.onnxrt.ops_cpu.op_conv_helper.nn_col2im_2d(data, output_shape, kernel_shape, dilations, padding)#
C++ implementation for col2im or
torch.nn.Fold()
.- Parameters:
data – image (float), 2 dimensions.
output_shape – output size
kernel_shape – kernel shape
dilations – dilations
padding – padding
- Returns:
result
- mlprodict.onnxrt.ops_cpu.op_conv_helper.nn_im2col_2d(data, kernel_shape, dilations, padding, fill_value=0)#
C++ implementation for im2col or
torch.nn.Unfold()
.- Parameters:
data – image (float), 2 dimensions.
kernel_shape – kernel shape
dilations – dilations
padding – padding
fill_value – fill value
- Returns:
result