pytorch_mmcv环境配置

版本要求

  • cuda:11.1
  • cudtoolkit:11.0
  • cudnn:6.0
  • mmcv-full:1.4.5
  • pytorch:1.7

安装命令

新建虚拟环境并激活:

conda create -n pytorch python=3.7
conda activate pytorch

pytorch官网

官方命令:

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0 -c pytorch

通过pytorch下载速度很慢,可以换成清华源:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes

换源之后命令:

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0

接着安装cudnn:

cuda install cudnn(不加版本号自动匹配相应版本)

接着安装mmcv-full:

mmcv官网

进入官网找到对应的torch版本和cuda版本对应的mmcv命令:

pip install mmcv-full=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html

以上基本安装完毕,接下来就是clone下mmsegmentation仓库:

在相应目录下clone:

git clone  https://github.com/open-mmlab/mmsegmentation.git 

安装相关依赖:

cd mmsegmentation
pip install -e . 

测试是否安装成功

在mmsegmentation目录下新建test.py文件:

from mmseg.apis import inference_segmentor, init_segmentor
import mmcv

config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'
checkpoint_file = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'

# build the model from a config file and a checkpoint file
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')

# test a single image and show the results
img = 'test.jpg'  # or img = mmcv.imread(img), which will only load it once
result = inference_segmentor(model, img)
# visualize the results in a new window
model.show_result(img, result, show=True)
# or save the visualization results to image files
# you can change the opacity of the painted segmentation map in (0, 1].
model.show_result(img, result, out_file='result.jpg', opacity=0.5)

# test a video and show the results
#video = mmcv.VideoReader('video.mp4')
#for frame in video:
#   result = inference_segmentor(model, frame)
#   model.show_result(frame, result, wait_time=1)

新建目录checkpoints,进入目录并下载pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth文件:

下载地址

在mmsegmentation目录下添加一张jpg图片

运行test.py文件运行成功即为安装成功

mmdetection是一个基于PyTorch框架的目标检测库,它提供了丰富的目标检测算法和实用工具。下面是mmdetection的安装与环境配置步骤: 1. 安装Anaconda:首先,确保你已经安装了Anaconda,可以通过官方网站下载对应的安装包进行安装。 2. 创建虚拟环境:打开Anaconda命令行工具或者终端,执行以下命令来创建一个新的虚拟环境: ``` conda create -n mmdet python=3.7 -y ``` 这将在当前目录下创建一个名为mmdet的虚拟环境,并使用Python 3.7版本。 3. 激活虚拟环境:创建完成后,执行以下命令来激活虚拟环境: ``` conda activate mmdet ``` 4. 安装依赖:在激活的虚拟环境中,执行以下命令来安装mmdetection所需的依赖: ``` conda install pytorch torchvision -c pytorch pip install mmcv-full==1.3.0 ``` 5. 下载mmdetection:你可以通过Git克隆mmdetection的代码库,执行以下命令来下载mmdetection: ``` git clone https://github.com/open-mmlab/mmdetection.git cd mmdetection ``` 6. 安装mmdetection:在mmdetection目录下,执行以下命令来安装mmdetection: ``` pip install -r requirements/build.txt pip install -v -e . ``` 7. 编译CUDA扩展:如果你的环境支持CUDA,并且你需要使用CUDA加速,可以执行以下命令来编译CUDA扩展: ``` pip install -r requirements/optional.txt cd mmdet/ops python setup.py develop cd ../.. ``` 至此,mmdetection的安装与环境配置完成。你可以通过运行示例代码或者参考mmdetection的文档来使用该库进行目标检测任务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值