ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.34k stars 16.25k forks source link

torchvision: Couldn't load custom C++ ops #5511

Closed NB-wo closed 2 years ago

NB-wo commented 2 years ago

Search before asking

Question

Hi, I had this problem when i upgraded pytorch from version 1.9 to 1.10. The version of torchvision is 0.11.1.(Running detect.py v6.0) The full error information is as follows:RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.version and your torchvision version with torchvision.version and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.

How can i solve this problem?

Additional

No response

github-actions[bot] commented 2 years ago

👋 Hello @NB-wo, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

Zengyf-CVer commented 2 years ago

@NB-wo Since you upgraded the version, the old version still exists. The new version just overwrites the old version, but it is not uninstalled. You now uninstall all pytorch cleanly, make sure there is no torch and torchvision in the virtual environment, and then reinstall it. Also clear the cache in conda: /home/***/.cache/pip

NB-wo commented 2 years ago

@Zengyf-CVer Thanks for your reply!But I'm not using conda, and i deleted the entire virtual environment.It still doesn't work.

github-actions[bot] commented 2 years ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

echosalik commented 2 years ago

@NB-wo did you find any solution?

NB-wo commented 2 years ago

@NB-wo did you find any solution? downgrade my Python(3.10) to 3.9😹

mattiasstahre commented 2 years ago

I have a similar issue here:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/Users/mattias/git/layout parser/layout-parser/examples/Deep Layout Parsing.ipynb Cell 7' in <module>
----> [1]()[ layout = model.detect(image)

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/layoutparser/models/layoutmodel.py:167, in Detectron2LayoutModel.detect(self, image)
    ]()[164]()[         image = image.convert("RGB")
    ]()[165]()[     image = np.array(image)
--> ]()[167]()[ outputs = self.model(image)
    ]()[168]()[ layout = self.gather_output(outputs)
    ]()[169]()[ return layout

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/detectron2/engine/defaults.py:317, in DefaultPredictor.__call__(self, original_image)
    ]()[314]()[ image = torch.as_tensor(image.astype("float32").transpose(2, 0, 1))
    ]()[316]()[ inputs = {"image": image, "height": height, "width": width}
--> ]()[317]()[ predictions = self.model([inputs])[0]
    ]()[318]()[ return predictions

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/torch/nn/modules/module.py:1102, in Module._call_impl(self, *input, **kwargs)
   ]()[1098]()[ # If we don't have any hooks, we want to skip the rest of the logic in
   ]()[1099]()[ # this function, and just call forward.
   ]()[1100]()[ if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   ]()[1101]()[         or _global_forward_hooks or _global_forward_pre_hooks):
-> ]()[1102]()[     return forward_call(*input, **kwargs)
   ]()[1103]()[ # Do not call functions when jit is used
   ]()[1104]()[ full_backward_hooks, non_full_backward_hooks = [], []

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/detectron2/modeling/meta_arch/rcnn.py:146, in GeneralizedRCNN.forward(self, batched_inputs)
    ]()[123]()[ """
    ]()[124]()[ Args:
    ]()[125]()[     batched_inputs: a list, batched outputs of :class:`DatasetMapper` .
   (...)
    ]()[143]()[         "pred_boxes", "pred_classes", "scores", "pred_masks", "pred_keypoints"
    ]()[144]()[ """
    ]()[145]()[ if not self.training:
--> ]()[146]()[     return self.inference(batched_inputs)
    ]()[148]()[ images = self.preprocess_image(batched_inputs)
    ]()[149]()[ if "instances" in batched_inputs[0]:

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/detectron2/modeling/meta_arch/rcnn.py:204, in GeneralizedRCNN.inference(self, batched_inputs, detected_instances, do_postprocess)
    ]()[202]()[ if detected_instances is None:
    ]()[203]()[     if self.proposal_generator is not None:
--> ]()[204]()[         proposals, _ = self.proposal_generator(images, features, None)
    ]()[205]()[     else:
    ]()[206]()[         assert "proposals" in batched_inputs[0]

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/torch/nn/modules/module.py:1102, in Module._call_impl(self, *input, **kwargs)
   ]()[1098]()[ # If we don't have any hooks, we want to skip the rest of the logic in
   ]()[1099]()[ # this function, and just call forward.
   ]()[1100]()[ if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   ]()[1101]()[         or _global_forward_hooks or _global_forward_pre_hooks):
