tfaehse / DashcamCleaner

Censor identifiable information in videos, in particular dashcam recordings in Germany.
GNU Affero General Public License v3.0
131 stars 27 forks source link

RuntimeError: Couldn't load custom C++ ops. #13

Open joshinils opened 2 years ago

joshinils commented 2 years ago
Blurrer started!
Worker started
Traceback (most recent call last):
  File "/home/niels/Documents/DashcamCleaner/dashcamcleaner/src/blurrer.py", line 158, in run
    new_detections = self.detect_identifiable_information(frame.copy())
  File "/home/niels/Documents/DashcamCleaner/dashcamcleaner/src/blurrer.py", line 97, in detect_identifiable_information
    results = self.detector(image, size=scale)
  File "/home/niels/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/niels/.local/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/niels/.cache/torch/hub/ultralytics_yolov5_master/models/common.py", line 606, in forward
    y = non_max_suppression(y if self.dmb else y[0],
  File "/home/niels/.cache/torch/hub/ultralytics_yolov5_master/utils/general.py", line 859, in non_max_suppression
    i = torchvision.ops.nms(boxes, scores, iou_thres)  # NMS
  File "/home/niels/.local/lib/python3.8/site-packages/torchvision/ops/boxes.py", line 35, in nms
    _assert_has_ops()
  File "/home/niels/.local/lib/python3.8/site-packages/torchvision/extension.py", line 62, in _assert_has_ops
    raise RuntimeError(
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.
./main.py:193: DeprecationWarning: 'exec_' will be removed in the future. Use 'exec' instead.
  msg_box.exec_()

sry, this is running my fork, so line numbers may be wrong

joshinils commented 2 years ago

trying to run with the main.py gui (after adding a shebang...)

tfaehse commented 2 years ago

No worries about the line numbers :) Looks like a dependency issue, have you verified that your PyTorch and torch vision versions are compatible? With pip list you can list your installed packages, pytorch and torchvision should match here: https://github.com/pytorch/vision#installation

To make sure it's not a dependency issue, you can create a new python environment (I use conda, but venv works too) and install only the listed dependencies, in your case

pip install -r requirements.txt

Then please launch main.py using this python version, not your system's main one.

joshinils commented 2 years ago

no, pip3 tells me i have these installed:

➜  ~ pip3 list|grep torch
torch                    1.8.1+cu111
torchaudio               0.8.1
torchvision              0.9.1

and i am using python v 3.8.10

joshinils commented 2 years ago

I tried a fresh environment with conda and python3.9. — that worked.

trying to install manually for python3.9 results in mismatched torch, torchvision, torchaudio versions since you have a ">=" in the requirements.txt files and it chooses a bigger version which is not compatible.

after installing the correct and compatioble versions for torch==1.8.1 and running main.py with pythooon3.9 i get:

➜  ~ python3.9 ~/Documents/DashcamCleaner/dashcamcleaner/main.py
Using cache found in /home/niels/.cache/torch/hub/ultralytics_yolov5_master
Traceback (most recent call last):
  File "/home/niels/Documents/DashcamCleaner/dashcamcleaner/main.py", line 248, in <module>
    window = MainWindow()
  File "/home/niels/Documents/DashcamCleaner/dashcamcleaner/main.py", line 33, in __init__
    self.load_weights_options()
  File "/home/niels/Documents/DashcamCleaner/dashcamcleaner/main.py", line 45, in load_weights_options
    self.setup_blurrer()
  File "/home/niels/Documents/DashcamCleaner/dashcamcleaner/main.py", line 52, in setup_blurrer
    self.blurrer = VideoBlurrer(weights_name)
  File "/home/niels/Documents/DashcamCleaner/dashcamcleaner/src/blurrer.py", line 29, in __init__
    self.detector = setup_detector(weights_path)
  File "/home/niels/Documents/DashcamCleaner/dashcamcleaner/src/blurrer.py", line 220, in setup_detector
    model = torch.hub.load("ultralytics/yolov5", "custom", weights_path)
  File "/home/niels/.local/lib/python3.9/site-packages/torch/hub.py", line 339, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "/home/niels/.local/lib/python3.9/site-packages/torch/hub.py", line 368, in _load_local
    model = entry(*args, **kwargs)
  File "/home/niels/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 71, in custom
    return _create(path, autoshape=autoshape, verbose=_verbose, device=device)
  File "/home/niels/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 31, in _create
    from models.common import AutoShape, DetectMultiBackend
  File "/home/niels/.cache/torch/hub/ultralytics_yolov5_master/models/common.py", line 24, in <module>
    from utils.dataloaders import exif_transpose, letterbox
  File "/home/niels/.cache/torch/hub/ultralytics_yolov5_master/utils/dataloaders.py", line 29, in <module>
    from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
  File "/home/niels/.cache/torch/hub/ultralytics_yolov5_master/utils/augmentations.py", line 12, in <module>
    from utils.general import LOGGER, check_version, colorstr, resample_segments, segment2box
  File "/home/niels/.cache/torch/hub/ultralytics_yolov5_master/utils/general.py", line 37, in <module>
    from utils.metrics import box_iou, fitness
  File "/home/niels/.cache/torch/hub/ultralytics_yolov5_master/utils/metrics.py", line 10, in <module>
    import matplotlib.pyplot as plt
  File "/home/niels/.local/lib/python3.9/site-packages/matplotlib/__init__.py", line 208, in <module>
    _check_versions()
  File "/home/niels/.local/lib/python3.9/site-packages/matplotlib/__init__.py", line 202, in _check_versions
    module = importlib.import_module(modname)
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'kiwisolver'

but kiwisolver is installed ?!:

➜  ~ python3.9 -m pip show kiwisolver                    
Name: kiwisolver
Version: 1.0.1
Summary: A fast implementation of the Cassowary constraint solver
Home-page: https://github.com/nucleic/kiwi
Author: The Nucleic Development Team
Author-email: sccolbert@gmail.com
License: UNKNOWN
Location: /usr/lib/python3/dist-packages
Requires: 
Required-by: matplotlib
tfaehse commented 2 years ago

Huh, that is weird. Good point for the requirements, looks like I have to set a fixed version for torchvision too - I must've missed that. While on that we can also finally update to newer torch versions in general, there don't seem to be any compatibility issues.

I've never had that kiwi solver issue (I didn't even know it was installed...), but it unfortunately seems to be common and can supposedly fixed by just reinstalling it: https://stackoverflow.com/questions/49522502/macos-python-modulenotfounderror-no-module-named-kiwisolver https://github.com/nucleic/kiwi/issues/68

