S-aiueo32 / contextual_loss_pytorch

Contextual Loss (CX) and Contextual Bilateral Loss (CoBi).
MIT License
172 stars 45 forks source link

CUDA out of memory #7

Open RuyuXu2019 opened 4 years ago

RuyuXu2019 commented 4 years ago

How can I solve this question? Do it really need so much memory?

Traceback (most recent call last): File "main.py", line 33, in main() File "main.py", line 27, in main t.train() File "/home/anaconda3/workFile/DCTtoSpatial/YCbCrCxLoss/YCbCrCxLoss/src/trainer.py", line 58, in train loss_reconstruct = self.loss(sr, hr) File "/home/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call result = self.forward(*input, *kwargs) File "/home/anaconda3/workFile/DCTtoSpatial/YCbCrCxLoss/YCbCrCxLoss/src/loss/init.py", line 78, in forward loss = l['function'](sr, hr) File "/home/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call result = self.forward(input, **kwargs) File "/home/anaconda3/workFile/DCTtoSpatial/YCbCrCxLoss/YCbCrCxLoss/src/loss/modules/contextual.py", line 66, in forward return F.contextual_loss(x, y, self.band_width) File "/home/anaconda3/workFile/DCTtoSpatial/YCbCrCxLoss/YCbCrCxLoss/src/loss/functional.py", line 43, in contextual_loss dist_raw = compute_cosine_distance(x, y) File "/home/anaconda3/workFile/DCTtoSpatial/YCbCrCxLoss/YCbCrCxLoss/src/loss/functional.py", line 150, in compute_cosine_distance dist = 1 - cosine_sim File "/home/anaconda3/lib/python3.6/site-packages/torch/tensor.py", line 325, in rsub return _C._VariableFunctions.rsub(self, other) RuntimeError: CUDA out of memory. Tried to allocate 5.06 GiB (GPU 1; 10.76 GiB total capacity; 5.43 GiB already allocated; 4.33 GiB free; 138.94 MiB cached)

hjynwa commented 3 years ago

The same question...

Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import torchvision.transforms as transforms
>>> import contextual_loss as cl 
>>> import numpy as np
>>> import cv2
>>> 
>>> img1 = torch.rand(1, 3, 512, 512)
>>> img2 = torch.rand(1, 3, 512, 512)
>>> criterion = cl.ContextualLoss()
>>> loss = criterion(img1, img2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/hanjin/.conda/envs/py35/lib/python3.5/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/hanjin/.conda/envs/py35/lib/python3.5/site-packages/contextual_loss_pytorch-latest-py3.5.egg/contextual_loss/modules/contextual.py", line 66, in forward
  File "/home/hanjin/.conda/envs/py35/lib/python3.5/site-packages/contextual_loss_pytorch-latest-py3.5.egg/contextual_loss/functional.py", line 43, in contextual_loss
  File "/home/hanjin/.conda/envs/py35/lib/python3.5/site-packages/contextual_loss_pytorch-latest-py3.5.egg/contextual_loss/functional.py", line 147, in compute_cosine_distance
RuntimeError: [enforce fail at CPUAllocator.cpp:64] . DefaultCPUAllocator: can't allocate memory: you tried to allocate 274877906944 bytes. Error code 12 (Cannot allocate memory)
SuperBruceJia commented 2 years ago

+1