Jetson nano 2gb体验maskrcnn-benchmark

官网安装教程maskrcnn-benchmark/INSTALL.md at main · facebookresearch/maskrcnn-benchmark · GitHub

用jupyter跑demo/Mask_R-CNN_demo.ipnb文件,效果如下:
记得要把cpu改成cuda):

Jetson nano 2gb体验maskrcnn-benchmark_第1张图片

Jetson nano 2gb体验maskrcnn-benchmark_第2张图片

上面这两个图使用 jupyter跑的demo,下面才是用源码跑的数据,x先贴一个官网的安装步骤:这里面的依赖这些我之前就设置好了,可以看之前的文章安装pytorch,opencv等;这里是安装maskrcnn-benchmark

# first, make sure that your conda is setup properly with the right environment
# for that, check that `which conda`, `which pip` and `which python` points to the
# right path. From a clean conda env, this is what you need to do

conda create --name maskrcnn_benchmark -y
conda activate maskrcnn_benchmark

# this installs the right pip and dependencies for the fresh python
conda install ipython pip

# maskrcnn_benchmark and coco api dependencies
pip install ninja yacs cython matplotlib tqdm opencv-python

# follow PyTorch installation in https://pytorch.org/get-started/locally/
# we give the instructions for CUDA 9.0
conda install -c pytorch pytorch-nightly torchvision cudatoolkit=9.0

export INSTALL_DIR=$PWD

因为我直接在设备上安装没用虚拟环境上面的我没使用
# install pycocotools
cd $INSTALL_DIR
git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
python3 setup.py build_ext install

# install cityscapesScripts
cd $INSTALL_DIR
git clone https://github.com/mcordts/cityscapesScripts.git
cd cityscapesScripts/
python3 setup.py build_ext install

# install apex
cd $INSTALL_DIR
git clone https://github.com/NVIDIA/apex.git
cd apex
python3 setup.py install --cuda_ext --cpp_ext

# install PyTorch Detection
cd $INSTALL_DIR
git clone https://github.com/facebookresearch/maskrcnn-benchmark.git
cd maskrcnn-benchmark

# the following will install the lib with
# symbolic links, so that you can modify
# the files if you want and won't need to
# re-build it
python3 setup.py build develop


unset INSTALL_DIR

# or if you are on macOS
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py build develop

解决下面这个错误的参考:https://github.com/mrlooi/rotated_maskrcnn/issues/31#issuecomment-631416601

解决方法

在maskrcnn_benchmark/csrc/cuda/deform_conv_cuda.cu和maskrcnn_benchmark/csrc/cuda/deform_pool_cuda.cu文件的开头加上

#ifndef AT_CHECK
#define AT_CHECK TORCH_CHECK 
#endif
/home/nvidia/maskrcnn-benchmark/maskrcnn_benchmark/csrc/cuda/deform_pool_cuda.cu(42): error: identifier "AT_CHECK" is undefined

/home/nvidia/maskrcnn-benchmark/maskrcnn_benchmark/csrc/cuda/deform_pool_cuda.cu(68): error: identifier "AT_CHECK" is undefined

2 errors detected in the compilation of "/tmp/tmpxft_000030f8_00000000-6_deform_pool_cuda.cpp1.ii".
error: command '/usr/local/cuda/bin/nvcc' failed with exit status 1

2gb的内存是真不行呀,10多个小时了尴尬。 

sudo apt-get install ninja_build

pip3 install --default=1000  lvis

打开“apex/requirements.txt”,“apex/requirements_dev.txt” ,对照conda list ,安装缺失的库。

>>> import torch
>>> import apex
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/ljx/vscode/apex/apex/__init__.py", line 8, in 
    from . import amp
  File "/home/ljx/vscode/apex/apex/amp/__init__.py", line 1, in 
    from .amp import init, half_function, float_function, promote_function,\
  File "/home/ljx/vscode/apex/apex/amp/amp.py", line 1, in 
    from . import compat, rnn_compat, utils, wrap
  File "/home/ljx/vscode/apex/apex/amp/rnn_compat.py", line 1, in 
    from . import utils, wrap
  File "/home/ljx/vscode/apex/apex/amp/wrap.py", line 3, in 
    from ._amp_state import _amp_state
  File "/home/ljx/vscode/apex/apex/amp/_amp_state.py", line 14, in 
    from torch._six import container_abcs
ImportError: cannot import name 'container_abcs'

参考大佬的ImportError: cannot import name ‘container_abcs‘ from ‘torch._six‘_豆芽菜-CSDN博客

解决思路:大佬的参考关于升级pytorch1.9后出现cannot import name ‘container_abcs‘ from ‘torch._six‘错误的解决方法_星辰辰大海的博客-CSDN博客

出错的原因是torch不同版本中container_abcs导入差异导致的。因为1.8版本之后container_abcs就已经被移除了。cannot import name 'container_abcs' from 'torch._six'

在使用一些开源代码的时候,可能会遇到该错误。解决方法也很简单我们只需要给它更新。

例如在apex/amp/_amp_state.py中

TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])
if TORCH_MAJOR == 0:
    import collections.abc as container_abcs
else:
    from torch._six import container_abcs
    
改为:

TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])
if TORCH_MAJOR == 1 and TORCH_MINOR < 8:
    from torch._six import container_abcs
else:
    import collections.abc as container_abcs
 

你可能感兴趣的:(Jetson,nano,人工智能)