Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS-GMSD does not work with cuda tensors #90

Closed
PavelOstyakov opened this issue Jun 11, 2020 · 0 comments · Fixed by #91
Closed

MS-GMSD does not work with cuda tensors #90

PavelOstyakov opened this issue Jun 11, 2020 · 0 comments · Fixed by #91
Assignees
Labels
bug Something isn't working

Comments

@PavelOstyakov
Copy link
Contributor

In [1]: from photosynthesis_metrics import MultiScaleGMSDLoss

In [2]: import torch

In [3]: loss = MultiScaleGMSDLoss(chromatic=True)

In [4]: x = torch.rand(1, 3, 256, 256)

In [5]: y = torch.rand(1, 3, 256, 256)

In [6]: loss(x, y)
/home/ostyakov/.local/lib/python3.6/site-packages/photosynthesis_metrics/utils.py:58: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  assert (torch.tensor(scale_weights).dim() == 1), \
Out[6]: tensor(0.1725)

In [7]: loss(x.cuda(), y.cuda())
/home/ostyakov/.local/lib/python3.6/site-packages/photosynthesis_metrics/utils.py:58: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  assert (torch.tensor(scale_weights).dim() == 1), \
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-7-d464c6bd32e6> in <module>()
----> 1 loss(x.cuda(), y.cuda())

/home/ostyakov/.local/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--> 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

/home/ostyakov/.local/lib/python3.6/site-packages/photosynthesis_metrics/gmsd.py in forward(self, prediction, target)
    208         prediction, target = _adjust_dimensions(input_tensors=(prediction, target))
    209
--> 210         return self.compute_metric(prediction, target)
    211
    212     def compute_metric(self, prediction: torch.Tensor, target: torch.Tensor) -> torch.Tensor:

/home/ostyakov/.local/lib/python3.6/site-packages/photosynthesis_metrics/gmsd.py in compute_metric(self, prediction, target)
    248             # Convert to YIQ color space https://en.wikipedia.org/wiki/YIQ
    249             iq_weights = torch.tensor([[0.5959, -0.2746, -0.3213], [0.2115, -0.5227, 0.3112]]).t()
--> 250             prediction_iq = torch.matmul(prediction.permute(0, 2, 3, 1), iq_weights).permute(0, 3, 1, 2)
    251             target_iq = torch.matmul(target.permute(0, 2, 3, 1), iq_weights).permute(0, 3, 1, 2)
    252

RuntimeError: Expected object of device type cuda but got device type cpu for argument #2 'mat2' in call to _th_mm

@PavelOstyakov PavelOstyakov added the bug Something isn't working label Jun 11, 2020
@zakajd zakajd self-assigned this Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants