| 40 | |
| 41 | class GSEncoder(nn.Module): |
| 42 | def __init__(self, opt: Options, **kwargs): |
| 43 | super(GSEncoder, self).__init__() |
| 44 | self.width = opt.hidden_dim |
| 45 | self.patch_size = opt.patch_size |
| 46 | self.num_layers = opt.num_layers |
| 47 | |
| 48 | if len(opt.down_resolution) > 0: |
| 49 | self.actual_input_res = opt.down_resolution |
| 50 | else: |
| 51 | self.actual_input_res = (opt.image_height, opt.image_width) |
| 52 | |
| 53 | self.in_channels = opt.in_channels |
| 54 | |
| 55 | if opt.enable_depth: |
| 56 | self.in_channels += 1 |
| 57 | |
| 58 | self.transformer_encoder = TransformerEncoder( |
| 59 | in_channels=self.in_channels, |
| 60 | input_res=self.actual_input_res, |
| 61 | patch_size=self.patch_size, |
| 62 | layers=self.num_layers, |
| 63 | width=self.width, |
| 64 | heads=self.width // 64, |
| 65 | window_size=opt.bwindow_size |
| 66 | ) |
| 67 | self.transformer_encoder.set_grad_checkpointing(opt.checkpointing) |
| 68 | |
| 69 | def forward(self, x, timestamp=None): |
| 70 | assert x.dim() == 5, f"Input shape should be [b, #views, c, h, w] but {x.shape} is given" |