-> ]()[1102]()[     return forward_call(*input, **kwargs)
   ]()[1103]()[ # Do not call functions when jit is used
   ]()[1104]()[ full_backward_hooks, non_full_backward_hooks = [], []

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/detectron2/modeling/proposal_generator/rpn.py:477, in RPN.forward(self, images, features, gt_instances)
    ]()[475]()[ else:
    ]()[476]()[     losses = {}
--> ]()[477]()[ proposals = self.predict_proposals(
    ]()[478]()[     anchors, pred_objectness_logits, pred_anchor_deltas, images.image_sizes
    ]()[479]()[ )
    ]()[480]()[ return proposals, losses

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/detectron2/modeling/proposal_generator/rpn.py:503, in RPN.predict_proposals(self, anchors, pred_objectness_logits, pred_anchor_deltas, image_sizes)
    ]()[501]()[ with torch.no_grad():
    ]()[502]()[     pred_proposals = self._decode_proposals(anchors, pred_anchor_deltas)
--> ]()[503]()[     return find_top_rpn_proposals(
    ]()[504]()[         pred_proposals,
    ]()[505]()[         pred_objectness_logits,
    ]()[506]()[         image_sizes,
    ]()[507]()[         self.nms_thresh,
    ]()[508]()[         self.pre_nms_topk[self.training],
    ]()[509]()[         self.post_nms_topk[self.training],
    ]()[510]()[         self.min_box_size,
    ]()[511]()[         self.training,
    ]()[512]()[     )

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/detectron2/modeling/proposal_generator/proposal_utils.py:112, in find_top_rpn_proposals(proposals, pred_objectness_logits, image_sizes, nms_thresh, pre_nms_topk, post_nms_topk, min_box_size, training)
    ]()[109]()[ if _is_tracing() or keep.sum().item() != len(boxes):
    ]()[110]()[     boxes, scores_per_img, lvl = boxes[keep], scores_per_img[keep], lvl[keep]
--> ]()[112]()[ keep = batched_nms(boxes.tensor, scores_per_img, lvl, nms_thresh)
    ]()[113]()[ # In Detectron1, there was different behavior during training vs. testing.
    ]()[114]()[ # (https://github.com/facebookresearch/Detectron/issues/459)
    ]()[115]()[ # During training, topk is over the proposals from *all* images in the training batch.
   (...)
    ]()[118]()[ # and the configuration "POST_NMS_TOPK_TRAIN" end up relying on the batch size.
    ]()[119]()[ # This bug is addressed in Detectron2 to make the behavior independent of batch size.
    ]()[120]()[ keep = keep[:post_nms_topk]  # keep is already sorted

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/detectron2/layers/nms.py:20, in batched_nms(boxes, scores, idxs, iou_threshold)
     ]()[15]()[ assert boxes.shape[-1] == 4
     ]()[16]()[ # Note: Torchvision already has a strategy (https://github.com/pytorch/vision/issues/1311)
     ]()[17]()[ # to decide whether to use coordinate trick or for loop to implement batched_nms. So we
     ]()[18]()[ # just call it directly.
     ]()[19]()[ # Fp16 does not have enough range for batched NMS, so adding float().
---> ]()[20]()[ return box_ops.batched_nms(boxes.float(), scores, idxs, iou_threshold)

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/torchvision/ops/boxes.py:66, in batched_nms(boxes, scores, idxs, iou_threshold)
     ]()[62]()[ # Benchmarks that drove the following thresholds are at
     ]()[63]()[ # https://github.com/pytorch/vision/issues/1311#issuecomment-781329339
     ]()[64]()[ # Ideally for GPU we'd use a higher threshold
     ]()[65]()[ if boxes.numel() > 4_000 and not torchvision._is_tracing():
---> ]()[66]()[     return _batched_nms_vanilla(boxes, scores, idxs, iou_threshold)
     ]()[67]()[ else:
     ]()[68]()[     return _batched_nms_coordinate_trick(boxes, scores, idxs, iou_threshold)

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/torch/jit/_trace.py:1118, in _script_if_tracing.<locals>.wrapper(*args, **kwargs)
   ]()[1114]()[ @functools.wraps(fn)
   ]()[1115]()[ def wrapper(*args, **kwargs):
   ]()[1116]()[     if not is_tracing():
   ]()[1117]()[         # Not tracing, don't do anything
-> ]()[1118]()[         return fn(*args, **kwargs)
   ]()[1120]()[     compiled_fn = script(wrapper.__original_fn)  # type: ignore[attr-defined]
   ]()[1121]()[     return compiled_fn(*args, **kwargs)

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/torchvision/ops/boxes.py:102, in _batched_nms_vanilla(boxes, scores, idxs, iou_threshold)
    ]()[100]()[ for class_id in torch.unique(idxs):
    ]()[101]()[     curr_indices = torch.where(idxs == class_id)[0]
--> ]()[102]()[     curr_keep_indices = nms(boxes[curr_indices], scores[curr_indices], iou_threshold)
    ]()[103]()[     keep_mask[curr_indices[curr_keep_indices]] = True
    ]()[104]()[ keep_indices = torch.where(keep_mask)[0]

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/torchvision/ops/boxes.py:34, in nms(boxes, scores, iou_threshold)
      ]()[9]()[ def nms(boxes: Tensor, scores: Tensor, iou_threshold: float) -> Tensor:
     ]()[10]()[     """
     ]()[11]()[     Performs non-maximum suppression (NMS) on the boxes according
     ]()[12]()[     to their intersection-over-union (IoU).
   (...)
     ]()[32]()[         by NMS, sorted in decreasing order of scores
     ]()[33]()[     """
---> ]()[34]()[     _assert_has_ops()
     ]()[35]()[     return torch.ops.torchvision.nms(boxes, scores, iou_threshold)

File ~/.pyenv/versions/3.8.12/lib/python3.8/site-packages/torchvision/extension.py:31, in _assert_has_ops()
     ]()[29]()[ def _assert_has_ops():
     ]()[30]()[     if not _has_ops():
---> ]()[31]()[         raise RuntimeError(
     ]()[32]()[             "Couldn't load custom C++ ops. This can happen if your PyTorch and "
     ]()[33]()[             "torchvision versions are incompatible, or if you had errors while compiling "
     ]()[34]()[             "torchvision from source. For further information on the compatible versions, check "
     ]()[35]()[             "https://github.com/pytorch/vision#installation for the compatibility matrix. "
     ]()[36]()[             "Please check your PyTorch version with torch.__version__ and your torchvision "
     ]()[37]()[             "version with torchvision.__version__ and verify if they are compatible, and if not "
     ]()[38]()[             "please reinstall torchvision so that it matches your PyTorch install."
     ]()[39]()[         )

RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.__version__ and your torchvision version with torchvision.__version__ and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.]()

