Flax implementation of 2D Downsample layer Args: in_channels (`int`): Input channels dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32): Parameters `dtype`
| 93 | |
| 94 | |
| 95 | class FlaxDownsample2D(nn.Module): |
| 96 | """ |
| 97 | Flax implementation of 2D Downsample layer |
| 98 | |
| 99 | Args: |
| 100 | in_channels (`int`): |
| 101 | Input channels |
| 102 | dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32): |
| 103 | Parameters `dtype` |
| 104 | """ |
| 105 | |
| 106 | in_channels: int |
| 107 | dtype: jnp.dtype = jnp.float32 |
| 108 | |
| 109 | def setup(self): |
| 110 | self.conv = nn.Conv( |
| 111 | self.in_channels, |
| 112 | kernel_size=(3, 3), |
| 113 | strides=(2, 2), |
| 114 | padding="VALID", |
| 115 | dtype=self.dtype, |
| 116 | ) |
| 117 | |
| 118 | def __call__(self, hidden_states): |
| 119 | pad = ((0, 0), (0, 1), (0, 1), (0, 0)) # pad height and width dim |
| 120 | hidden_states = jnp.pad(hidden_states, pad_width=pad) |
| 121 | hidden_states = self.conv(hidden_states) |
| 122 | return hidden_states |
| 123 | |
| 124 | |
| 125 | class FlaxResnetBlock2D(nn.Module): |