class_docstr: Positional encoding using random spatial frequencies.
class_docstr_tok: ["Positional","encoding","using","random","spatial","frequencies","."]
docstr: Generate positional encoding for a grid of the specified size.
docstr_tok: ["Generate","positional","encoding","for","a","grid","of","the","specified","size","."]
code: def forward(self, size: Tuple[int, int]) -> paddle.Tensor:
      """Generate positional encoding for a grid of the specified size."""
      h, w = size
      device: Any = self.positional_encoding_gaussian_matrix.place
      grid = paddle.ones(shape=(h, w), dtype="float32")
      y_embed = grid.cumsum(axis=0) - 0.5
      x_embed = grid.cumsum(axis=1) - 0.5
      y_embed = y_embed / h
      x_embed = x_embed / w
      pe = self._pe_encoding(
          paddle.stack(x=[x_embed, y_embed], axis=-1)
      )
      return pe.transpose(perm=[2, 0, 1])
  
file_path: PaddleSeg/contrib/SegmentAnything/segment_anything/modeling/prompt_encoder.py
imports: import paddle
  import numpy
  from typing import Any, Optional, Tuple, Type
  from common import LayerNorm2d
label_desc: Use image node_id 3 for calling the PositionEmbeddingRandom obj's underlying member method code with example usage: obj.forward(size) and returns: pe