PANet训练自己的数据(VIA标注)
当前最好的实例分割网络非PANet莫属,可是由于模型太新,网上的资料太少,最近的项目需要 实例分割,只能自己踩踩坑了,目前我还没看到一篇关于PANet训练的博客,只有几篇讲论文的。
环境:ubuntu16.04 anaconda3 pytorch0.4.0
将代码down下来后,我在anaconda中新开了一个环境,用的是python3.6,如果用python2的话,在lib文件夹下的make.sh中的python3需要修改一下
然后一开始的时候我没有进行make,直接进行测试,运行
python tools/test_net.py --dataset coco2017 --cfg configs/panet/e2e_panet_R-50-FPN_2x_mask.yaml --load_ckpt {path/to/your/checkpoint}
然后,报错如下
Traceback (most recent call last): File "tools/test_net.py", line 14, in <module> from core.test_engine import run_inference File "/home/wzy/Documents/PANet-master/lib/core/test_engine.py", line 39, in <module> from modeling import model_builder File "/home/wzy/Documents/PANet-master/lib/modeling/model_builder.py", line 11, in <module> from model.roi_pooling.functions.roi_pool import RoIPoolFunction File "/home/wzy/Documents/PANet-master/lib/model/roi_pooling/functions/roi_pool.py", line 3, in <module> from .._ext import roi_pooling File "/home/wzy/Documents/PANet-master/lib/model/roi_pooling/_ext/roi_pooling/__init__.py", line 3, in <module> from ._roi_pooling import lib as _lib, ffi as _ffi ImportError: /home/wzy/Documents/PANet-master/lib/model/roi_pooling/_ext/roi_pooling/_roi_pooling.so: undefined symbol: __cudaPopCallConfiguration
还是需要make一下的,结果这个环节更让人头大,一直报错
running build_ext building 'utils.cython_bbox' extension creating build creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/utils gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/numpy/core/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c utils/cython_bbox.c -o build/temp.linux-x86_64-3.6/utils/cython_bbox.o -Wno-cpp creating build/lib.linux-x86_64-3.6 creating build/lib.linux-x86_64-3.6/utils gcc -pthread -shared -L/home/ustc/anaconda3/envs/py36/lib -Wl,-rpath=/home/ustc/anaconda3/envs/py36/lib,--no-as-needed -std=c99 build/temp.linux-x86_64-3.6/utils/cython_bbox.o -L/home/ustc/anaconda3/envs/py36/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/utils/cython_bbox.cpython-36m-x86_64-linux-gnu.so building 'utils.cython_nms' extension gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/numpy/core/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c utils/cython_nms.c -o build/temp.linux-x86_64-3.6/utils/cython_nms.o -Wno-cpp gcc -pthread -shared -L/home/ustc/anaconda3/envs/py36/lib -Wl,-rpath=/home/ustc/anaconda3/envs/py36/lib,--no-as-needed -std=c99 build/temp.linux-x86_64-3.6/utils/cython_nms.o -L/home/ustc/anaconda3/envs/py36/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/utils/cython_nms.cpython-36m-x86_64-linux-gnu.so copying build/lib.linux-x86_64-3.6/utils/cython_bbox.cpython-36m-x86_64-linux-gnu.so -> utils copying build/lib.linux-x86_64-3.6/utils/cython_nms.cpython-36m-x86_64-linux-gnu.so -> utils Compiling nms kernels by nvcc... Including CUDA code. /home/ustc/文档/PANet-master/lib/model/nms ['/home/ustc/文档/PANet-master/lib/model/nms/src/nms_cuda_kernel.cu.o'] generating /tmp/tmpwpj4u4zb/_nms.c running build_ext building '_nms' extension creating home creating home/ustc creating home/ustc/文档 creating home/ustc/文档/PANet-master creating home/ustc/文档/PANet-master/lib creating home/ustc/文档/PANet-master/lib/model creating home/ustc/文档/PANet-master/lib/model/nms creating home/ustc/文档/PANet-master/lib/model/nms/src gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c _nms.c -o ./_nms.o -std=c99 gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c /home/ustc/文档/PANet-master/lib/model/nms/src/nms_cuda.c -o ./home/ustc/文档/PANet-master/lib/model/nms/src/nms_cuda.o -std=c99 /home/ustc/文档/PANet-master/lib/model/nms/src/nms_cuda.c: In function ‘nms_cuda’: /home/ustc/文档/PANet-master/lib/model/nms/src/nms_cuda.c:14:22: error: dereferencing pointer to incomplete type ‘THTensor {aka struct THTensor}’ boxes_host->size[0], ^ Traceback (most recent call last): File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile extra_postargs) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/ffiplatform.py", line 49, in _build dist.run_command('build_ext') File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension depends=ext.depends) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "build.py", line 37, in <module> ffi.build() File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 189, in build _build_extension(ffi, cffi_wrapper_name, target_dir, verbose) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 111, in _build_extension outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/api.py", line 684, in compile compiler_verbose=verbose, debug=debug, **kwds) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/recompiler.py", line 1484, in recompile compiler_verbose, debug) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/ffiplatform.py", line 20, in compile outputfilename = _build(tmpdir, ext, compiler_verbose, debug) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/ffiplatform.py", line 56, in _build raise VerificationError('%s: %s' % (e.__class__.__name__, e)) cffi.error.VerificationError: CompileError: command 'gcc' failed with exit status 1 Compiling roi pooling kernels by nvcc... Including CUDA code. /home/ustc/文档/PANet-master/lib/model/roi_pooling generating /tmp/tmpy7_eurcc/_roi_pooling.c running build_ext building '_roi_pooling' extension creating home creating home/ustc creating home/ustc/文档 creating home/ustc/文档/PANet-master creating home/ustc/文档/PANet-master/lib creating home/ustc/文档/PANet-master/lib/model creating home/ustc/文档/PANet-master/lib/model/roi_pooling creating home/ustc/文档/PANet-master/lib/model/roi_pooling/src gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c _roi_pooling.c -o ./_roi_pooling.o -std=c99 gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c /home/ustc/文档/PANet-master/lib/model/roi_pooling/src/roi_pooling.c -o ./home/ustc/文档/PANet-master/lib/model/roi_pooling/src/roi_pooling.o -std=c99 gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c /home/ustc/文档/PANet-master/lib/model/roi_pooling/src/roi_pooling_cuda.c -o ./home/ustc/文档/PANet-master/lib/model/roi_pooling/src/roi_pooling_cuda.o -std=c99 gcc -pthread -shared -L/home/ustc/anaconda3/envs/py36/lib -Wl,-rpath=/home/ustc/anaconda3/envs/py36/lib,--no-as-needed -std=c99 ./_roi_pooling.o ./home/ustc/文档/PANet-master/lib/model/roi_pooling/src/roi_pooling.o ./home/ustc/文档/PANet-master/lib/model/roi_pooling/src/roi_pooling_cuda.o /home/ustc/文档/PANet-master/lib/model/roi_pooling/src/roi_pooling.cu.o -L/home/ustc/anaconda3/envs/py36/lib -lpython3.6m -o ./_roi_pooling.so Compiling roi crop kernels by nvcc... Including CUDA code. /home/ustc/文档/PANet-master/lib/model/roi_crop generating /tmp/tmptm4aw2z1/_roi_crop.c running build_ext building '_roi_crop' extension creating home creating home/ustc creating home/ustc/文档 creating home/ustc/文档/PANet-master creating home/ustc/文档/PANet-master/lib creating home/ustc/文档/PANet-master/lib/model creating home/ustc/文档/PANet-master/lib/model/roi_crop creating home/ustc/文档/PANet-master/lib/model/roi_crop/src gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c _roi_crop.c -o ./_roi_crop.o -std=c99 gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c -o ./home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.o -std=c99 /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c: In function ‘BilinearSamplerBHWD_updateOutput’: /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:10:30: error: dereferencing pointer to incomplete type ‘THTensor {aka struct THTensor}’ int batchsize = inputImages->size[0]; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c: In function ‘BilinearSamplerBHWD_updateGradInput’: /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:190:14: warning: unused variable ‘inBottomRight’ [-Wunused-variable] real inBottomRight=0; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:189:14: warning: unused variable ‘inBottomLeft’ [-Wunused-variable] real inBottomLeft=0; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:188:14: warning: unused variable ‘inTopRight’ [-Wunused-variable] real inTopRight=0; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:187:14: warning: unused variable ‘inTopLeft’ [-Wunused-variable] real inTopLeft=0; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:186:14: warning: unused variable ‘v’ [-Wunused-variable] real v=0; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c: In function ‘BilinearSamplerBCHW_updateGradInput’: /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:441:14: warning: unused variable ‘inBottomRight’ [-Wunused-variable] real inBottomRight=0; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:440:14: warning: unused variable ‘inBottomLeft’ [-Wunused-variable] real inBottomLeft=0; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:439:14: warning: unused variable ‘inTopRight’ [-Wunused-variable] real inTopRight=0; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:438:14: warning: unused variable ‘inTopLeft’ [-Wunused-variable] real inTopLeft=0; ^ /home/ustc/文档/PANet-master/lib/model/roi_crop/src/roi_crop.c:437:14: warning: unused variable ‘v’ [-Wunused-variable] real v=0; ^ Traceback (most recent call last): File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile extra_postargs) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/ffiplatform.py", line 49, in _build dist.run_command('build_ext') File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension depends=ext.depends) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "build.py", line 36, in <module> ffi.build() File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 189, in build _build_extension(ffi, cffi_wrapper_name, target_dir, verbose) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 111, in _build_extension outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/api.py", line 684, in compile compiler_verbose=verbose, debug=debug, **kwds) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/recompiler.py", line 1484, in recompile compiler_verbose, debug) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/ffiplatform.py", line 20, in compile outputfilename = _build(tmpdir, ext, compiler_verbose, debug) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/cffi/ffiplatform.py", line 56, in _build raise VerificationError('%s: %s' % (e.__class__.__name__, e)) cffi.error.VerificationError: CompileError: command 'gcc' failed with exit status 1 Compiling roi align kernels by nvcc... Including CUDA code. /home/ustc/文档/PANet-master/lib/modeling/roi_xfrom/roi_align generating /tmp/tmperu9f6wr/_roi_align.c running build_ext building '_roi_align' extension creating home creating home/ustc creating home/ustc/文档 creating home/ustc/文档/PANet-master creating home/ustc/文档/PANet-master/lib creating home/ustc/文档/PANet-master/lib/modeling creating home/ustc/文档/PANet-master/lib/modeling/roi_xfrom creating home/ustc/文档/PANet-master/lib/modeling/roi_xfrom/roi_align creating home/ustc/文档/PANet-master/lib/modeling/roi_xfrom/roi_align/src gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c _roi_align.c -o ./_roi_align.o -std=c99 gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/ustc/anaconda3/envs/py36/include/python3.6m -c /home/ustc/文档/PANet-master/lib/modeling/roi_xfrom/roi_align/src/roi_align_cuda.c -o ./home/ustc/文档/PANet-master/lib/modeling/roi_xfrom/roi_align/src/roi_align_cuda.o -std=c99 gcc -pthread -shared -L/home/ustc/anaconda3/envs/py36/lib -Wl,-rpath=/home/ustc/anaconda3/envs/py36/lib,--no-as-needed -std=c99 ./_roi_align.o ./home/ustc/文档/PANet-master/lib/modeling/roi_xfrom/roi_align/src/roi_align_cuda.o /home/ustc/文档/PANet-master/lib/modeling/roi_xfrom/roi_align/src/roi_align_kernel.cu.o -L/home/ustc/anaconda3/envs/py36/lib -lpython3.6m -o ./_roi_align.so
这里我主要google了一下 cffi.error.VerificationError: CompileError: command 'gcc' failed with exit status 1
我注意到这是一个很多人都遇到过的问题,在faster-rcnn的pytorch实现中也有这个问题,似乎这个代码的实现部分与faster-rcnn的有相同部分,然后我主要采用了两步解决办法,一是在make.sh中添加
export CXXFLAGS="-std=c++11"
export CFLAGS="-std=c99"
第二点就是采用pytorch0.4.0而不是pytorch0.4.1,然后再make,没看到报错,我就假定没问题了。
接下来琢磨如何训练自己的数据,官方代码给的示例是coco2017数据集,这个数据集很大的,几十G,在网上找了一篇博客https://blog.csdn.net/daniaokuye/article/details/78699138#commentsedit,用wget下载,速度尚可。
下载好后解压,几个文件夹如下所示
其中,三个注释压缩文件解压后的默认文件名都是annotations,所以出现了(2)(3),其中train2017中有118287张图片,19G,val2017有5000张图片,800多M,test2017有40670张图片,6.6G。我不太明白的是stuff_annotations里面的注释文件,查了一下好像是用来做背景语义分割的,做实例分割应该用不到,暂且不管它了,在annotations_trainval2017中存放的是我们想要的语义分割注释,当然了,里面还有场景描述和人体关键点检测的注释。如下
然后image_info_test2017里面是测试集的注释,
左边的应该是测试图片的注释,里面images部分的数目与测试集相等,不过其中只有图像的信息,并没有实例的标签,而右边的不知道是干嘛的。
现在我准备运行一下提供的测试代码,不是输入测试集,而是验证集,验证集有注释文件。
python tools/test_net.py --dataset coco2017 --cfg configs/panet/e2e_panet_R-50-FPN_2x_mask.yaml --load_ckpt {path/to/your/checkpoint
这里要测试的是coco2017验证集,在主目录下新建data文件夹,data里面新建coco文件夹,coco里面新建images文件夹和annotations文件夹,images里面放置val2017数据集,annotations里面放置instances_val2017.json文件,这个时候还需要预训练权重,resnet50_caffe.pth,一开始我下载了pytorch的官方实现,resnet50-19c8e357.pth,发现不行的,键值不匹配。报错如下
Traceback (most recent call last): File "tools/test_net.py", line 112, in <module> check_expected_results=True) File "/home/ustc/文档/PANet-master/lib/core/test_engine.py", line 128, in run_inference all_results = result_getter() File "/home/ustc/文档/PANet-master/lib/core/test_engine.py", line 108, in result_getter multi_gpu=multi_gpu_testing File "/home/ustc/文档/PANet-master/lib/core/test_engine.py", line 158, in test_net_on_dataset args, dataset_name, proposal_file, output_dir, gpu_id=gpu_id File "/home/ustc/文档/PANet-master/lib/core/test_engine.py", line 232, in test_net model = initialize_model_from_cfg(args, gpu_id=gpu_id) File "/home/ustc/文档/PANet-master/lib/core/test_engine.py", line 322, in initialize_model_from_cfg model = model_builder.Generalized_RCNN() File "/home/ustc/文档/PANet-master/lib/modeling/model_builder.py", line 124, in __init__ self._init_modules() File "/home/ustc/文档/PANet-master/lib/modeling/model_builder.py", line 128, in _init_modules resnet_utils.load_pretrained_imagenet_weights(self) File "/home/ustc/文档/PANet-master/lib/utils/resnet_weights_helper.py", line 29, in load_pretrained_imagenet_weights pretrianed_state_dict = convert_state_dict(torch.load(weights_file)) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/serialization.py", line 303, in load return _load(f, map_location, pickle_module) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/serialization.py", line 454, in _load return legacy_load(f) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/site-packages/torch/serialization.py", line 383, in legacy_load tar.extract('storages', path=tmpdir) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/tarfile.py", line 2034, in extract tarinfo = self.getmember(member) File "/home/ustc/anaconda3/envs/py36/lib/python3.6/tarfile.py", line 1745, in getmember raise KeyError("filename %r not found" % name) KeyError: "filename 'storages' not found"
于是乎下载resnet50_caffe.pth,搜了一下没发现什么下载链接,因为这个项目利用了detectron.pytorch这个项目的代码,所以我决定利用detectron.pytorch下载模型权重,项目地址如下https://github.com/roytseng-tw/Detectron.pytorch
安装了几个包后,我执行python download_imagenet_weights.py --targets=resnet50_caffe.pth,过了一会,文件下载好了,太开心了,跑起来
python tools/test_net.py --dataset coco2017 --cfg configs/panet/e2e_panet_R-50-FPN_2x_mask.yaml --load_ckpt /home/ustc/文档/PANet-master/data/pretrained_model/panet_mask_step179999.pth
后面的权重文件是从项目提供的链接下载的,一切妥当,开始对5000张图片进行检测
然后分别执行bbox评估和分割评估,如下
最后的输出为评估结果
接下来跑一下coco2017的训练集,如果没啥问题,就可以着手跑自己的数据了。
python tools/train_net_step.py --dataset coco2017 --cfg configs/panet/e2e_panet_R-50-FPN_2x_mask.yaml --bs 2
我用的这台机器只有一块1080ti,所以把把batch_size设为2,论文里是8块P40,羡慕啊。
训练跑起来后的样子如下
可以看到还需要13天训练完毕,此刻内心是平淡的~
下面就研究如何训练自己的数据了,我采取替换法,就是文件夹文件名啥的都不换,直接把里面的数据换成自己的,把train2017里面的图片换成自己的,把instances_train2017.json里面的注释文件换成自己的,把图片换成自己的,复制粘贴就行了,不过你的标注文件不一定与coco的格式一致,所以这块是麻烦的地方。
我采用的标注工具是VIA,使用说明网上有不少博客,如何将VIA格式转换为COCO格式呢,需要仔细看一下二者的区别,
VIA格式
用json存储,这一点与COCO相同,json就是一个大字典,VIA采用的键值为图像名称加一个size(这个size我没搞清楚,猜测是所有mask的面积和),图像名称下面仍然为一个字典,共有filename,size,regions,file_attributes四个键,文件名就是图像名,size按照我猜测的为掩码面积和,regions里面就是一个一个mask,file_attribute我没有用到,置为空。截图看一下
regions下面存放着许多region,每个region有shape_attributes和region_attributes两个属性,一个存放标注的多边形,一个存放类别,region就是关键。
COCO格式
关于COCO的格式,太多太多博客了,就大致看一下吧
总的框架
其中info,licenses都是无关紧要的
对于我们来说,需要关注的是images,annotatios还有categories,分别看一下
对于我们而言,id是可以自行生成的,类别是手动添加的,逐个累加就好,需要计算的是area,bbox,因为VIA格式中没有这两个属性,另外,我的应用场景中,物体都是单一的,所以crowd都设为0,这一点可能需要注意一下
然后就开始具体的转换了,我把代码放在了 https://github.com/codingwolfman/VIA2COCO
将VIA转为COCO后,就可以照常跑起来了。