class_docstr: Add coords to a tensor.
  
  MIT License
  Copyright (c) 2018 Walsvid
  
  Link to the paper: https://arxiv.org/abs/1807.03247
  Link to the PyTorch implementation: https://github.com/walsvid/CoordConv
class_docstr_tok: ["Add","coords","to","a","tensor",".","MIT","License","Copyright","(","c",")","2018","Walsvid","Link","to","the","paper",":","https",":","\/\/arxiv.org\/abs\/1807.03247","Link","to","the","PyTorch","implementation",":","https",":","\/\/github.com\/walsvid\/CoordConv"]
docstr: Forward pass.
  
  Args:
      input_tensor (Tensor): Input tensor
  
  Returns:
      Tensor: Output tensor with added coordinates.
docstr_tok: ["Forward","pass",".","Args",":","input_tensor","(","Tensor",")",":","Input","tensor","Returns",":","Tensor",":","Output","tensor","with","added","coordinates","."]
code: def forward(self, input_tensor: Tensor) -> Tensor:
      """Forward pass.
  
      Args:
          input_tensor (Tensor): Input tensor
  
      Returns:
          Tensor: Output tensor with added coordinates.
      """
      # NOTE: This is a modified version of the original implementation,
      #   which only supports rank 2 tensors.
      batch, _, x_dim, y_dim = input_tensor.shape
      xx_ones = torch.ones([1, 1, 1, y_dim], dtype=torch.int32)
      yy_ones = torch.ones([1, 1, 1, x_dim], dtype=torch.int32)
  
      xx_range = torch.arange(x_dim, dtype=torch.int32)
      yy_range = torch.arange(y_dim, dtype=torch.int32)
      xx_range = xx_range[None, None, :, None]
      yy_range = yy_range[None, None, :, None]
  
      xx_channel = torch.matmul(xx_range, xx_ones)
      yy_channel = torch.matmul(yy_range, yy_ones)
  
      # Transpose y
      yy_channel = yy_channel.permute(0, 1, 3, 2)
  
      xx_channel = xx_channel.float() / (x_dim - 1)
      yy_channel = yy_channel.float() / (y_dim - 1)
  
      xx_channel = xx_channel * 2 - 1
      yy_channel = yy_channel * 2 - 1
  
      xx_channel = xx_channel.repeat(batch, 1, 1, 1).to(
          input_tensor.device
      )
      yy_channel = yy_channel.repeat(batch, 1, 1, 1).to(
          input_tensor.device
      )
  
      out = torch.cat([input_tensor, xx_channel, yy_channel], dim=1)
  
      if self.with_r:
          rr_channel = torch.sqrt(
              torch.pow(xx_channel - 0.5, 2)
              + torch.pow(yy_channel - 0.5, 2)
          )
          out = torch.cat([out, rr_channel], dim=1)
  
      return out
  
imports: from __future__ import annotations
  import torch
  import torch.nn.functional
  import torchvision
  from einops import rearrange
  from sklearn.cluster import KMeans
  from torch import Tensor, nn
  from torch.fx.graph_module import GraphModule
  from torch.nn.common_types import _size_2_t
  from torch.utils.data import DataLoader
  from torchvision.models.feature_extraction import create_feature_extractor
  from tqdm import tqdm
  from anomalib.models.cfa.anomaly_map import AnomalyMapGenerator
  from anomalib.models.components import DynamicBufferModule
  from anomalib.models.components.feature_extractors import dryrun_find_featuremap_dims
label_desc: Use image node_id 2 for calling the AddCoords obj's underlying member method code with example usage: obj.forward(input_tensor) and returns: out