YOLOX icon indicating copy to clipboard operation
YOLOX copied to clipboard

RuntimeError: Ninja is required to load C++ extensions

Open yjcreation opened this issue 3 years ago • 9 comments

run code by python tools/eval.py -n yolox-s -c yolox_s.pth -b 2 -d 1 --conf 0.001

error: 2022-07-30 00:16:44.546 | ERROR | yolox.core.launch:launch:98 - An error has been caught in function 'launch', process 'MainProcess' (73156), thread 'MainThread' (85696): Traceback (most recent call last):

File "tools/eval.py", line 219, in args=(exp, args, num_gpu), │ │ └ 1 │ └ Namespace(batch_size=2, ckpt='yolox_s.pth', conf=0.001, devices=1, dist_backend='nccl', dist_url=None, exp_file=None, experim... └ ╒═══════════════════╤════════════════════════════════════════════════════════════════════════════════════════════════════════...

File "d:\pywork\3.debug\yolox\yolox\core\launch.py", line 98, in launch main_func(*args) │ └ (╒═══════════════════╤═══════════════════════════════════════════════════════════════════════════════════════════════════════... └ <function main at 0x0000023B5407F730>

File "tools/eval.py", line 194, in main model, is_distributed, args.fp16, trt_file, decoder, exp.test_size │ │ │ │ │ │ │ └ (640, 640) │ │ │ │ │ │ └ ╒═══════════════════╤════════════════════════════════════════════════════════════════════════════════════════════════════════... │ │ │ │ │ └ None │ │ │ │ └ None │ │ │ └ False │ │ └ Namespace(batch_size=2, ckpt='yolox_s.pth', conf=0.001, devices=1, dist_backend='nccl', dist_url=None, exp_file=None, experim... │ └ False └ YOLOX( (backbone): YOLOPAFPN( (backbone): CSPDarknet( (stem): Focus( (conv): BaseConv( (conv): ...

File "d:\pywork\3.debug\yolox\yolox\evaluators\coco_evaluator.py", line 242, in evaluate eval_results = self.evaluate_prediction(data_list, statistics) │ │ │ └ tensor([2.1702, 0.0110, 4.0000], device='cuda:0') │ │ └ [{'image_id': 0, 'category_id': 56, 'bbox': [-33.6690673828125, 9.699737548828125, 3907.0078125, 2132.7041015625], 'score': 0... │ └ <function COCOEvaluator.evaluate_prediction at 0x0000023B58CC9BF8> └ <yolox.evaluators.coco_evaluator.COCOEvaluator object at 0x0000023B60FC6F28>

File "d:\pywork\3.debug\yolox\yolox\evaluators\coco_evaluator.py", line 317, in evaluate_prediction from yolox.layers import COCOeval_opt as COCOeval

File "d:\pywork\3.debug\yolox\yolox\layers_init_.py", line 11, in from .fast_coco_eval_api import COCOeval_opt

File "d:\pywork\3.debug\yolox\yolox\layers\fast_coco_eval_api.py", line 17, in FastCOCOEvalOp().jit_load() └ <class 'yolox.layers.jit_ops.FastCOCOEvalOp'>

File "d:\pywork\3.debug\yolox\yolox\layers\jit_ops.py", line 107, in jit_load verbose=verbose, └ True

File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1136, in load keep_intermediates=keep_intermediates) └ True

File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1347, in _jit_compile is_standalone=is_standalone) └ False

File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1418, in _write_ninja_file_and_build_library verify_ninja_availability() └ <function verify_ninja_availability at 0x0000023B632F7268>

File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1474, in verify_ninja_availability raise RuntimeError("Ninja is required to load C++ extensions")

RuntimeError: Ninja is required to load C++ extensions How can I solve this on a windows machine ?

When i use pip install ninja, it shows Requirement already satisfied: ninja in d:\f\anaconda3\envs\yolox\lib\site-packages (1.10.2.3)

yjcreation avatar Jul 29 '22 16:07 yjcreation

What about direct build by the following code:

from yolox.layers import FastCOCOEvalOp
FastCOCOEvalOp().jit_load()

FateScript avatar Aug 01 '22 03:08 FateScript

Where should the above code be added?

Before this problem occurs, I have added the above two lines of code to yolox/layers/fast_ coco_ eval_ api.py. What should I do?

yjcreation avatar Aug 01 '22 03:08 yjcreation

Where should the above code be added?

Plz try it in a terminal like python3 or ipython

FateScript avatar Aug 01 '22 08:08 FateScript

When i try it in a terminal like python3, I have the same error.yolox is my virtual environment: `(yolox) D:\pywork\3.debug\YOLOX>python Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information.

from yolox.layers import FastCOCOEvalOp Using C:\Users\15496\AppData\Local\torch_extensions\torch_extensions\Cache\py37_cu113 as PyTorch extensions root... Traceback (most recent call last): File "D:\F\Anaconda3\envs\pytorch\lib\runpy.py", line 193, in run_module_as_main "main", mod_spec) File "D:\F\Anaconda3\envs\pytorch\lib\runpy.py", line 85, in run_code exec(code, run_globals) File "D:\F\Anaconda3\envs\yolox\Scripts\ninja.exe_main.py", line 4, in ModuleNotFoundError: No module named 'ninja' Traceback (most recent call last): File "", line 1, in File "D:\pywork\3.debug\YOLOX\yolox\layers_init.py", line 11, in from .fast_coco_eval_api import COCOeval_opt File "D:\pywork\3.debug\YOLOX\yolox\layers\fast_coco_eval_api.py", line 17, in FastCOCOEvalOp().jit_load() File "D:\pywork\3.debug\YOLOX\yolox\layers\jit_ops.py", line 107, in jit_load verbose=verbose, File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1136, in load keep_intermediates=keep_intermediates) File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1347, in _jit_compile is_standalone=is_standalone) File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1418, in _write_ninja_file_and_build_library verify_ninja_availability() File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1474, in verify_ninja_availability raise RuntimeError("Ninja is required to load C++ extensions") RuntimeError: Ninja is required to load C++ extensions`

yjcreation avatar Aug 01 '22 08:08 yjcreation

Plz make sure that ninja is installed in your conda env.

FateScript avatar Aug 01 '22 09:08 FateScript

i'm sure that ninja is installed in my conda env yolox. image

But i found that errorFile "D:\F\Anaconda3\envs\pytorch\lib\runpy.py", line 193, in run_module_as_main "main", mod_spec) File "D:\F\Anaconda3\envs\pytorch\lib\runpy.py", line 85, in run_code exec(code, run_globals) in the previous comment. So i installed ninja in another conda env pytorch. pytorch is my another conda env, i don't know why it went to my another virtual environment pytorch to find ninja in the virtual environment of yolox?

yjcreation avatar Aug 01 '22 09:08 yjcreation

What about direct build by the following code:

from yolox.layers import FastCOCOEvalOp
FastCOCOEvalOp().jit_load()

I am add this code in train.py, and get the following err:

Traceback (most recent call last):
  File "/home/jinhai_zhou/work/YOLOX/tools/train.py", line 17, in <module>
    FastCOCOEvalOp().jit_load()
  File "/home/jinhai_zhou/work/YOLOX/yolox/layers/jit_ops.py", line 107, in jit_load
    verbose=verbose,
  File "/home/anaconda3/envs/Yolo/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 997, in load
    keep_intermediates=keep_intermediates)
  File "/home/anaconda3/envs/Yolo/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1202, in _jit_compile
    with_cuda=with_cuda)
  File "/home/anaconda3/envs/Yolo/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1268, in _write_ninja_file_and_build_library
    verify_ninja_availability()
  File "/home/anaconda3/envs/Yolo/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1323, in verify_ninja_availability
    raise RuntimeError("Ninja is required to load C++ extensions")
RuntimeError: Ninja is required to load C++ extensions

I have the same problem, but the ninja was installed in my conda env image

@yjcreation Then I solved it by following code:

wget https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-linux.zip
sudo unzip ninja-linux.zip -d /usr/local/bin/
sudo update-alternatives --install /usr/bin/ninja ninja /usr/local/bin/ninja 1 --force 

zhoujinhai avatar Aug 25 '22 03:08 zhoujinhai

Is there any solution in windows environment with this problem?

xiaomaofeng avatar Mar 31 '23 09:03 xiaomaofeng

What solved it for me (so far) in a windows environment: I made sure that I have ninja 1.11.1 installed in pip, re-installed YoloX and downloaded the ninja.exe for windows from ninja-build repo and added it to PATH together with my venv:

    my_env = os.environ.copy()
    my_env["PATH"] = "D:\\code\\YoloX\\.venv\\;" + my_env["PATH"]
    my_env["PATH"] = "D:\\code\\YoloX\\ninja\\;" + my_env["PATH"]
    os.environ.update(my_env)

After that had to fix #1346 and now I am currently fixing #1307.

UPDATE: I gave up and I run it in WSL instead.

szymonkulpinski avatar Feb 28 '24 13:02 szymonkulpinski