Have tried different versions of all packages but still not working..

HuShifang commented 2 years ago

I was having the same error message. FWIW, I resolved it by installing the latest build of torchvision from the Anaconda pytorch channel in a fresh environment rather than relying on the requirements.txt specification. pip was installing an older torchvision version which wasn't compatible with my Anaconda-installed v1.10.2 PyTorch build.

PWZER commented 2 years ago

I have the same problem,Install the torch and TorchVision packages with the same CUDA version from https://download.pytorch.org/whl/ and then it work.

awsankur commented 2 years ago

I get the same error. My torchvision version is 11.1 and torch version is 1.10. These are compatible with each other but I still get the error below.

RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.version and your torchvision version with torchvision.version and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.

LearningHarder commented 2 years ago

I have the same problem,Install the torch and TorchVision packages with the same CUDA version from https://download.pytorch.org/whl/ and then it work.

thank you very much!

tothedistance commented 2 years ago

I use conda create --file requirement.txt to install, conda installs cpu pytorch and torchvision with cuda build. change it to pytorch-mutex

Nineyoyoyo commented 2 years ago

I reinstall torchvision and change it's version from 0.12.0+cu113 to only 0.12.0 and it works (I dunno why it's version is followed by "+cu113" tho)

methmal1997 commented 2 years ago

