class_docstr: Perceptual loss using features from pretrained deep neural networks trained. The function supports networks
  pretrained on: ImageNet that use the LPIPS approach from Zhang, et al. "The unreasonable effectiveness of deep
  features as a perceptual metric." https://arxiv.org/abs/1801.03924 ; RadImagenet from Mei, et al. "RadImageNet: An
  Open Radiologic Deep Learning Research Dataset for Effective Transfer Learning"
  https://pubs.rsna.org/doi/full/10.1148/ryai.210315 ; MedicalNet from Chen et al. "Med3D: Transfer Learning for
  3D Medical Image Analysis" https://arxiv.org/abs/1904.00625 ;
  and ResNet50 from Torchvision: https://pytorch.org/vision/main/models/generated/torchvision.models.resnet50.html .
  
  The fake 3D implementation is based on a 2.5D approach where we calculate the 2D perceptual loss on slices from all
  three axes and average. The full 3D approach uses a 3D network to calculate the perceptual loss.
  
  Args:
      spatial_dims: number of spatial dimensions.
      network_type: {``"alex"``, ``"vgg"``, ``"squeeze"``, ``"radimagenet_resnet50"``,
      ``"medicalnet_resnet10_23datasets"``, ``"medicalnet_resnet50_23datasets"``, ``"resnet50"``}
          Specifies the network architecture to use. Defaults to ``"alex"``.
      is_fake_3d: if True use 2.5D approach for a 3D perceptual loss.
      fake_3d_ratio: ratio of how many slices per axis are used in the 2.5D approach.
      cache_dir: path to cache directory to save the pretrained network weights.
      pretrained: whether to load pretrained weights. This argument only works when using networks from
          LIPIS or Torchvision. Defaults to ``"True"``.
      pretrained_path: if `pretrained` is `True`, users can specify a weights file to be loaded
          via using this argument. This argument only works when ``"network_type"`` is "resnet50".
          Defaults to `None`.
      pretrained_state_dict_key: if `pretrained_path` is not `None`, this argument is used to
          extract the expected state dict. This argument only works when ``"network_type"`` is "resnet50".
          Defaults to `None`.
code: def __init__(
      self,
      spatial_dims: int,
      network_type: str = PercetualNetworkType.alex,
      is_fake_3d: bool = True,
      fake_3d_ratio: float = 0.5,
      cache_dir: str | None = None,
      pretrained: bool = True,
      pretrained_path: str | None = None,
      pretrained_state_dict_key: str | None = None,
  ):
      super().__init__()
  
      if spatial_dims not in [2, 3]:
          raise NotImplementedError(
              "Perceptual loss is implemented only in 2D and 3D."
          )
  
      if (
          spatial_dims == 2 or is_fake_3d
      ) and "medicalnet_" in network_type:
          raise ValueError(
              "MedicalNet networks are only compatible with ``spatial_dims=3``."
              "Argument is_fake_3d must be set to False."
          )
  
      if network_type.lower() not in list(PercetualNetworkType):
          raise ValueError(
              "Unrecognised criterion entered for Adversarial Loss. Must be one in: %s"
              % ", ".join(PercetualNetworkType)
          )
  
      if cache_dir:
          torch.hub.set_dir(cache_dir)
          # raise a warning that this may change the default cache dir for all torch.hub calls
          warnings.warn(
              f"Setting cache_dir to {cache_dir}, this may change the default cache dir for all torch.hub calls."
          )
  
      self.spatial_dims = spatial_dims
      self.perceptual_function: nn.Module
      if spatial_dims == 3 and is_fake_3d is False:
          self.perceptual_function = MedicalNetPerceptualSimilarity(
              net=network_type, verbose=False
          )
      elif "radimagenet_" in network_type:
          self.perceptual_function = RadImageNetPerceptualSimilarity(
              net=network_type, verbose=False
          )
      elif network_type == "resnet50":
          self.perceptual_function = (
              TorchvisionModelPerceptualSimilarity(
                  net=network_type,
                  pretrained=pretrained,
                  pretrained_path=pretrained_path,
                  pretrained_state_dict_key=pretrained_state_dict_key,
              )
          )
      else:
          self.perceptual_function = LPIPS(
              pretrained=pretrained, net=network_type, verbose=False
          )
      self.is_fake_3d = is_fake_3d
      self.fake_3d_ratio = fake_3d_ratio
  
imports: from __future__ import annotations
  import warnings
  import torch
  import torch.nn
  from monai.utils import optional_import
  from monai.utils.enums import StrEnum
label_desc: Use image node_id 1 to create a new PerceptualLoss object from inherited base classes: nn with example: obj = PerceptualLoss(spatial_dims, network_type, is_fake_3d, fake_3d_ratio, cache_dir, pretrained, pretrained_path, pretrained_state_dict_key)