faster-rcnn.pytorch项目环境配置(从0到1)

本文详细介绍了如何在AutoDL平台上配置faster-rcnn.pytorch项目的环境,包括Python、CUDA、COCOAPI的安装,以及解决pytorch版本问题和数据集的下载。此外,还提到了代码修改和预训练模型的获取,以确保项目能成功运行。
摘要由CSDN通过智能技术生成

faster-rcnn.pytorch项目环境配置(从0到1)

其实pytorch版本和CUDA版本高,都没有关系!!!都可以适配,显卡30系、20系都没关系,都可以用!

下面我将在AutoDL平台上,从0到1安装配置一遍!!!

  1. conda create -n DA python=3.8
  2. conda activate DA
  3. 克隆代码
git clone https://github.com/jwyang/faster-rcnn.pytorch.git
cd faster-rcnn.pytorch
git checkout pytorch-1.0
  1. pip install -r requirements.txt

若安装opencv时卡死,请单独安装opencv-python,并附带版本:

pip install opencv-python==3.4.9.31

  1. 安装pytorch
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
  1. 编译coco api

cd lib/pycocotools #进入coco文件夹
新建 setup.py 文件,并将以下内容复制

# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------

import os
from setuptools import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy as np


# Obtain the numpy include directory.  This logic works across numpy versions.
try:
   numpy_include = np.get_include()
except AttributeError:
   numpy_include = np.get_numpy_include()


ext_modules = [
   Extension(
       '_mask',
       sources=['maskApi.c', '_mask.pyx'],
       include_dirs = [numpy_include, '.'],
       extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
   )
]

setup(
   name='faster_rcnn',
   ext_modules=ext_modules,
   # inject our custom trigger
   cmdclass={'build_ext': build_ext},
)

随后python setup.py build_ext --inplace

  1. 编译cuda依赖

cd …
python setup.py build develop # 编译cuda 依赖项

若发生以下错误:

image-20230704101551308

pytorch版本问题:pytorch在最新的版(1.11)本中将THC/THC.h文件删除了。降低pytorch版本即可
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge
  1. 在根目录下创建data,下载数据集/预训练权重
mkdir data
cd data

wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar

tar xvf VOCtrainval_06-Nov-2007.tar
tar xvf VOCtest_06-Nov-2007.tar
tar xvf VOCdevkit_08-Jun-2007.tar

# 在xxx/data路径下
ln -s /root/autodl-tmp/faster-rcnn.pytorch/data/VOCdevkit VOCdevkit2007

mkdir pretrained_model
cd pretrained_model
wget https://filebox.ece.vt.edu/~jw2yang/faster-rcnn/pretrained-base-models/resnet101_caffe.pth
wget https://filebox.ece.vt.edu/~jw2yang/faster-rcnn/pretrained-base-models/vgg16_caffe.pth
  1. 更改代码:
autodl-tmp/faster-rcnn.pytorch/lib/roi_data_layer/minibatch.py
第15行: from scipy.misc import imread
改为: from imageio import imread  
pip install imageio

autodl-tmp/faster-rcnn.pytorch/lib/model/utils/config.py
第374行:yaml_cfg = edict(yaml.load(f))
改为:yaml_cfg = edict(yaml.safe_load(f))

随后

CUDA_VISIBLE_DEVICES=0 python trainval_net.py --dataset pascal_voc --net vgg16 --epochs 20 --bs 1 --nw 2 --lr 1e-2 --lr_decay_step 8 --use_tfb --cuda

image-20230704113958634

参考:

1

2

[3](
https://blog.csdn.net/cube_suger/article/details/112648721

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值