(input: Tensor,
weight: Tensor,
bias: Optional[Tensor] = None,
stride: Tuple[int, int] = (1, 1),
padding: Tuple[int, int] = (0, 0),
dilation: Tuple[int, int] = (1, 1),
groups: int = 1,
pre_padding: Optional[Tuple[int, int]] = None,
post_padding: Optional[Tuple[int, int]] = None)
| 3584 | |
| 3585 | |
| 3586 | def conv2d(input: Tensor, |
| 3587 | weight: Tensor, |
| 3588 | bias: Optional[Tensor] = None, |
| 3589 | stride: Tuple[int, int] = (1, 1), |
| 3590 | padding: Tuple[int, int] = (0, 0), |
| 3591 | dilation: Tuple[int, int] = (1, 1), |
| 3592 | groups: int = 1, |
| 3593 | pre_padding: Optional[Tuple[int, int]] = None, |
| 3594 | post_padding: Optional[Tuple[int, int]] = None) -> Tensor: |
| 3595 | ## |
| 3596 | ## TODO: Document that function! |
| 3597 | ## |
| 3598 | |
| 3599 | ndim = input.ndim() |
| 3600 | if ndim == 3: |
| 3601 | input = expand_dims(input, 0) |
| 3602 | |
| 3603 | noutput = weight.size()[0] |
| 3604 | kernel_size = (weight.size()[-2], weight.size()[-1]) |
| 3605 | |
| 3606 | is_weight_constant = (weight.producer is not None |
| 3607 | and weight.producer.type == trt.LayerType.CONSTANT) |
| 3608 | weight = weight.producer.weights if is_weight_constant else trt.Weights() |
| 3609 | |
| 3610 | if bias is not None: |
| 3611 | is_bias_constant = (bias.producer is not None |
| 3612 | and bias.producer.type == trt.LayerType.CONSTANT) |
| 3613 | bias = bias.producer.weights if is_bias_constant else trt.Weights() |
| 3614 | |
| 3615 | layer = default_trtnet().add_convolution_nd(input.trt_tensor, noutput, |
| 3616 | kernel_size, weight, bias) |
| 3617 | layer.stride_nd = stride |
| 3618 | layer.padding_nd = padding |
| 3619 | layer.dilation_nd = dilation |
| 3620 | layer.num_groups = groups |
| 3621 | layer.dilation_nd = dilation |
| 3622 | if pre_padding: |
| 3623 | layer.pre_padding = pre_padding |
| 3624 | if post_padding: |
| 3625 | layer.post_padding = post_padding |
| 3626 | |
| 3627 | if not is_weight_constant: |
| 3628 | layer.set_input(1, weight.trt_tensor) |
| 3629 | if bias is not None and not is_bias_constant: |
| 3630 | layer.set_input(2, bias.trt_tensor) |
| 3631 | |
| 3632 | output = _create_tensor(layer.get_output(0), layer) |
| 3633 | |
| 3634 | if ndim == 3: |
| 3635 | return output.view( |
| 3636 | concat([output.size(1), |
| 3637 | output.size(2), |
| 3638 | output.size(3)])) |
| 3639 | |
| 3640 | return output |
| 3641 | |
| 3642 | |
| 3643 | def conv3d(input: Tensor, |
no test coverage detected