deep_sort_pytorch icon indicating copy to clipboard operation
deep_sort_pytorch copied to clipboard

timecost of image preprocessing(incluse resize) in detector.py is high

Open jishanshanss opened this issue 4 years ago • 7 comments

original code :

img = ori_img.astype(np.float)/255.
img = cv2.resize(img, self.size)
img = torch.from_numpy(img).float().permute(2,0,1).unsqueeze(0)
img = img.to(self.device)
with torch.no_grad():
            out_boxes = self.net(img)

I suggest using:

from PIL import Image
from torch.utils.data import DataLoader
from torchvision import datasets, transforms
from torch.autograd import Variable

img = Image.fromarray(ori_img)
img_transforms=transforms.Compose([transforms.Resize((self.size)),
            transforms.ToTensor(),
            ])
Tensor = torch.cuda.FloatTensor
image_tensor = img_transforms(img).float()
image_tensor = image_tensor.unsqueeze_(0)
img = Variable(image_tensor.type(Tensor)) 
with torch.no_grad():
            out_boxes = self.net(img)

the test speed will be faster :

resized = cv2.resize(ori_img, self.size, interpolation=cv2.INTER_LINEAR) img_in = np.transpose(resized, (2, 0, 1)).astype(np.float32) img_in = np.expand_dims(img_in, axis=0) img_in /= 255.0 img_in = np.ascontiguousarray(img_in) Tensor = torch.cuda.FloatTensor img = Variable(torch.tensor(img_in).to(self.device))

jishanshanss avatar Apr 26 '20 09:04 jishanshanss

wow, It works! My detector speed increased by 20%! excellent! Another question, what's your utilization rate of the GPU? Mine is only 1%, what can I do to improve it? Or is there anything wrong during my installation?

pauli-lab avatar Apr 27 '20 03:04 pauli-lab

sorry , I don't know much about it try to use this command :watch -n0.05 nvidia-smi
to watch your device, it changes every time, hope it works

jishanshanss avatar Apr 27 '20 07:04 jishanshanss

can you tell me your fps? my fps is just 8 or 9.

DerekSunYH avatar May 28 '20 12:05 DerekSunYH

can you tell me your fps? my fps is just 8 or 9.

mine is just 9-11, also not very high.Maybe that is because my GPU is poor

pauli-lab avatar May 28 '20 12:05 pauli-lab

my gpu 1080ti. how about yours?

DerekSunYH avatar May 28 '20 12:05 DerekSunYH

mine is 1050, but the number of the object in my video is small, about 25--35. What about yours?

pauli-lab avatar May 28 '20 12:05 pauli-lab

much the same! I don't know why my fps is so low

DerekSunYH avatar May 28 '20 12:05 DerekSunYH