class_docstr: Sinusoidal positional encodings
  
  Using the scaling term from https://github.com/megvii-research/CREStereo/blob/master/nets/attention/position_encoding.py
  Reference implementation from https://github.com/facebookresearch/detr/blob/8a144f83a287f4d3fece4acdf073f387c5af387d/models/position_encoding.py#L28-L48
class_docstr_tok: ["Sinusoidal","positional","encodings","Using","the","scaling","term","from","https",":","\/\/github.com\/megvii-research\/CREStereo\/blob\/master\/nets\/attention\/position_encoding.py","Reference","implementation","from","https",":","\/\/github.com\/facebookresearch\/detr\/blob\/8a144f83a287f4d3fece4acdf073f387c5af387d\/models\/position_encoding.py","#","L28-L48"]
code: def _make_pe_of_size(self, size: int) -> Tensor:
      pe = torch.zeros(
          (self.dim_model, *(size, size)), dtype=torch.float32
      )
      y_positions = (
          torch.ones((size, size)).cumsum(0).float().unsqueeze(0)
      )
      x_positions = (
          torch.ones((size, size)).cumsum(1).float().unsqueeze(0)
      )
      div_term = torch.exp(
          torch.arange(0.0, self.dim_model // 2, 2)
          * (-math.log(10000.0) / self.dim_model // 2)
      )
      div_term = div_term[:, None, None]
      pe[0::4, :, :] = torch.sin(x_positions * div_term)
      pe[1::4, :, :] = torch.cos(x_positions * div_term)
      pe[2::4, :, :] = torch.sin(y_positions * div_term)
      pe[3::4, :, :] = torch.cos(y_positions * div_term)
      pe = pe.unsqueeze(0)
      return pe
  
imports: import math
  from functools import partial
  from typing import Callable, Dict, Iterable, List, Optional, Tuple
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torchvision.models.optical_flow.raft
  from torch import Tensor
  from torchvision.models._api import register_model, Weights, WeightsEnum
  from torchvision.models._utils import handle_legacy_interface
  from torchvision.models.optical_flow._utils import grid_sample, make_coords_grid, upsample_flow
  from torchvision.ops import Conv2dNormActivation
  from torchvision.prototype.transforms._presets import StereoMatching
label_desc: Use image node_id 2 for calling the PositionalEncodingSine obj's underlying member method code with example usage: obj._make_pe_of_size(size) and returns: pe