Closed Hanleon closed 3 years ago
I checked the code again, and found return ToTensor()(Image.fromarray(frame)).unsqueeze_(0).cuda()
this part is the key.
It's not used CUDA to run.
Then I checked CUDA and CUDNN on my environment.
Python 3.8.8 (default, Feb 24 2021, 15:54:32) [MSC v.1928 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
import torch
print(torch.cuda.is_available())
True
from torch.backends import cudnn
print(cudnn.is_available())
True
It's available.
Now I have no idea, please help me, Thx~
Soved it.
Just change
return ToTensor()(Image.fromarray(frame)).unsqueeze_(0).cuda()
to
return torch.as_tensor(frame, device=torch.device("cuda")).type(torch.cuda.FloatTensor).unsqueeze(0).permute(0, 3, 1, 2)/255
.
Hi: I tried to run "inference_webcam.py", but the CPU always at 100%(the CPU is 9700K). Then I tried to change resolution "1280x720" or "640x480", also not work. And at this part
res = res.mul(255).byte().cpu().permute(0, 2, 3, 1).numpy()[0]
, it's run by CPU. So, is it problem? And how can I fix it to run CUDA? Thx~~~