MCPcopy Create free account
hub / github.com/NVlabs/CTG / MapGridDecoder

Class MapGridDecoder

tbsim/models/diffuser_helpers.py:352–389  ·  view source on GitHub ↗

Has 3 doubling up-samples. UNet part based on https://github.com/milesial/Pytorch-UNet/tree/master/unet

Source from the content-addressed store, hash-verified

350from tbsim.models.base_models import Up, ConvBlock, IdentityBlock
351
352class MapGridDecoder(nn.Module):
353 """
354 Has 3 doubling up-samples.
355 UNet part based on https://github.com/milesial/Pytorch-UNet/tree/master/unet
356 """
357
358 def __init__(self, input_shape, output_channel, encoder_channels, bilinear=True, batchnorm=True):
359 super(MapGridDecoder, self).__init__()
360 input_channel = input_shape[0]
361 input_hw = np.array(input_shape[1:])
362 self.conv1 = nn.Sequential(
363 nn.Conv2d(input_channel, 512, kernel_size=3,
364 stride=1, padding=1, bias=False),
365 nn.ReLU(True)
366 )
367
368 self.up1 = Up(512 + encoder_channels[-1], 256, bilinear)
369 input_hw = input_hw * 2
370
371 self.up2 = Up(256 + encoder_channels[-2], 128, bilinear)
372 input_hw = input_hw * 2
373
374 self.up3 = Up(128 + encoder_channels[-3], 64, bilinear)
375 input_hw = input_hw * 2
376
377 self.conv2 = ConvBlock(64, [64, 64, 64], kernel_size=3, stride=1, batchnorm=batchnorm)
378 self.conv3 = nn.Conv2d(64, output_channel, kernel_size=1)
379 self.out_norm = nn.LayerNorm((output_channel, int(input_hw[0]), int(input_hw[1])))
380
381 def forward(self, feat_to_decode: torch.Tensor, encoder_feats: List[torch.Tensor]):
382 assert len(encoder_feats) >= 3
383 x = self.conv1(feat_to_decode)
384 x = self.up1(x, encoder_feats[-1])
385 x = self.up2(x, encoder_feats[-2])
386 x = self.up3(x, encoder_feats[-3])
387 x = self.conv2(x)
388 x = self.conv3(x)
389 return self.out_norm(x)
390
391def query_feature_grid(pos, feat_grid):
392 '''

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected