當前最好的實例分割網絡非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后,就可以照常跑起來了。