You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
torchmetrics.image.fid FrechetInceptionDistance normalize argument is not working. The description states that if normalize=True, then the input images are expected to be of float type. Yet if I input float I still get the ValueError: Expecting image as torch.Tensor with dtype=torch.uint8
To Reproduce
The following is adapted from the example provided with the docs, now using random images of dtype float. [(https://torchmetrics.readthedocs.io/en/latest/image/frechet_inception_distance.html)]
### Traceback
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [9], in <cell line: 10>()
8 print(imgs_dist1.size())
9 imgs_dist2 = torch.rand((100, 3, 299, 299), dtype=torch.float)
---> 10 fid.update(imgs_dist1, real=True)
11 fid.update(imgs_dist2, real=False)
12 fid.compute()
File ~\anaconda3\lib\site-packages\torchmetrics\metric.py:391, in Metric._wrap_update.<locals>.wrapped_func(*args, **kwargs)
389 with torch.set_grad_enabled(self._enable_grad):
390 try:
--> 391 update(*args, **kwargs)
392 except RuntimeError as err:
393 if "Expected all tensors to be on" in str(err):
File ~\anaconda3\lib\site-packages\torchmetrics\image\fid.py:253, in FrechetInceptionDistance.update(self, imgs, real)
246 def update(self, imgs: Tensor, real: bool) -> None: # type: ignore
247 """Update the state with extracted features.
248
249 Args:
250 imgs: tensor with images feed to the feature extractor
251 real: bool indicating if ``imgs`` belong to the real or the fake distribution
252 """
--> 253 features = self.inception(imgs)
255 if real:
256 self.real_features.append(features)
File ~\anaconda3\lib\site-packages\torch\nn\modules\module.py:1102, in Module._call_impl(self, *input, **kwargs)
1098 # If we don't have any hooks, we want to skip the rest of the logic in
1099 # this function, and just call forward.
1100 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1101 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1102 return forward_call(*input, **kwargs)
1103 # Do not call functions when jit is used
1104 full_backward_hooks, non_full_backward_hooks = [], []
File ~\anaconda3\lib\site-packages\torchmetrics\image\fid.py:57, in NoTrainInceptionV3.forward(self, x)
56 def forward(self, x: Tensor) -> Tensor:
---> 57 out = super().forward(x)
58 return out[0].reshape(x.shape[0], -1)
File ~\anaconda3\lib\site-packages\torch_fidelity\feature_extractor_inceptionv3.py:92, in FeatureExtractorInceptionV3.forward(self, x)
91 def forward(self, x):
---> 92 vassert(torch.is_tensor(x) and x.dtype == torch.uint8, 'Expecting image as torch.Tensor with dtype=torch.uint8')
93 features = {}
94 remaining_features = self.features_list.copy()
File ~\anaconda3\lib\site-packages\torch_fidelity\helpers.py:9, in vassert(truecond, message)
7 def vassert(truecond, message):
8 if not truecond:
----> 9 raise ValueError(message)
ValueError: Expecting image as torch.Tensor with dtype=torch.uint8
Environment
TorchMetrics version 0.9.3 (conda)
Python 3.9.12 & PyTorch 1.10.2
torch fidelity installed using pip install torch-fidelity
The text was updated successfully, but these errors were encountered:
Hi @Jelle-Plomp, thanks for raising the issue. I've run your code on the master and also on the latest 0.10.2 release. Found out I got the same error as you for the latest release. However, everything seems to work fine on master (likely thanks to #1246). You can either install torchmetrics from the source, or we are also planning to come with a new release soon.
🐛 Bug
torchmetrics.image.fid FrechetInceptionDistance normalize argument is not working. The description states that if normalize=True, then the input images are expected to be of float type. Yet if I input float I still get the ValueError: Expecting image as torch.Tensor with dtype=torch.uint8
To Reproduce
The following is adapted from the example provided with the docs, now using random images of dtype float. [(https://torchmetrics.readthedocs.io/en/latest/image/frechet_inception_distance.html)]
Steps to reproduce the behavior...
Code sample
Environment
The text was updated successfully, but these errors were encountered: