docstr: Initializes a perceptual loss torch.nn.Module.
  
  Args:
      pretrained: This flag controls the linear layers should be pretrained version or random
      net: Indicate backbone to use, choose between ['alex','vgg','squeeze']
      spatial: If input should be spatial averaged
      pnet_rand: If backbone should be random or use imagenet pre-trained weights
      pnet_tune: If backprop should be enabled
      use_dropout: If dropout layers should be added
      model_path: Model path to load pretained models from
      eval_mode: If network should be in evaluation mode
      resize: If input should be resized to this size
code: def __init__(
      self,
      pretrained: bool = True,
      net: Literal["alex", "vgg", "squeeze"] = "alex",
      spatial: bool = False,
      pnet_rand: bool = False,
      pnet_tune: bool = False,
      use_dropout: bool = True,
      model_path: Optional[str] = None,
      eval_mode: bool = True,
      resize: Optional[int] = None,
  ) -> None:
      """Initializes a perceptual loss torch.nn.Module.
  
      Args:
          pretrained: This flag controls the linear layers should be pretrained version or random
          net: Indicate backbone to use, choose between ['alex','vgg','squeeze']
          spatial: If input should be spatial averaged
          pnet_rand: If backbone should be random or use imagenet pre-trained weights
          pnet_tune: If backprop should be enabled
          use_dropout: If dropout layers should be added
          model_path: Model path to load pretained models from
          eval_mode: If network should be in evaluation mode
          resize: If input should be resized to this size
  
      """
      super().__init__()
  
      self.pnet_type = net
      self.pnet_tune = pnet_tune
      self.pnet_rand = pnet_rand
      self.spatial = spatial
      self.resize = resize
      self.scaling_layer = ScalingLayer()
  
      if self.pnet_type in ["vgg", "vgg16"]:
          net_type = Vgg16
          self.chns = [64, 128, 256, 512, 512]
      elif self.pnet_type == "alex":
          net_type = Alexnet  # type: ignore[assignment]
          self.chns = [64, 192, 384, 256, 256]
      elif self.pnet_type == "squeeze":
          net_type = SqueezeNet  # type: ignore[assignment]
          self.chns = [64, 128, 256, 384, 384, 512, 512]
      self.L = len(self.chns)
  
      self.net = net_type(
          pretrained=not self.pnet_rand, requires_grad=self.pnet_tune
      )
  
      self.lin0 = NetLinLayer(self.chns[0], use_dropout=use_dropout)
      self.lin1 = NetLinLayer(self.chns[1], use_dropout=use_dropout)
      self.lin2 = NetLinLayer(self.chns[2], use_dropout=use_dropout)
      self.lin3 = NetLinLayer(self.chns[3], use_dropout=use_dropout)
      self.lin4 = NetLinLayer(self.chns[4], use_dropout=use_dropout)
      self.lins = [
          self.lin0,
          self.lin1,
          self.lin2,
          self.lin3,
          self.lin4,
      ]
      if self.pnet_type == "squeeze":  # 7 layers for squeezenet
          self.lin5 = NetLinLayer(self.chns[5], use_dropout=use_dropout)
          self.lin6 = NetLinLayer(self.chns[6], use_dropout=use_dropout)
          self.lins += [self.lin5, self.lin6]
      self.lins = nn.ModuleList(self.lins)  # type: ignore[assignment]
  
      if pretrained:
          if model_path is None:
              model_path = os.path.abspath(
                  os.path.join(inspect.getfile(self.__init__), "..", f"lpips_models/{net}.pth")  # type: ignore[misc]
              )
  
          self.load_state_dict(
              torch.load(model_path, map_location="cpu"), strict=False
          )
  
      if eval_mode:
          self.eval()
  
imports: import inspect
  import os
  from typing import List, NamedTuple, Optional, Tuple, Union
  import torch
  from torch import Tensor, nn
  from typing_extensions import Literal
  from torchmetrics.utilities.imports import _TORCHVISION_AVAILABLE, _TORCHVISION_GREATER_EQUAL_0_13
label_desc: Use image node_id 1 to create a new _LPIPS object from inherited base classes: nn with example: obj = _LPIPS(pretrained, net, spatial, pnet_rand, pnet_tune, use_dropout, model_path, eval_mode, resize)