MMTracking は, OpenMMLab の構成物で,トラッキング・ビジョンの機能を提供する.
Windows での Git のインストール: 別ページ »で説明
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
Windows での Python 3.10,関連パッケージ,Python 開発環境のインストール: 別ページ »で説明
【サイト内の関連ページ】
Python のまとめ: 別ページ »にまとめ
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
Windows での Build Tools for Visual Studio 2022,NVIDIA ドライバ,NVIDIA CUDA ツールキット 11.8,NVIDIA cuDNN v8.6 のインストールと動作確認: 別ページ »で説明
【関連する外部ページ】
コマンドプロンプトを管理者として実行: 別ページ »で説明
PyTorch のページ: https://pytorch.org/index.html
次のコマンドは, PyTorch 2.0 (NVIDIA CUDA 11.8 用) をインストールする. 事前に NVIDIA CUDA のバージョンを確認しておくこと(ここでは,NVIDIA CUDA ツールキット 11.8 が前もってインストール済みであるとする).
PyTorch で,GPU が動作している場合には,「torch.cuda.is_available()」により,True が表示される.
python -m pip install -U pip python -m pip install -U torch torchvision torchaudio numpy --index-url https://download.pytorch.org/whl/cu118 python -c "import torch; print(torch.__version__, torch.cuda.is_available())"
コマンドプロンプトを管理者として実行: 別ページ »で説明
python -c "import torch; TORCH_VERSION = '.'.join(torch.__version__.split('.')[:2]); print(TORCH_VERSION)"
このとき,実際には 11.8 をインストールしているのに,「cu117」のように古いバージョンが表示されることがある.このような場合は,気にせずに続行する.
python -c "import torch; CUDA_VERSION = torch.__version__.split('+')[-1]; print(CUDA_VERSION)"
インストール手順は, https://mmcv.readthedocs.io/en/latest/get_started/installation.html に記載の手順による
python -m pip install -U --ignore-installed pip python -m pip uninstall -y openmim mmcv mmcv-full opencv-python opencv-python-headless python -m pip install -U openmim opencv-python cd %HOMEPATH% rmdir /s /q mmtracking git clone https://github.com/open-mmlab/mmtracking.git cd mmtracking mim uninstall -y mmtrack pip install -r requirements.txt mim install -e . python -m pip install -U --ignore-installed --no-cache-dir numpy mim list
python -m pip install git+https://github.com/JonathonLuiten/TrackEval.git
コマンドプロンプトを管理者として実行: 別ページ »で説明
次のコマンドを実行する.
cd %HOMEPATH%\mmtracking mkdir checkpoints cd checkpoints curl -O https://download.openmmlab.com/mmtracking/vid/selsa/selsa_faster_rcnn_r50_dc5_1x_imagenetvid/selsa_faster_rcnn_r50_dc5_1x_imagenetvid_20201227_204835-2f5a4952.pth curl -O https://download.openmmlab.com/mmtracking/sot/siamese_rpn/siamese_rpn_r50_1x_lasot/siamese_rpn_r50_1x_lasot_20211203_151612-da4b3c66.pth curl -O https://download.openmmlab.com/mmtracking/vis/masktrack_rcnn/masktrack_rcnn_r50_fpn_12e_youtubevis2019/masktrack_rcnn_r50_fpn_12e_youtubevis2019_20211022_194830-6ca6b91e.pth
次の Python プログラムを実行する.mmcv を用いた表示を行うので,Jupyter QtConsole や Jupyter ノートブック (Jupyter Notebook) の利用が便利である.
Python プログラムは,公式ページhttps://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb のものを書き換えて使用.
下図では,Python プログラムの実行のため,jupyter qtconsole を使用している.
import os import mmcv import tempfile from mmtrack.apis import inference_mot, init_model os.chdir((os.getenv('HOMEPATH') + '\\' + 'mmtracking')) mot_config = './configs/mot/deepsort/deepsort_faster-rcnn_fpn_4e_mot17-private-half.py' input_video = './demo/demo.mp4' imgs = mmcv.VideoReader(input_video) # build the model from a config file mot_model = init_model(mot_config, device='cuda:0') prog_bar = mmcv.ProgressBar(len(imgs)) out_dir = tempfile.TemporaryDirectory() out_path = out_dir.name # test and show/save the images for i, img in enumerate(imgs): result = inference_mot(mot_model, img, frame_id=i) mot_model.show_result( img, result, show=False, wait_time=int(1000. / imgs.fps), out_file=f'{out_path}/{i:06d}.jpg') prog_bar.update() output = './demo/mot.mp4' print(f'\n making the output video at {output} with a FPS of {imgs.fps}') mmcv.frames2video(out_path, output, fps=imgs.fps, fourcc='mp4v') out_dir.cleanup()
./demo/mot.mp4 を表示.
次の Python プログラムを実行する.mmcv を用いた表示を行うので,Jupyter QtConsole や Jupyter ノートブック (Jupyter Notebook) の利用が便利である.
Python プログラムは,公式ページhttps://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb のものを書き換えて使用.
下図では,Python プログラムの実行のため,jupyter qtconsole を使用している.
import os import mmcv import tempfile from mmtrack.apis import inference_mot, init_model os.chdir((os.getenv('HOMEPATH') + '\\' + 'mmtracking')) vis_config = './configs/vis/masktrack_rcnn/masktrack_rcnn_r50_fpn_12e_youtubevis2019.py' vis_checkpoint = './checkpoints/masktrack_rcnn_r50_fpn_12e_youtubevis2019_20211022_194830-6ca6b91e.pth' # build the model from a config file and a checkpoint file vis_model = init_model(vis_config, vis_checkpoint, device='cuda:0') input_video = './demo/demo.mp4' imgs = mmcv.VideoReader(input_video) prog_bar = mmcv.ProgressBar(len(imgs)) out_dir = tempfile.TemporaryDirectory() out_path = out_dir.name for i, img in enumerate(imgs): result = inference_mot(vis_model, img, frame_id=i) vis_model.show_result( img, result, wait_time=int(1000. / imgs.fps), out_file=f'{out_path}/{i:06d}.jpg') prog_bar.update() output = './demo/vis.mp4' print(f'\n making the output video at {output} with a FPS of {imgs.fps}') mmcv.frames2video(out_path, output, fps=imgs.fps, fourcc='mp4v') out_dir.cleanup()
./demo/vis.mp4 を表示.
次の Python プログラムを実行する.mmcv を用いた表示を行うので,Jupyter QtConsole や Jupyter ノートブック (Jupyter Notebook) の利用が便利である.
Python プログラムは,公式ページhttps://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb のものを書き換えて使用.
下図では,Python プログラムの実行のため,jupyter qtconsole を使用している.
import os import mmcv import tempfile from mmtrack.apis import inference_vid, init_model os.chdir((os.getenv('HOMEPATH') + '\\' + 'mmtracking')) vid_config = './configs/vid/selsa/selsa_faster_rcnn_r50_dc5_1x_imagenetvid.py' vid_checkpoint = './checkpoints/selsa_faster_rcnn_r50_dc5_1x_imagenetvid_20201227_204835-2f5a4952.pth' # build the model from a config file and a checkpoint file vid_model = init_model(vid_config, vid_checkpoint, device='cuda:0') input_video = './demo/demo.mp4' imgs = mmcv.VideoReader(input_video) prog_bar = mmcv.ProgressBar(len(imgs)) out_dir = tempfile.TemporaryDirectory() out_path = out_dir.name for i, img in enumerate(imgs): result = inference_vid(vid_model, img, frame_id=i) vid_model.show_result( img, result, wait_time=int(1000. / imgs.fps), out_file=f'{out_path}/{i:06d}.jpg') prog_bar.update() output = './demo/vid.mp4' print(f'\n making the output video at {output} with a FPS of {imgs.fps}') mmcv.frames2video(out_path, output, fps=imgs.fps, fourcc='mp4v') out_dir.cleanup()
./demo/vid.mp4 を表示.
次の Python プログラムを実行する.mmcv を用いた表示を行うので,Jupyter QtConsole や Jupyter ノートブック (Jupyter Notebook) の利用が便利である.
Python プログラムは,公式ページhttps://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb のものを書き換えて使用.
下図では,Python プログラムの実行のため,jupyter qtconsole を使用している.
import os import mmcv import tempfile from mmtrack.apis import inference_sot, init_model os.chdir((os.getenv('HOMEPATH') + '\\' + 'mmtracking')) sot_config = './configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py' sot_checkpoint = './checkpoints/siamese_rpn_r50_1x_lasot_20211203_151612-da4b3c66.pth' # build the model from a config file and a checkpoint file sot_model = init_model(sot_config, sot_checkpoint, device='cuda:0') init_bbox = [371, 411, 450, 646] input_video = './demo/demo.mp4' imgs = mmcv.VideoReader(input_video) prog_bar = mmcv.ProgressBar(len(imgs)) out_dir = tempfile.TemporaryDirectory() out_path = out_dir.name for i, img in enumerate(imgs): result = inference_sot(sot_model, img, init_bbox, frame_id=i) sot_model.show_result( img, result, wait_time=int(1000. / imgs.fps), out_file=f'{out_path}/{i:06d}.jpg') prog_bar.update() output = './demo/sot.mp4' print(f'\n making the output video at {output} with a FPS of {imgs.fps}') mmcv.frames2video(out_path, output, fps=imgs.fps, fourcc='mp4v') out_dir.cleanup()
./demo/sot.mp4 を表示.