紙
より高速な ILOD: より高速な RCNN 2020 に基づく物体検出器の増分学習
論文: https://arxiv.org/abs/2003.03901
コード: https://github.com/CanPeng123/Faster-ILOD
コード
一、要件:
-
ナイトリー リリースの PyTorch 1.0。1.0 や 1.0.1 では動作しません
。インストール手順は https://pytorch.org/get-started/locally/ にあります。 -
マスターからのトーチビジョン
-
ココアピ
-
yacs
-
matplotlib
-
GCC >= 4.9
-
OpenCV
-
CUDA >= 9.0
2. インストール ステップバイステップのインストール
# 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
python setup.py build_ext install
# install cityscapesScripts
cd $INSTALL_DIR
git clone https://github.com/mcordts/cityscapesScripts.git
cd cityscapesScripts/
python setup.py build_ext install
# install apex
cd $INSTALL_DIR
git clone https://github.com/NVIDIA/apex.git
cd apex
python 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
python 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
3.より高速なILOD
maskrcnn 環境をインストールした後、Faster-ILOD 関連のコードを maskrcnn 関連のフォルダーに上書きし、python setup.py build development を実行して、Faster-ILOD コードを直接再コンパイルまたはダウンロードします。
4. Faster-ILOD を実行する
例として 15+5 を取り上げます。
1. データセット パスを変更する
Faster-ILOD/maskrcnn_benchmark/config/paths_catalog.py を変更して、voc に対応するパスを見つけ、独自のものに変更します。
2.構成ファイルを変更する
/configs/e2e_faster_rcnn_R_50_C4_1x.yaml は
、要件に応じてさまざまなパラメーターを変更できます。このファイルは今のところ変更されません。
3. 基本的なネットワークのトレーニング
正常に実行された後python tools/train_first_step.py --config-file="./configs/e2e_faster_rcnn_R_50_C4_1x.yaml"
、トレーニングの出力/home/incremental_learning_ResNet50_C4/RPN_15_classes_40k_steps
を で。
4. インクリメンタル トレーニング
(1) e2e_faster_rcnn_R_50_C4_1x_Source_model.yaml と e2e_faster_rcnn_R_50_C4_1x_Target_model.yaml を変更し、ファイル内のカテゴリ、新しいカテゴリ、古いカテゴリ、前の段階でトレーニングされた最終モデルのパス、およびそれに応じて出力パスを変更します。実行して、python tools/train_incremental.py
対応する出力ファイルで最終的なトレーニング結果を取得します。
- e2e_faster_rcnn_R_50_C4_1x_Source_model.yaml
- e2e_faster_rcnn_R_50_C4_1x_Target_model.yaml
- tools/train_incremental.py
source_model_config_file = "/home/chenfang/maskrcnn-benchmark/configs/e2e_faster_rcnn_R_50_C4_1x_Source_model.yaml"
target_model_config_file = "/home/chenfang/maskrcnn-benchmark/configs/e2e_faster_rcnn_R_50_C4_1x_Target_model.yaml"
五、遭遇する問題
1. ネットワークの問題により git clone をダウンロードできない
ファイルはローカルにダウンロードしてサーバーにアップロードできます。
インストール パッケージもローカルにダウンロードしてサーバーにアップロードできます。インストールする pip install ファイル パス
2.RuntimeError: 拡張機能のオブジェクトのコンパイル中にエラーが発生しました
pytorch のバージョンが不適切解決策を検討した
後、pytorch のバージョンを 1.5 にダウングレードすることに成功しました。
CUDA 10.1
Pytorch 1.4.0
torchvision 0.5.0
その他のソリューションについては、https://github.com/facebookresearch/maskrcnn-benchmark/issues/1236 を参照してください。
3.RuntimeError: UnbindBackward の出力 0 はビューであり、そのベースまたはそのベースの別のビューがインプレースで変更されています。
RuntimeError: Output 0 of UnbindBackward is a view and its base or another view of its base has been modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.
参考: https://blog.csdn.net/Ginomica_xyx/article/details/120491859
この問題の原因は、self.bbox が複数回変更されていることであることがわかっており、2 回目の変更時に、python は元の self.bbox を操作するのか、変更された self.bbox を操作するのかわかりません。
問題を認識し、問題の解決を試みてください: コードを変更して、self.bbox をパラメーターにコピーしてから、このパラメーターを操作します (許可されていません); ディープ コピーも許可されていません。
関連する問題を確認してください。最終的な分析では、pytorch1.7.0 のバグです。
この問題を解決するには、pytorch のバージョンを 1.6.0 にダウングレードします。
4.「usr/local/cuda-10.0/bin/nvcc」を実行できません:そのようなファイルまたはディレクトリはありません
https://blog.csdn.net/qq_41251963/article/details/110120386
https://blog.csdn.net/tailonh/article/details/120322932
https://blog.csdn.net/G_inkk/article/details/ 124584873
5. エラー: メンバ関数 'void std::basic_string<_CharT, _Traits, _Alloc>を呼び出せません::
python setup.py ビルド 開発 再コンパイル
はエラーです
void std::basic_string<_CharT, _Traits, _Alloc>::_Rep
ソリューション
参考:https://blog.csdn.net/weixin_45328592/article/details/114646355
https://blog.csdn.net/qq_29695701/article/details/118548238
sudo gedit /usr/include/c++/7/bits/basic_string.tcc
意思
__p->_M_set_sharable()
に変更
(*__p)._M_set_sharable()
それでおしまい。
ファイルの変更に問題がある場合:
'readonly' オプションが設定されている (オーバーライドするために ! を追加する)
現在のユーザーに権限がない場合は、最初に sudo -i を実行して root 権限に切り替えてから変更します 直接 sudo vim を使用してファイルを開きます修正用ファイル
参考
https://blog.csdn.net/cheng_feng_xiao_zhan/article/details/53391474
RuntimeError: 拡張用のオブジェクトのコンパイル エラーは、
次の原因によっても発生する可能性があります。
解決策: エラー パスに余分なコロンがあり、環境変数の設定に問題があることを示しています。
sudo vim ~/.bashrc
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda
改的
export CUDA_HOME=/usr/local/cuda
ソース ~/.bashrc
参考:
https://blog.csdn.net/loovelj/article/details/110490986
https://www.codeleading.com/article/95735054818/
https://blog.csdn.net/zt1091574181/article/details/113611468
6.AsstributeError: 'tuple' オブジェクトに属性 'values' がありません
loss_dict を loss_dict[0] に変更します
7.RuntimeError: テンソル a (16) のサイズは、非シングルトン次元 0 でテンソル b (21) のサイズと一致する必要があります
増分学習エラー。基本的なトレーニング データをロードするときに問題が発生するはずです。オプティマイザーの値を [なし] に変更するだけです。
checkpointer_target = DetectronCheckpointer(
cfg_target, model_target, optimizer=None, scheduler=scheduler,
save_dir=output_dir_target,save_to_disk=save_to_disk, logger=logger_target)
8.インクリメンタルラーニングと直接テスト中のトレーニングはありません
基本モデルの実行回数は 40,000 で、arguments_target[“iteration”] はそのまま 40,000 です.インクリメンタル トレーニング中も 40,000 に設定しています.実行が終了したと思われる場合は、直接トレーニングできます.変更できます. 80,000までe2e_faster_rcnn_R_50_C4_1x_Target_model.yaml
。MAX_ITER: 80000 # number of iteration
ps: 複数の cuda バージョンを切り替える
/usr/local/ ディレクトリに自分でインストールした cuda のバージョンを確認する
cd /usr/local
ls
bin cuda cuda-10.2 etc include man share
cud cuda-10.1 cuda-11.0 games lib sbin src
現在の cuda バージョンを表示する
nvcc -V
または、stat cuda
現在の cuda ソフト接続を表示するために使用します
File: cuda -> /usr/local/cuda-10.1
Size: 20 Blocks: 0 IO Block: 4096 symbolic link
Device: 812h/2066d Inode: 2757665 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2022-06-06 21:34:32.342489356 +0800
Modify: 2022-05-22 15:11:26.498549390 +0800
Change: 2022-05-22 15:11:26.498549390 +0800
Birth: -
バージョン 10.2 に変更する場合は、最初に現在のリンクを削除してから 10.2 にリセットする必要があります。必要なコードは 2 行のみです。
sudo rm -rf cuda
sudo ln -s /usr/local/cuda-10.2 /usr/local/cuda
この時点でcudaのバージョンを確認してください
nvcc -V
バージョンが入れ替わっているのがわかります
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89