(in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias)
| 15 | import os |
| 16 | |
| 17 | def get_conv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias): |
| 18 | if type(kernel_size) is int: |
| 19 | use_large_impl = kernel_size > 5 |
| 20 | else: |
| 21 | assert len(kernel_size) == 2 and kernel_size[0] == kernel_size[1] |
| 22 | use_large_impl = kernel_size[0] > 5 |
| 23 | has_large_impl = 'LARGE_KERNEL_CONV_IMPL' in os.environ |
| 24 | if has_large_impl and in_channels == out_channels and out_channels == groups and use_large_impl and stride == 1 and padding == kernel_size // 2 and dilation == 1: |
| 25 | sys.path.append(os.environ['LARGE_KERNEL_CONV_IMPL']) |
| 26 | # Please follow the instructions https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/README.md |
| 27 | # export LARGE_KERNEL_CONV_IMPL=absolute_path_to_where_you_cloned_the_example (i.e., depthwise_conv2d_implicit_gemm.py) |
| 28 | # TODO more efficient PyTorch implementations of large-kernel convolutions. Pull requests are welcomed. |
| 29 | # Or you may try MegEngine. We have integrated an efficient implementation into MegEngine and it will automatically use it. |
| 30 | from depthwise_conv2d_implicit_gemm import DepthWiseConv2dImplicitGEMM |
| 31 | return DepthWiseConv2dImplicitGEMM(in_channels, kernel_size, bias=bias) |
| 32 | else: |
| 33 | return nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=stride, |
| 34 | padding=padding, dilation=dilation, groups=groups, bias=bias) |
| 35 | |
| 36 | use_sync_bn = False |
| 37 |
no outgoing calls
no test coverage detected