Cutie
Cutie copied to clipboard
When test Cuda out of Mem
Code : ———————————————————————————— from cutie.utils.get_default_model import get_default_model from cutie.inference.inference_core import InferenceCore import torch import os os.environ['CUDA_VISIBLE_DEVICES']='0' from PIL import Image import numpy as np from torchvision import transforms
def main():
cutie = get_default_model()
processor = InferenceCore(cutie, cfg=cutie.cfg)
image_path = r'TestDataset\JPEGImages\20231214113655970'
images = sorted(os.listdir(image_path)) # ordering is important
mask = Image.open(r'TestDataset\Annotations\20231214113655970\frame_000000.png')
palette = mask.getpalette()
objects = np.unique(np.array(mask))
objects = objects[objects != 0].tolist() # background "0" does not count as an object
mask = torch.from_numpy(np.array(mask)).cuda()
for ti, image_name in enumerate(images):
image = Image.open(os.path.join(image_path, image_name))
image = transforms.ToTensor()(image).cuda().float()
if ti == 0:
output_prob = processor.step(image, mask, objects=objects)
else:
output_prob = processor.step(image)
# convert output probabilities to an object mask
mask = processor.output_prob_to_mask(output_prob)
# visualize prediction
output_dir = image_path.replace('JPEGImages','output')
output_path = os.path.join(image_path, image_name).replace('JPEGImages','output').replace('.jpg','.png')
if not os.path.exists(output_dir):
os.makedirs(output_dir)
mask = Image.fromarray(mask.cpu().numpy().astype(np.uint8))
mask.putpalette(palette)
mask.save(output_path) # or use mask.save(...) to save it somewhere
main() ———————————Code end—————————————
We get :
————————————————————————————
Traceback (most recent call last):
File "d:/WorkShopU/WorkShop/DetactionDsitance/main-Cutie/Test.py", line 47, in
————————————————————————————
Q:
dear rex is any mistakes in my code or my devices ? i just can't run this inference demo.
Resize input mitigates this problem, but it still doesn't complete the reasoning
What's the input? Number of objects/resolution?
JPG 2 objects. resolution:1024*648. i only got 8 mask png when OutOfMemoryError happen. sincely waitting for solution.
That shouldn't happen. I am speculating but are you sure that there are only 8 objects? Sometimes people interpolate the masks and it creates a lot of new unique values (i.e., objects).
Another note is that you are missing
@torch.inference_mode()
@torch.cuda.amp.autocast()
which are present in our demo.