Daankular commited on
Commit
cf35ba7
·
verified ·
1 Parent(s): cb5743a

Fix device mismatch: maskrcnn detector lands on cuda under mmgps lingering default device, but torch.from_numpy() input stays on cpu

Browse files
Files changed (1) hide show
  1. lib/pymaf/utils/imutils.py +6 -1
lib/pymaf/utils/imutils.py CHANGED
@@ -115,8 +115,13 @@ def process_image(img_file,
115
  # detection for bbox
116
  detector = detection.maskrcnn_resnet50_fpn(pretrained=True)
117
  detector.eval()
 
 
 
 
 
118
  predictions = detector(
119
- [torch.from_numpy(img_for_crop).permute(2, 0, 1) / 255.])[0]
120
  human_ids = torch.logical_and(
121
  predictions["labels"] == 1,
122
  predictions["scores"] == predictions["scores"].max()).nonzero().squeeze(1)
 
115
  # detection for bbox
116
  detector = detection.maskrcnn_resnet50_fpn(pretrained=True)
117
  detector.eval()
118
+ # Under mmgp'''s lingering torch.set_default_device('''cuda'''), this freshly-constructed
119
+ # detector'''s weights land on GPU automatically, but torch.from_numpy() always returns
120
+ # a CPU tensor (it shares memory with the numpy buffer). Match the input to wherever
121
+ # the detector actually ended up instead of assuming either device.
122
+ detector_device = next(detector.parameters()).device
123
  predictions = detector(
124
+ [(torch.from_numpy(img_for_crop).permute(2, 0, 1) / 255.).to(detector_device)])[0]
125
  human_ids = torch.logical_and(
126
  predictions["labels"] == 1,
127
  predictions["scores"] == predictions["scores"].max()).nonzero().squeeze(1)