i just want to use this code to get the voc's segmentation images, when i use this code on my computer , i meet this error:
RuntimeError: CUDA out of memory. Tried to allocate 1.04 GiB (GPU 0; 3.95 GiB total capacity; 1.24 GiB already allocated; 741.94 MiB free; 1.03 GiB cached)
the code:
`import os
import torch
import torch.nn as nn
import argparse
import cv2
import numpy as np
from upsnet.config.config import *
from upsnet.config.parse_args import parse_args
i just want to use this code to get the voc's segmentation images, when i use this code on my computer , i meet this error:
RuntimeError: CUDA out of memory. Tried to allocate 1.04 GiB (GPU 0; 3.95 GiB total capacity; 1.24 GiB already allocated; 741.94 MiB free; 1.03 GiB cached)
the code: `import os import torch import torch.nn as nn import argparse import cv2 import numpy as np
from upsnet.config.config import * from upsnet.config.parse_args import parse_args
from upsnet.models import *
from PIL import Image, ImageDraw
def get_pallete():
parser = argparse.ArgumentParser() args, rest = parser.parse_known_args() args.cfg = "/home/sunny/SK/Cut_and_paste/UPSNet-master/upsnet/experiments/upsnet_resnet50_coco_4gpu.yaml" args.weight_path = "/home/sunny/SK/Cut_and_paste/UPSNet-master/model/upsnet_resnet_50_coco_90000.pth" args.eval_only = "Ture" update_config(args.cfg)
test_model = eval("resnet_50_upsnet")().cuda() test_model.load_state_dict(torch.load(args.weight_path))
print(test_model)
for p in test_model.parameters(): p.requires_grad = False
test_model.eval()
im = cv2.imread("/media/sunny/52F058D7F058C341/project/Data/PASCAL_VOC/2012/JPEGImages/2007_000027.jpg") im_resize = cv2.resize(im,(2048,1024),interpolation=cv2.INTER_CUBIC) im_resize = im_resize.transpose(2, 0, 1)
im_tensor = torch.from_numpy(im_resize) im_tensor =torch.unsqueeze(im_tensor,0).type(torch.FloatTensor).cuda() print(im_tensor.shape) # torch.Size([1, 3, 1024, 2048])
test_fake_numpy_data = np.random.rand(1,3) data = {'data': im_tensor , 'im_info' : test_fake_numpy_data} print(data['im_info']) output = test_model(data)
print(output)
print(output['fcn_outputs'])
pallete = get_pallete() segmentation_result = np.uint8(np.squeeze(np.copy(output['fcn_outputs']))) segmentation_result = Image.fromarray(segmentation_result) segmentation_result.putpalette(pallete) segmentation_result = segmentation_result.resize((im.shape[1],im.shape[0])) segmentation_result.save("hello_result.png")`