Generate a Conv 2d operator
| 506 | |
| 507 | |
| 508 | class Conv2d(Layer): |
| 509 | """ |
| 510 | Generate a Conv 2d operator |
| 511 | """ |
| 512 | |
| 513 | def __init__(self, |
| 514 | nb_kernels, |
| 515 | kernel_size, |
| 516 | *args, |
| 517 | stride=1, |
| 518 | padding=0, |
| 519 | dilation=1, |
| 520 | group=1, |
| 521 | bias=True, |
| 522 | pad_mode="NOTSET", |
| 523 | activation="NOTSET", |
| 524 | **kwargs): |
| 525 | """ |
| 526 | Args: |
| 527 | nb_kernels (int): the channel of output, also is the number of filters |
| 528 | kernel_size (int or tuple): kernel size for two direction of each |
| 529 | axis. For example, (2, 3), the first 2 means will add 2 at the |
| 530 | beginning and also 2 at the end for its axis.and if a int is |
| 531 | accepted, the kernel size will be initiated as (int, int) |
| 532 | stride (int or tuple): stride, the logic is the same as kernel size. |
| 533 | padding (int): tuple, list or None, padding, the logic is the same |
| 534 | as kernel size. However, if you set pad_mode as "SAME_UPPER" or |
| 535 | "SAME_LOWER" mode, you can set padding as None, and the padding |
| 536 | will be computed automatically. |
| 537 | dilation (int): only support 1 |
| 538 | group (int): group |
| 539 | bias (bool): bias |
| 540 | pad_mode (string): can be NOTSET, SAME_UPPER, or SAME_LOWER, where |
| 541 | default value is NOTSET, which means explicit padding is used. |
| 542 | SAME_UPPER or SAME_LOWER mean pad the input so that the output |
| 543 | spatial size match the input. In case of odd number add the extra |
| 544 | padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. |
| 545 | activation (string): can be NOTSET, RELU, where default value is NOTSET, |
| 546 | which means there is no activation behind the conv2d layer. |
| 547 | RELU means there is a ReLU behind current conv2d layer. |
| 548 | """ |
| 549 | super(Conv2d, self).__init__() |
| 550 | |
| 551 | # the old code create the layer like: Conv2d(8, 16, 3), or Conv2d(8, 16, 3, stride=1) |
| 552 | # the following code block is for backward compatibility |
| 553 | if len(args) > 0: |
| 554 | nb_kernels = kernel_size |
| 555 | kernel_size = args[0] |
| 556 | if len(args) > 1: |
| 557 | stride = args[1] |
| 558 | if len(args) > 2: |
| 559 | padding = args[2] |
| 560 | |
| 561 | self.nb_kernels = nb_kernels |
| 562 | self.kernel_size = kernel_size |
| 563 | self.stride = stride |
| 564 | self.padding = padding |
| 565 | self.dilation = dilation |