open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.55k stars 9.46k forks source link

你这个安装教程不对啊! #11926

Open lingdujunshang opened 2 months ago

lingdujunshang commented 2 months ago

这是我安装的history,环境ubuntu22,cuda11.8(带cudnn,nccl),python3.9,4090显卡,,哪一步都是照着教程做的,最后我只得到了一堆报错, Traceback (most recent call last): File "demo/image_demo.py", line 63, in from mmdet.apis import DetInferencer File "/home/xuqing/miniconda3/mmdetection/mmdet/init.py", line 16, in assert (mmcv_version >= digit_version(mmcv_minimum_version) AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4, <2.2.0.

我对mmdetection没啥意见,咱就是说,入门的安装教程跑不起来,后面咋跑啊, 2055 mkdir -p ~/miniconda3 2056 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh 2057 bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 2058 cd ~/miniconda3/ 2059 ls 2060 conda --version 2061 ~/miniconda3/bin/conda init bash 2062 ~/miniconda3/bin/conda init zsh 2063 cat ~/.zshrc 2064 cd .. 2065 conda create --name openmmlab python=3.8 -y 2066 cd miniconda3/ 2067 conda --version 2068 ls 2069 /home/xuqing/miniconda3/bin/conda --version 2070 /home/xuqing/miniconda3/bin/conda create --name openmmlab python=3.8 -y 2071 cat ~/.zshrc 2072 vim ~/.bashrc 2073 source ~/.bashrc 2074 vim ~/.bashrc 2075 conda activate openmmlab 2076 conda install pytorch torchvision -c pytorch 2077 pip install -U openmim 2078 conda install pytorch torchvision -c pytorch 2079 conda install fsspec 2080 pip install -U openmim 2081 mim install mmengine 2082 mim install "mmcv>=2.0.0" 2083 git clone https://github.com/open-mmlab/mmdetection.git 2084 cd mmdetection 2085 pip install -v -e . 2086 mim download mmdet --config rtmdet_tiny_8xb32-300e_coco --dest . 2087 python demo/image_demo.py demo/demo.jpg rtmdet_tiny_8xb32-300e_coco.py --weights rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth --device cpu 2088 mim install mmcv==2.0.0rc4 (#装不上。失败)

大佬们把这个代码开源出来供大家学习,确实是感谢,就是吧,这个教程实在是跑不通,也不利于长期发展啊,,如果需要支援,需要各种环境测试,我愿意支持,啥时候能把安装教程给更新一下就好了。

zsz00 commented 2 months ago

@Keiku @hhaAndroid 希望看下, 更新下 mmcv 和 mmdet 的兼容性.

AI-Tianlong commented 2 months ago

其实,最简单的修改办法。。就是把mmdettection/mmdet/__init.py__中的 mmcv_maximum_version = '2.2.0' 改大一点。。。现在的版本刚好是MMCV=2.2.0,但他是,左闭右开, image 所以。。。把mmcv_maximum_version = '2.2.0'改为 mmcv_maximum_version = '2.5.0' 就能顺利安装了

lingdujunshang commented 2 months ago

其实,最简单的修改办法。。就是把mmdettection/mmdet/__init.py__中的 mmcv_maximum_version = '2.2.0' 改大一点。。。现在的版本刚好是MMCV=2.2.0,但他是,左闭右开, image 所以。。。把mmcv_maximum_version = '2.2.0'改为 mmcv_maximum_version = '2.5.0' 就能顺利安装了

这个办法早试过了,并不管用,不过后来我也装好了,,我总结下来,最根本的问题是各个软件版本包括torch的对应问题,我在下面写自己安装成功的版本和方式希望能够帮助初步搭建环境的各位

lingdujunshang commented 2 months ago

果然还是自己最能了解自己,在我尝试了两个pip虚拟环境以及一个miniconda的环境以后,我认为环境搭建成功的秘诀在于各个软件版本的对应问题,比如说。教程中说安装mmengine的方式是这样的pip install mmengine,这谁不会啊,,但是你pip这么个装法,还就是真的不对,因为打开git上的mmengine主页,标题下面的小字就能看到,人家要求torch1.6-2.1,咱根据torch官网装了个2.4,那必然要报错啊,说不定mmengine开发的时候,torch2.4还没有呢,怎么能要求各个api都能对应的起来呢?所以,我在这里之说我自己装了的能跑推理和yolov3训练的但是还有warning的环境,仅供各位参考,有啥说的不对的,欢迎匹配指出:首先需要一台电脑,我的是ubuntu22服务器,硬件是双4090,显卡驱动,cuda11.8,cudnn8.9.7,nccl版本不详(单卡不用装这个),python3.9,首先创建一个虚拟环境,我用的是venv,然后装torch2.1(torch官网上找到的版本是pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu118 ),然后就是源码编译安装mmcv和mmengine,直接打开mmcv的git主页和mmengine的git主页看源码编译方式就可以了,我估计直接编译估计问题不大,如果mmcv说有问题的话,可以试一下我的实践:下载2.x版本的mmcv,编译的时候报--std=c++14的错误,我直接把setup.py中的c++14全都改成了c++17,,,,目前虽然项目还有点陌生,推理一张图基本就是这样报错的,看了一下源码,水平不到没看懂, Loads checkpoint by local backend from path: work_dirs/yolov3_mobilenetv2_8xb24-320-300e_coco/epoch_30.pth 09/03 13:34:27 - mmengine - WARNING - Failed to search registry with scope "mmdet" in the "function" registry tree. As a workaround, the current "function" registry in "mmengine" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmdet" is a correct scope, or whether the registry is initialized. /home/xuqing/projects/mm_env2/lib/python3.9/site-packages/mmengine/visualization/visualizer.py:196: UserWarning: Failed to add <class 'mmengine.visualization.vis_backend.LocalVisBackend'>, please provide the save_dir argument. warnings.warn(f'Failed to add {vis_backend.class}, ' Inference ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
results have been saved at temp

lingdujunshang commented 2 months ago

最后还是感谢mmdetection开源项目,虽然环境安装费了些功夫,但是不管是框架还是代码都有很多可以学习的地方,致敬大佬们,我再继续学习学习去了。

hashstone commented 2 months ago

Loads checkpoint by local backend from path: work_dirs/yolov3_mobilenetv2_8xb24-320-300e_coco/epoch_30.pth 09/03 13:34:27 - mmengine - WARNING - Failed to search registry with scope "mmdet" in the "function" registry tree. As a workaround, the current "function" registry in "mmengine" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmdet" is a correct scope, or whether the registry is initialized. /home/xuqing/projects/mm_env2/lib/python3.9/site-packages/mmengine/visualization/visualizer.py:196: UserWarning: Failed to add <class 'mmengine.visualization.vis_backend.LocalVisBackend'>, please provide the save_dir argument. warnings.warn(f'Failed to add {vis_backend.class}, '

@lingdujunshang 这个只是告警,推理已经成功了,result在temp目录. 最好用镜像来跑

  1. 修改下dockerfile/Dockerfile, RUN pip install --no-cache-dir openmim && mim install "mmengine>=0.7.1" "mmcv>=2.0.0rc4,<2.2.0"
  2. docker build -t mmdetection docker/
  3. docker run -v /data/${your-models-path}:/mmdetection/${your-models-path} --it mmdetection:latest /bin/bash,
  4. pip install lap
  5. 然后按照 https://mmdetection.readthedocs.io/zh-cn/latest/get_started.html 中的验证安装的步骤即可,把模型下载到 /mmdetection/${your-models-path} 目录下, 下次运行就不用重复下载了,其余的demo命令改下对应的目录参数