joshinils commented 2 years ago

ah, ok i reinstalled kiwisolver (which did not work using python3.9 -m pip, i had to use the 3.8 pip)

but now i have the same issue as before, but it runs for 25% of the file, only then does it raise the RuntimeError...

i looked at the intermediary *_copy.mkv file, it contains everything which does not need blurring. so i guess the first frame which needs to be blurred results in the error.

i'll try update both torch and torchvision for various compatible versions and update this comment which versions work for me.

torch torchvision python works
1.8.1+cu111 0.9.1 3.8.10 until first frame to be blurred
1.8.1+cu111 0.9.1 3.9 no, even fewer frames
1.9.0 0.10.0 3.8.10 yes, 2 frames visible license plate
1.9.0 0.10.0 3.9 yes, same 2 frames visible license plate
1.9.1 0.10.1 3.8.10 yes, same 2 frames visible license plate
1.9.1 0.10.1 3.9 yes, same 2 frames visible license plate
1.10.0 0.11.1 3.8.10 yes, same 2 frames visible license plate
1.10.0 0.11.1 3.9 yes, same 2 frames visible license plate
1.10.1 0.11.2 3.8.10 yes, same 2 frames visible license plate
1.10.1 0.11.2 3.9 yes, same 2 frames visible license plate
1.10.2 0.11.3 3.8.10 yes, same 2 frames visible license plate
1.10.2 0.11.3 3.9 yes, same 2 frames visible license plate
tfaehse commented 2 years ago

Just in case it helps, I'm currently running Python 3.10.5 with

Oh, and feel free to git pull, there've been a few changes! In case torch complains and won't load the weights file you might have to force a reload, it created a cache in your user folder (~/.cache/torch/hub...) that might need deletion.

joshinils commented 2 years ago

Just in case it helps, I'm currently running Python 3.10.5

i dont think i will use py3.10, since the default on 20.04.4 LTS (Focal Fossa) is 3.8 and even using 3.9 takes effort to alyways install packages for and run with... and i think 3.10 doesnt even work for me, and i dont want to try

joshinils commented 2 years ago

problem was mismatching and or too old versions of torch and torchvision, i needed to update, and the requirements.txt should or has to aswell

joshinils commented 2 years ago

@tfaehse please update the requirements.txt to include a working combination of the packages, i guess this is still an issue for some people