FCOS源码:https://github.com/tianzhi0549/FCOS
FCOS Installation & Requirements:https://github.com/tianzhi0549/FCOS/blob/master/INSTALL.md
一、建立 CUDA+cudnn镜像
github option1 给出的是CUDA 10.2的版本(其他版本也可,安装匹配的软件版本即可),结合本地环境,首先建立基础镜像,直接拉取nvidia docker官方镜像作为我们的系统镜像。
docker pull nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
二、制作数据卷
建立了本地服务器的位置/data/g_y 和数据卷位置 /usr/Downloads的映射,实现了数据的共享和重用。
docker run -v /data/g_y:/usr/Downloads --name dataVol nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04 /bin/bash
docker inspect dataVol,查看数据卷的信息。
注意:挂载到的数据卷的位置,如果与容器中的位置相同时,服务器挂载到数据卷的文件夹,会覆盖掉容器里的原来该文件夹的内容。
例如容器里也有/usr/Downloads文件夹,且文件夹下含有文件a,则服务器挂载过来的文件夹/data/g_y到容器的/usr/Downloads位置,该文件夹下只包含服务器/data/g_y的内容,文件a将不存在。
三、创建容器,挂载到dataVol数据卷
docker run -it --gpus all --name g_fcos --volumes-from dataVol nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04 /bin/bash
容器名为g_fcos,方便引用。同时更新源和相应的软件。
apt-get update
apt-get upgrade
apt-get install vim
apt-get install wget curl git
update :同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,获取到最新的软件包。upgrade是根据update命令下载的metadata决定要更新什么包(同时获取每个包的位置)。
四、安装FCOS
根据FCOS Installation & Requirements 安装各种环境及编译FCOS。
1.FCOS应用conda 安装,则先安装anaconda。https://repo.anaconda.com 选择相应的conda下载安装。
wget -c https://repo.anaconda.com/archive/Anaconda3-2019.07-Linux-x86_64.sh
bash /usr/Downloads/Anaconda3-2019.07-Linux-x86_64.sh
出现的问题:Executing transaction: \ WARNING conda.core.envs_manager:register_env(46): Unable to register environment. Path not writable or missing. environment location: /root/anaconda3
该处为warning,同时也会显示“installation finished.” 。warning可不予处理,查看anaconda路径已写入到环境变量Path中,不影响后期使用。
2.在anaconda 中建立FCOS环境,用于安装FCOS。
conda create --name FCOS python=3.7
同时安装了python 3.7。
3.安装FCOS和coco 依赖项
pip install ninja yacs cython matplotlib tqdm
可根据conda list罗列已安装的模块,再选择安装上述依赖项。
4.安装pytorch
conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
可根据pytorch官网https://pytorch.org/get-started/locally,选择相应的配置环境获取对应的pytorch安装链接。
5.安装pycocotools
git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
python setup.py build_ext install
6.安装FCOS
git clone https://github.com/tianzhi0549/FCOS.git
cd FCOS
python setup.py build develop --no-deps
等待编译成功。
五、运行demo
wget https://cloudstor.aarnet.edu.au/plus/s/ZSAqNJB96hA71Yf/download -O FCOS_imprv_R_50_FPN_1x.pth
python demo/fcos_demo.py
输出图片名和相应的前向处理时间,由于在容器里实现,直接保存生成的效果图再查看。
六、提交容器,上传镜像
退出当前容器,exit。再提交至镜像。
docker commit g_FCOS XXXXXX:g_fcos
push到云端
docker push XXXXXX:g_fcos
七、安装、编译、运行demo过程中出现的问题:
1)File "/root/FCOS/fcos_core/modeling/rpn/fcos/inference.py", line 69, in forward_for_single_feature_map
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
解决方法:用 .contiguous() 将view的tensor在内存中变成连续分布:
pre_nms_top_n = candidate_inds.contiguous.view(N, -1).sum(1)
2) csrc/cuda/deform_pool_cuda.cu(42): error: identifier "AT_CHECK" is undefined
解决方法:在报错文件的开头加上宏:
#ifndef AT_CHECK
#define AT_CHECK TORCH_CHECK
#endif
3)找不到文件报错
build时相应的文件都有,但在代码里嵌套了相对路径可能存在问题,按实际相对路径修改。
4)FCOS 编译成功,运行demo时opencv的问题
i) cv2.error: OpenCV(3.4.2) /tmp/build/80754af9/opencv-suite_1535558553474/work/modules/highgui/src/window.cpp:632: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
ii) File "/root/anaconda3/envs/FCOS_g/lib/python3.7/site-packages/cv2/__init__.py", line 5, in <module>
from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
iii) qt.qpa.plugin: Could not load the Qt platform plugin “xcb” in “/root/anaconda3/.../cv2/qt/plugins” even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb
以上三个opencv问题更新&安装了opencv的组件等,都没有解决。sudo apt install libgl1-mesa-glx、sudo apt-get install -y libgl1-mesa-dev这些都没有解决问题。
重新安装了opencv可以解决上述报错。