Skip to content

torch.OutOfMemoryError: CUDA out of memory. #156

@intersoulest

Description

@intersoulest

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions