Forward function for partial conv2d. Args: input (torch.Tensor): Tensor with shape of (n, c, h, w). mask (torch.Tensor): Tensor with shape of (n, c, h, w) or (n, 1, h, w). If mask is not given, the function will work as standard conv2d
(self,
x,
mask=None,
activate=True,
norm=True,
return_mask=True)
| 42 | self.init_weights() |
| 43 | |
| 44 | def forward(self, |
| 45 | x, |
| 46 | mask=None, |
| 47 | activate=True, |
| 48 | norm=True, |
| 49 | return_mask=True): |
| 50 | """Forward function for partial conv2d. |
| 51 | |
| 52 | Args: |
| 53 | input (torch.Tensor): Tensor with shape of (n, c, h, w). |
| 54 | mask (torch.Tensor): Tensor with shape of (n, c, h, w) or |
| 55 | (n, 1, h, w). If mask is not given, the function will |
| 56 | work as standard conv2d. Default: None. |
| 57 | activate (bool): Whether use activation layer. |
| 58 | norm (bool): Whether use norm layer. |
| 59 | return_mask (bool): If True and mask is not None, the updated |
| 60 | mask will be returned. Default: True. |
| 61 | |
| 62 | Returns: |
| 63 | Tensor or tuple: Result Tensor or 2-tuple of |
| 64 | |
| 65 | ``Tensor``: Results after partial conv. |
| 66 | |
| 67 | ``Tensor``: Updated mask will be returned if mask is given \ |
| 68 | and `return_mask` is True. |
| 69 | """ |
| 70 | for layer in self.order: |
| 71 | if layer == 'conv': |
| 72 | if self.with_explicit_padding: |
| 73 | x = self.padding_layer(x) |
| 74 | mask = self.padding_layer(mask) |
| 75 | if return_mask: |
| 76 | x, updated_mask = self.conv( |
| 77 | x, mask, return_mask=return_mask) |
| 78 | else: |
| 79 | x = self.conv(x, mask, return_mask=False) |
| 80 | elif layer == 'norm' and norm and self.with_norm: |
| 81 | x = self.norm(x) |
| 82 | elif layer == 'act' and activate and self.with_activation: |
| 83 | x = self.activate(x) |
| 84 | |
| 85 | if return_mask: |
| 86 | return x, updated_mask |
| 87 | |
| 88 | return x |
nothing calls this directly
no outgoing calls
no test coverage detected