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

Method __init__

utils/torchmetric_inception.py:105–143  ·  view source on GitHub ↗
(
        self,
        feature: Union[str, int, Module] = "logits_unbiased",
        splits: int = 10,
        normalize: bool = False,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

103 feature_network: str = "inception"
104
105 def __init__(
106 self,
107 feature: Union[str, int, Module] = "logits_unbiased",
108 splits: int = 10,
109 normalize: bool = False,
110 **kwargs: Any,
111 ) -> None:
112 super().__init__(**kwargs)
113
114 rank_zero_warn(
115 "Metric `InceptionScore` will save all extracted features in buffer."
116 " For large datasets this may lead to large memory footprint.",
117 UserWarning,
118 )
119
120 if isinstance(feature, (str, int)):
121 if not _TORCH_FIDELITY_AVAILABLE:
122 raise ModuleNotFoundError(
123 "InceptionScore metric requires that `Torch-fidelity` is installed."
124 " Either install as `pip install torchmetrics[image]` or `pip install torch-fidelity`."
125 )
126 valid_int_input = ("logits_unbiased", 64, 192, 768, 2048)
127 if feature not in valid_int_input:
128 raise ValueError(
129 f"Integer input to argument `feature` must be one of {valid_int_input}, but got {feature}."
130 )
131
132 self.inception = NoTrainInceptionV3(name="inception-v3-compat", features_list=[str(feature)])
133 elif isinstance(feature, Module):
134 self.inception = feature
135 else:
136 raise TypeError("Got unknown input to argument `feature`")
137
138 if not isinstance(normalize, bool):
139 raise ValueError("Argument `normalize` expected to be a bool")
140 self.normalize = normalize
141
142 self.splits = splits
143 self.add_state("features", [], dist_reduce_fx=None)
144
145 def update(self, imgs: Tensor) -> None:
146 """Update the state with extracted features."""

Callers

nothing calls this directly

Calls 1

NoTrainInceptionV3Class · 0.90

Tested by

no test coverage detected