Unsure about placement of non-maximum suppression (NMS) in code

I’m doing inference on a faster r-cnn model and have the following set up where I apply non-maximum suppression on some outputs (batch size is always 1):

model_test.eval()
with torch.no_grad():
     
   for images, targets in data_loader:
            images = list(img.to(device) for img in images)
            outputs = model_test(images)
            outputs = [{k: v.to(cpu_device) for k, v in t.items()} for t in outputs]
            predictions = apply_nms(outputs[0], iou_thresh=0.1)

However, I just wanted to be sure what this line of code is doing and why it is necessary during evaluation:

outputs = [{k: v.to(cpu_device) for k, v in t.items()} for t in outputs]

Can anyone provide me with a good explanation?

And finally is it ok for me to apply non-maximum suppression like how I have defined?

This seems to be moving data from cuda to cpu, which might be necessary to apply NMS.
Probably NMS routines are typically run on the CPU.

1 Like

tbh I applied NMS there and was wondering if it is the correct place to put it. It appears so from my results but I want to make sure it’s not a wrong placement

As far as I could understand, the placement of NMS seems correct.

1 Like