@Nineyoyoyo How did you do that? Can you please share your code?

e101sg commented 1 year ago

conda install -c pytorch torchvision (v0.14.1) solved the issue on Jan 2023. Hope this helps.

peiyiniu commented 1 year ago

I got exactly the same error when I run a jupyter notebook cells in VS Code in wsl ubuntu 22.04. The error came out when I call this function: i = torchvision.ops.nms(boxes, scores, iou_thres). I uninstall - reinstall torch and torchvision for two times and make sure their versions are compatible with each other (see here for their Compatability: https://github.com/pytorch/vision#installation). But all didn't work. I finally found that the two inputs to this function (boxes and scores) are tensors of device(type='cpu') in fact. I then check to see what the returned value is from the cell with torch.cuda.is_available(). The returned value is False. I use the same way from a terminal to check the returned, and it gives True, which means that jupyter somehow couldn't see cuda within VS Code. I googled and found a way to resolve this issue here: https://stackoverflow.com/questions/74183243/cuda-is-available-false-on-vscode-ipynb-but-true-on-jupyterlab, then followed it and the error disappeared.

gisingkim commented 1 year ago

pip3 list => torch - 1.9.0 , torch - 0.10.0 : old version => fail pip install --upgrade torch pip install --upgrade torchvision pip3 list => torch - 2.0.1 , torch - 0.11.2 : new version => success

glenn-jocher commented 1 year ago

@gisingkim hi there,

It seems that you were able to resolve the issue by upgrading the torch and torchvision packages to newer versions. Sometimes, using older versions of these packages can cause compatibility issues.

If you encounter similar issues in the future, I would recommend upgrading both torch and torchvision packages to the latest versions available. This ensures that they are compatible with each other and with your specific setup.

Please let us know if you have any further questions or issues.

Thank you! Glenn Jocher

pioneerRick commented 1 year ago

Your torch and and torchvision version too high,you should back your version.

glenn-jocher commented 1 year ago

@pioneerRick thanks for reaching out and bringing up the issue. While it's true that using incompatible versions of torch and torchvision can cause problems, it's important to ensure that your versions are compatible with each other and with the YOLOv5 codebase.

Make sure to check the compatibility matrix provided by the torchvision repository to ensure that your versions are supported. If you encounter any issues, please consider downgrading or upgrading the versions of torch and torchvision accordingly.

Feel free to provide more specific details about your setup or any specific error messages you are seeing, and we will be happy to help you further.

Thanks, Glenn Jocher

makarbaderko commented 10 months ago

Running pip3 install torch torchvision --upgrade has fixed the problem for me.

glenn-jocher commented 10 months ago

@makarbaderko great to hear that! If you encounter any further issues or have more questions, feel free to ask. Happy coding!

xingguangYan commented 7 months ago

How to solve this problem?


RuntimeError Traceback (most recent call last) Cell In[14], line 2 1 mask = "segment.tif" ----> 2 sam.generate( 3 image, mask, batch=True, foreground=True, erosion_kernel=(3, 3), mask_multiplier=255 4 )

File ~\miniconda3\envs\geo\Lib\site-packages\samgeo\samgeo.py:188, in SamGeo.generate(self, source, output, foreground, batch, erosion_kernel, mask_multiplier, unique, kwargs) 186 self.source = source 187 self.masks = output --> 188 return tiff_to_tiff( 189 source, 190 output, 191 self, 192 foreground=foreground, 193 erosion_kernel=erosion_kernel, 194 mask_multiplier=mask_multiplier, 195 kwargs, 196 ) 198 image = cv2.imread(source) 199 image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

File ~\miniconda3\envs\geo\Lib\site-packages\samgeo\common.py:1142, in tiff_to_tiff(src_fp, dst_fp, func, data_to_rgb, sample_size, sample_resize, bound, foreground, erosion_kernel, mask_multiplier, kwargs) 1137 uint8_rgb_in = cv2.resize( 1138 uint8_rgb_in, resize_hw, interpolation=cv2.INTER_LINEAR 1139 ) 1141 # Run the model, call the call method of SamGeo class -> 1142 uin8_out = func( 1143 uint8_rgb_in, 1144 foreground=foreground, 1145 erosion_kernel=erosion_kernel, 1146 mask_multiplier=mask_multiplier, 1147 kwargs, 1148 ) 1150 if resize_hw is not None: 1151 uin8_out = cv2.resize( 1152 uin8_out, orig_size, interpolation=cv2.INTER_NEAREST 1153 )

File ~\miniconda3\envs\geo\Lib\site-packages\samgeo\samgeo.py:125, in SamGeo.call(self, image, foreground, erosion_kernel, maskmultiplier, **kwargs) 113 """Generate masks for the input tile. This function originates from the segment-anything-eo repository. 114 See https://bit.ly/41pwiHw 115 (...) 121 You can use this parameter to scale the mask to a larger range, for example [0, 255]. Defaults to 255. 122 """ 123 h, w, = image.shape --> 125 masks = self.mask_generator.generate(image) 127 if foreground: # Extract foreground objects only 128 resulting_mask = np.zeros((h, w), dtype=np.uint8)

File ~\miniconda3\envs\geo\Lib\site-packages\torch\utils_contextlib.py:115, in context_decorator..decorate_context(*args, kwargs) 112 @functools.wraps(func) 113 def decorate_context(*args, *kwargs): 114 with ctx_factory(): --> 115 return func(args, kwargs)

File ~\miniconda3\envs\geo\Lib\site-packages\segment_anything\automatic_mask_generator.py:163, in SamAutomaticMaskGenerator.generate(self, image) 138 """ 139 Generates masks for the given image. 140 (...) 159 the mask, given in XYWH format. 160 """ 162 # Generate masks --> 163 mask_data = self._generate_masks(image) 165 # Filter small disconnected regions and holes in masks 166 if self.min_mask_region_area > 0:

File ~\miniconda3\envs\geo\Lib\site-packages\segment_anything\automatic_mask_generator.py:206, in SamAutomaticMaskGenerator._generate_masks(self, image) 204 data = MaskData() 205 for crop_box, layer_idx in zip(crop_boxes, layer_idxs): --> 206 crop_data = self._process_crop(image, crop_box, layer_idx, orig_size) 207 data.cat(crop_data) 209 # Remove duplicate masks between crops

File ~\miniconda3\envs\geo\Lib\site-packages\segment_anything\automatic_mask_generator.py:251, in SamAutomaticMaskGenerator._process_crop(self, image, crop_box, crop_layer_idx, orig_size) 248 self.predictor.reset_image() 250 # Remove duplicates within this crop. --> 251 keep_by_nms = batched_nms( 252 data["boxes"].float(), 253 data["iou_preds"], 254 torch.zeros_like(data["boxes"][:, 0]), # categories 255 iou_threshold=self.box_nms_thresh, 256 ) 257 data.filter(keep_by_nms) 259 # Return to the original image frame

File ~\miniconda3\envs\geo\Lib\site-packages\torchvision\ops\boxes.py:73, in batched_nms(boxes, scores, idxs, iou_threshold) 70 # Benchmarks that drove the following thresholds are at 71 # https://github.com/pytorch/vision/issues/1311#issuecomment-781329339 72 if boxes.numel() > (4000 if boxes.device.type == "cpu" else 20000) and not torchvision._is_tracing(): ---> 73 return _batched_nms_vanilla(boxes, scores, idxs, iou_threshold) 74 else: 75 return _batched_nms_coordinate_trick(boxes, scores, idxs, iou_threshold)

File ~\miniconda3\envs\geo\Lib\site-packages\torch\jit_trace.py:1240, in _script_if_tracing..wrapper(*args, kwargs) 1236 @functools.wraps(fn) 1237 def wrapper(*args: P.args, *kwargs: P.kwargs) -> R: 1238 if not is_tracing(): 1239 # Not tracing, don't do anything -> 1240 return fn(args, kwargs) 1242 compiled_fn: Callable[P, R] = script(wrapper.__original_fn) # type: ignore[attr-defined] 1243 return compiled_fn(*args, **kwargs)

File ~\miniconda3\envs\geo\Lib\site-packages\torchvision\ops\boxes.py:109, in _batched_nms_vanilla(boxes, scores, idxs, iou_threshold) 107 for class_id in torch.unique(idxs): 108 curr_indices = torch.where(idxs == class_id)[0] --> 109 curr_keep_indices = nms(boxes[curr_indices], scores[curr_indices], iou_threshold) 110 keep_mask[curr_indices[curr_keep_indices]] = True 111 keep_indices = torch.where(keep_mask)[0]

File ~\miniconda3\envs\geo\Lib\site-packages\torchvision\ops\boxes.py:40, in nms(boxes, scores, iou_threshold) 38 if not torch.jit.is_scripting() and not torch.jit.is_tracing(): 39 _log_api_usage_once(nms) ---> 40 _assert_has_ops() 41 return torch.ops.torchvision.nms(boxes, scores, iou_threshold)

File ~\miniconda3\envs\geo\Lib\site-packages\torchvision\extension.py:48, in _assert_has_ops() 46 def _assert_has_ops(): 47 if not _has_ops(): ---> 48 raise RuntimeError( 49 "Couldn't load custom C++ ops. This can happen if your PyTorch and " 50 "torchvision versions are incompatible, or if you had errors while compiling " 51 "torchvision from source. For further information on the compatible versions, check " 52 "https://github.com/pytorch/vision#installation for the compatibility matrix. " 53 "Please check your PyTorch version with torch.version and your torchvision " 54 "version with torchvision.version and verify if they are compatible, and if not " 55 "please reinstall torchvision so that it matches your PyTorch install." 56 )

RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.version and your torchvision version with torchvision.version and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.

glenn-jocher commented 5 months ago

Hi there! It looks like you're encountering a compatibility issue between PyTorch and torchvision. Here are a few steps to potentially resolve this:

  1. Check Versions: Ensure that your PyTorch and torchvision versions are compatible. You can check the versions using:

    import torch
    import torchvision
    print(torch.__version__, torchvision.__version__)
  2. Update/Reinstall: If the versions are not compatible, consider updating both packages:

    pip install torch torchvision --upgrade
  3. Environment Check: Since you're using a Jupyter notebook, ensure that the notebook is running in the correct environment where the libraries are installed.

  4. CUDA Availability: If you're using CUDA, check its availability in your notebook:

    print(torch.cuda.is_available())

If these steps don't resolve the issue, you might want to reinstall both libraries ensuring their compatibility. Let me know how it goes! 😊