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

torch.OutOfMemoryError: CUDA out of memory. #156

Open
intersoulest opened this issue Dec 24, 2024 · 1 comment
Open

torch.OutOfMemoryError: CUDA out of memory. #156

intersoulest opened this issue Dec 24, 2024 · 1 comment

Comments

@intersoulest
Copy link

i want to inference a photo,but it have a error, i need help,please to point my question of program.
`import cv2
import os
import numpy as np
os.environ['CUDA_VISIBLE_DEVICES']='0'
import torch
from basicsr.models import build_model

from basicsr.utils.options import parse_options

if name=='main':
opt, args = parse_options('.', is_train=False)
device = 'cuda:0'
opt['network_g']['img_size'] = 512 // 4
model = build_model(opt)

print(model.net_g)
model.net_g = model.net_g.to(device)
model.net_g.eval()
path = "codes/basicsr/123.png"
# try_input = torch.randn((1,3,32,32)).float().to(device)
img = cv2.imread(path, cv2.IMREAD_COLOR).astype(np.float32) / 255.
img = torch.from_numpy(np.transpose(img[:, :, [2, 1, 0]], (2, 0, 1))).float()
img = img.unsqueeze(0).to(device)
print(img.shape)
# with torch.no_grad():
output = model.net_g(img)
print(output.shape)
print(model.net_g.flops()/1e9)
    # save image
output = output.data.squeeze().float().cpu().clamp_(0, 1).numpy()
output = np.transpose(output[[2, 1, 0], :, :], (1, 2, 0))
output = (output * 255.0).round().astype(np.uint8)
cv2.imwrite('IPG.png', output)`

image
image

@YuchuanTian
Copy link
Collaborator

It's not your fault; rather, the GPU Memory is too small for IPG. You can change to GPUs with a larger memory (like V100 with 32G memory), or you may refer to https://github.com/gladzhang/ART/blob/main/basicsr/models/art_model.py that crops the image into pieces first and then send them into the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants