MCPcopy Create free account
hub / github.com/buaacxf/VIPTR / forward

Method forward

modules/VIPTRv2.py:841–914  ·  view source on GitHub ↗
(self, x, size)

Source from the content-addressed store, hash-verified

839 self.downsample = None
840
841 def forward(self, x, size):
842 b, h, w, d = x.size()
843 # print(x.size())
844 if self.mixer_type == 'Local1':
845 for blk in self.blocks:
846 x = x.flatten(1).reshape(b, -1, d)
847 x = blk(x, size)
848 x = x.reshape(b, h, w, -1)
849
850 elif self.mixer_type == 'Local2':
851 rel_pos = self.Relpos((h, w), chunkwise_recurrent=self.chunkwise_recurrent)
852 for blk in self.blocks:
853 if self.use_checkpoint:
854 tmp_blk = partial(blk, incremental_state=None, chunkwise_recurrent=self.chunkwise_recurrent,
855 retention_rel_pos=rel_pos)
856 x = checkpoint.checkpoint(tmp_blk, x)
857 else:
858 x = blk(x, incremental_state=None, chunkwise_recurrent=self.chunkwise_recurrent,
859 retention_rel_pos=rel_pos)
860
861 elif self.mixer_type == 'Global1':
862 for blk in self.blocks:
863 x = x.flatten(1).reshape(b, -1, d)
864 # x = x.permute(0, 3, 1, 2).contiguous()
865 x = blk(x, size)
866 x = x.reshape(b, h, w, -1)
867
868 elif self.mixer_type == 'Global2':
869 for blk in self.blocks:
870 x = x.flatten(1).reshape(b, -1, d)
871 x = blk(x, size)
872 x = x.reshape(b, h, w, -1)
873
874 elif self.mixer_type == 'LG1':
875 # print(self.mixer_type)
876 # print(x.shape)
877 # rel_pos = self.Relpos((h, w), chunkwise_recurrent=self.chunkwise_recurrent)
878 for lblk, gblk in zip(self.local_unit, self.global_unit):
879 x = x.flatten(1).reshape(b, -1, d)
880 x1, x2 = torch.chunk(x, chunks=2, dim=2)
881 x1 = lblk(x1, size)
882 x2 = gblk(x2, size)
883 x = torch.cat([x1, x2], dim=2)
884 x = x.transpose(1, 2).contiguous().reshape(b, -1, h, w)
885 x = self.proj(x) + x
886 x = x.permute(0, 2, 3, 1).contiguous()
887 x = x.reshape(b, h, w, -1)
888
889 # x = x.flatten(1).reshape(b, -1, d)
890 # x1, x2 = torch.chunk(x, chunks=2, dim=2)
891 # x1 = lblk(x1, size)
892 # x2 = gblk(x2, size)
893 # x = torch.cat([x1, x2], dim=2)
894 # x = x.transpose(1, 2).contiguous().reshape(b, -1, h, w)
895 # x = self.proj(x) + x
896 # x = x.permute(0, 2, 3, 1).contiguous()
897 # x = x.reshape(b, h, w, -1)
898

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected