Spaces:
Sleeping
Sleeping
alrichardbollans
commited on
Commit
·
efacbd3
1
Parent(s):
ae2089c
Fix TypeError: can't convert cuda:0 device type tensor to numpy issue
Browse files
python_utils/get_model.py
CHANGED
|
@@ -48,8 +48,10 @@ def load_model(using_final_model: bool = True):
|
|
| 48 |
cfg.merge_from_file(tmp.name)
|
| 49 |
if not torch.cuda.is_available():
|
| 50 |
cfg.MODEL.DEVICE = "cpu"
|
|
|
|
| 51 |
else:
|
| 52 |
cfg.MODEL.DEVICE = 'cuda'
|
|
|
|
| 53 |
|
| 54 |
if using_final_model:
|
| 55 |
## when rerouting to use the final model (final_tz_segmentor) USE_FED_LOSS has to be set to False
|
|
@@ -123,7 +125,9 @@ def apply_nms(prediction, mask=False, cls_agnostic_nms=OPTIMAL_NMS_THRESHOLD):
|
|
| 123 |
from detectron2.structures import Instances
|
| 124 |
print(f'applying nms with threshold {cls_agnostic_nms} and mask {mask}... \n')
|
| 125 |
if mask:
|
| 126 |
-
|
|
|
|
|
|
|
| 127 |
prediction["instances"]._fields["scores"], cls_agnostic_nms)
|
| 128 |
else:
|
| 129 |
nms_indices = nms(prediction["instances"].pred_boxes.tensor,
|
|
|
|
| 48 |
cfg.merge_from_file(tmp.name)
|
| 49 |
if not torch.cuda.is_available():
|
| 50 |
cfg.MODEL.DEVICE = "cpu"
|
| 51 |
+
print('No GPU available, using CPU')
|
| 52 |
else:
|
| 53 |
cfg.MODEL.DEVICE = 'cuda'
|
| 54 |
+
print('Using GPU')
|
| 55 |
|
| 56 |
if using_final_model:
|
| 57 |
## when rerouting to use the final model (final_tz_segmentor) USE_FED_LOSS has to be set to False
|
|
|
|
| 125 |
from detectron2.structures import Instances
|
| 126 |
print(f'applying nms with threshold {cls_agnostic_nms} and mask {mask}... \n')
|
| 127 |
if mask:
|
| 128 |
+
# print(prediction["instances"].pred_masks)
|
| 129 |
+
# print(prediction["instances"].pred_masks.cpu())
|
| 130 |
+
nms_indices = mask_nms(prediction["instances"].pred_masks.cpu().numpy(),
|
| 131 |
prediction["instances"]._fields["scores"], cls_agnostic_nms)
|
| 132 |
else:
|
| 133 |
nms_indices = nms(prediction["instances"].pred_boxes.tensor,
|