mikel-brostrom / boxmot

BoxMOT: pluggable SOTA tracking modules for segmentation, object detection and pose estimation models
GNU Affero General Public License v3.0
6.4k stars 1.68k forks source link

Run Strong Sort Tracker on GPU #1508

Closed BirenMer closed 1 week ago

BirenMer commented 2 weeks ago

Search before asking

Question

Below is my code for initializing a tracker strong sort or deep_oc_sort, also my problem is no matter what I do the code runs on my CPU insted of my GPU card (I have two GPU's in th system)


from pathlib import Path from boxmot import StrongSORT from boxmot import DeepOCSORT

def tracker_init(tracker_name:str='strong_sort',reid_model_path:str='models/osnet_x0_25_msmt17.pt',cuda_device:bool=True,cuda_device_number:int=0): """ Usage: Used to initialize trackers || Default=strong_sort Currently support two Trackers :

  1. strong_sort (default)
  2. deep_oc_sort Args :

    1. tracker_name(str) -> used to select a traker || Default = strong_sort
    2. reid_model_path(str) -> used to select a reid model || Defualt = osnet_x0_25_msmt17
    3. cuda_device(bool) -> Used to select between CPU and GPU for calculation || Default=GPU
    4. cuda_device_number(int) -> Used to select GPU device (If there exists multiple device) || Default = 0

    Returns : Returns a tracker object

    List of available reid model : ['resnet50', 'resnet101', 'mobilenetv2_x1_0', 'mobilenetv2_x1_4', 'hacnn', 'mlfn', 'osnet_x1_0', 'osnet_x0_75', 'osnet_x0_5', 'osnet_x0_25', 'osnet_ibn_x1_0', 'osnet_ain_x1_0', 'osnet_ain_x0_75', 'osnet_ain_x0_5', 'osnet_ain_x0_25', 'lmbn_n', 'clip'] """ tracker=None if tracker_name=='deep_oc_sort': tracker = DeepOCSORT( model_weights=Path(reid_model_path), # which ReID model to use device=f'cuda:{cuda_device_number}' if cuda_device else 'cpu', fp16=False, )

    else: tracker = StrongSORT( model_weights=Path(reid_model_path), # which ReID model to use device=f'cuda:{cuda_device_number}' if cuda_device else 'cpu', fp16=False, ) return tracker


Please let me know what I am doing wrong

mikel-brostrom commented 2 weeks ago

I cannot help you without more information. When CUDA is not available you will receive a message similar to this

ValueError: Invalid CUDA 'device=0' requested. Use 'device=cpu' or pass valid CUDA device(s) if available, i.e. 'device=0' or 'device=0,1,2,3' for Multi-GPU.

torch.cuda.is_available(): False
torch.cuda.device_count(): 0
os.environ['CUDA_VISIBLE_DEVICES']: None
See https://pytorch.org/get-started/locally/ for up-to-date torch install instructions if no CUDA devices are seen by torch.
BirenMer commented 1 week ago

I cannot help you without more information. When CUDA is not available you will receive a message similar to this

ValueError: Invalid CUDA 'device=0' requested. Use 'device=cpu' or pass valid CUDA device(s) if available, i.e. 'device=0' or 'device=0,1,2,3' for Multi-GPU.

torch.cuda.is_available(): False
torch.cuda.device_count(): 0
os.environ['CUDA_VISIBLE_DEVICES']: None
See https://pytorch.org/get-started/locally/ for up-to-date torch install instructions if no CUDA devices are seen by torch.

Sir I am actually getting no error messages, When I see my gpu usage while running the code they are near to zero and my cpu usage is sky rocketing, If I stop the tracking part and run only YOLO for detection then my CPU usage is normal.

So at this point I am also confused why it is happening.

mikel-brostrom commented 1 week ago

Try device=0