MCPcopy Create free account
hub / github.com/CompVis/zigma / __init__

Method __init__

utils/torchmetric_kid.py:167–231  ·  view source on GitHub ↗
(
        self,
        feature: Union[str, int, torch.nn.Module] = 2048,
        subsets: int = 100,
        subset_size: int = 1000,
        degree: int = 3,
        gamma: Optional[float] = None,  # type: ignore
        coef: float = 1.0,
        reset_real_features: bool = True,
        compute_on_step: Optional[bool] = None,
        **kwargs: Dict[str, Any],
    )

Source from the content-addressed store, hash-verified

165 is_differentiable: bool = False
166
167 def __init__(
168 self,
169 feature: Union[str, int, torch.nn.Module] = 2048,
170 subsets: int = 100,
171 subset_size: int = 1000,
172 degree: int = 3,
173 gamma: Optional[float] = None, # type: ignore
174 coef: float = 1.0,
175 reset_real_features: bool = True,
176 compute_on_step: Optional[bool] = None,
177 **kwargs: Dict[str, Any],
178 ) -> None:
179 super().__init__(compute_on_step=compute_on_step, **kwargs)
180
181 rank_zero_warn(
182 "Metric `Kernel Inception Distance` will save all extracted features in buffer."
183 " For large datasets this may lead to large memory footprint.",
184 UserWarning,
185 )
186
187 if isinstance(feature, (str, int)):
188 if not _TORCH_FIDELITY_AVAILABLE:
189 raise ModuleNotFoundError(
190 "Kernel Inception Distance metric requires that `Torch-fidelity` is installed."
191 " Either install as `pip install torchmetrics[image]` or `pip install torch-fidelity`."
192 )
193 valid_int_input = ("logits_unbiased", 64, 192, 768, 2048)
194 if feature not in valid_int_input:
195 raise ValueError(
196 f"Integer input to argument `feature` must be one of {valid_int_input}," f" but got {feature}."
197 )
198
199 self.inception: Module = NoTrainInceptionV3(name="inception-v3-compat", features_list=[str(feature)])
200 elif isinstance(feature, Module):
201 self.inception = feature
202 else:
203 raise TypeError("Got unknown input to argument `feature`")
204
205 if not (isinstance(subsets, int) and subsets > 0):
206 raise ValueError("Argument `subsets` expected to be integer larger than 0")
207 self.subsets = subsets
208
209 if not (isinstance(subset_size, int) and subset_size > 0):
210 raise ValueError("Argument `subset_size` expected to be integer larger than 0")
211 self.subset_size = subset_size
212
213 if not (isinstance(degree, int) and degree > 0):
214 raise ValueError("Argument `degree` expected to be integer larger than 0")
215 self.degree = degree
216
217 if gamma is not None and not (isinstance(gamma, float) and gamma > 0):
218 raise ValueError("Argument `gamma` expected to be `None` or float larger than 0")
219 self.gamma = gamma
220
221 if not (isinstance(coef, float) and coef > 0):
222 raise ValueError("Argument `coef` expected to be float larger than 0")
223 self.coef = coef
224

Callers

nothing calls this directly

Calls 1

NoTrainInceptionV3Class · 0.90

Tested by

no test coverage detected