@@ -100,16 +100,15 @@ def __init__(
100100 super ().__init__ ()
101101
102102 if spatial_dims not in [2 , 3 ]:
103- raise NotImplementedError ("Perceptual loss is implemented only in 2D and 3D." , stacklevel = 2 )
103+ raise NotImplementedError ("Perceptual loss is implemented only in 2D and 3D." )
104104
105105 network_type = network_type .lower ()
106106
107107 # Strict validation for MedicalNet
108108 if "medicalnet_" in network_type :
109109 if spatial_dims == 2 or is_fake_3d :
110110 raise ValueError (
111- "MedicalNet networks are only compatible with ``spatial_dims=3``. Argument is_fake_3d must be set to False." ,
112- stacklevel = 2 ,
111+ "MedicalNet networks are only compatible with ``spatial_dims=3``. Argument is_fake_3d must be set to False."
113112 )
114113 if not channel_wise :
115114 warnings .warn (
@@ -118,12 +117,11 @@ def __init__(
118117
119118 # Channel-wise only for MedicalNet
120119 elif channel_wise :
121- raise ValueError ("Channel-wise loss is only compatible with MedicalNet networks." , stacklevel = 2 )
120+ raise ValueError ("Channel-wise loss is only compatible with MedicalNet networks." )
122121
123122 if network_type .lower () not in list (PerceptualNetworkType ):
124123 raise ValueError (
125- f"Unrecognised criterion entered for Perceptual Loss. Must be one in: { ', ' .join (PerceptualNetworkType )} " ,
126- stacklevel = 2 ,
124+ f"Unrecognised criterion entered for Perceptual Loss. Must be one in: { ', ' .join (PerceptualNetworkType )} "
127125 )
128126 if cache_dir :
129127 torch .hub .set_dir (cache_dir )
@@ -203,7 +201,7 @@ def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
203201 """
204202 if target .shape != input .shape :
205203 raise ValueError (
206- f"ground truth has differing shape ({ target .shape } ) from input ({ input .shape } )" , stacklevel = 2
204+ f"ground truth has differing shape ({ target .shape } ) from input ({ input .shape } )"
207205 )
208206
209207 if self .spatial_dims == 3 and self .is_fake_3d :
@@ -249,7 +247,7 @@ def __init__(
249247 super ().__init__ ()
250248 if net not in HF_MONAI_MODELS :
251249 raise ValueError (
252- f"Invalid download model name '{ net } '. Must be one of: { ', ' .join (HF_MONAI_MODELS )} ." , stacklevel = 2
250+ f"Invalid download model name '{ net } '. Must be one of: { ', ' .join (HF_MONAI_MODELS )} ."
253251 )
254252
255253 self .model = torch .hub .load (
@@ -345,7 +343,7 @@ def __init__(self, net: str = "radimagenet_resnet50", verbose: bool = False, cac
345343 super ().__init__ ()
346344 if net not in HF_MONAI_MODELS :
347345 raise ValueError (
348- f"Invalid download model name '{ net } '. Must be one of: { ', ' .join (HF_MONAI_MODELS )} ." , stacklevel = 2
346+ f"Invalid download model name '{ net } '. Must be one of: { ', ' .join (HF_MONAI_MODELS )} ."
349347 )
350348 self .model = torch .hub .load (
351349 "Project-MONAI/perceptual-models:main" , model = net , verbose = verbose , cache_dir = cache_dir , trust_repo = True
@@ -416,7 +414,7 @@ def __init__(
416414 supported_networks = ["resnet50" ]
417415 if net not in supported_networks :
418416 raise NotImplementedError (
419- f"'net' { net } is not supported, please select a network from { supported_networks } ." , stacklevel = 2
417+ f"'net' { net } is not supported, please select a network from { supported_networks } ."
420418 )
421419
422420 if pretrained_path is None :
0 commit comments