本文参考:使用colab训练faster-rcnn_LCCFlccf的博客-CSDN博客
首先下载配置谷歌云盘下载配置不做介绍。
1.配置环境
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
2.克隆Faster_RCNN源代码
!git clone -b pytorch-1.0 https://github.com/jwyang/faster-rcnn.pytorch.git
3.进入Faster_ RCNN文件夹
import os
os.chdir('faster-rcnn.pytorch')
!ls
4.下载预训练权重
!mkdir data
os.chdir('data')
!mkdir pretrained_model
os.chdir('pretrained_model')
# 下载预训练模型res101
!wget https://filebox.ece.vt.edu/~jw2yang/faster-rcnn/pretrained-base-models/resnet101_caffe.pth
# 下载预训练模型vgg16
!wget https://filebox.ece.vt.edu/~jw2yang/faster-rcnn/pretrained-base-models/vgg16_caffe.pth
5.下载数据集
os.chdir('../') #返回上一级目录即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
# 建立软连接
!ln -s $VOCdevkit VOCdevkit2007 #注意!如果上面解压缩得到的文件夹名字为"VOCdevdit",要将其改为“VOCdevdit2007",否则后面会报错。
6.删除faster-rcnn.pytorch下的VOCdevkit2007,并修改文件夹VOCdevkit为VOCdevkit2007
!rm -rf VOCdevkit2007
在进行下一步代码编译之前由于CUDA版本预GCC不对应的问题会出现如下错误:
error: command '/usr/local/cuda/bin/nvcc' failed with exit status 1
解决方法运行下面代码: