MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / interpolate

Function interpolate

detrsmpl/models/heads/pare_head.py:137–158  ·  view source on GitHub ↗

Args: feat (torch.Tensor): [B, C, H, W] image features uv (torch.Tensor): [B, 2, N] uv coordinates in the image plane, range [-1, 1] Returns: samples[:, :, :, 0] (torch.Tensor): [B, C, N] image features at the uv coordinates

(feat, uv)

Source from the content-addressed store, hash-verified

135
136
137def interpolate(feat, uv):
138 """
139 Args:
140 feat (torch.Tensor): [B, C, H, W] image features
141 uv (torch.Tensor): [B, 2, N] uv coordinates
142 in the image plane, range [-1, 1]
143 Returns:
144 samples[:, :, :, 0] (torch.Tensor):
145 [B, C, N] image features at the uv coordinates
146 """
147 if uv.shape[-1] != 2:
148 uv = uv.transpose(1, 2) # [B, N, 2]
149 uv = uv.unsqueeze(2) # [B, N, 1, 2]
150 # NOTE: for newer PyTorch, it seems that training
151 # results are degraded due to implementation diff in F.grid_sample
152 # for old versions, simply remove the aligned_corners argument.
153 if int(torch.__version__.split('.')[1]) < 4:
154 samples = torch.nn.functional.grid_sample(feat, uv) # [B, C, N, 1]
155 else:
156 samples = torch.nn.functional.grid_sample(
157 feat, uv, align_corners=True) # [B, C, N, 1]
158 return samples[:, :, :, 0] # [B, C, N]
159
160
161def _softmax(tensor, temperature, dim=-1):

Callers 2

_get_local_featsMethod · 0.70
forwardMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected