Closed medalotte closed 2 years ago
Dockerfile が用意されているのでこれを使用しようと思ったが、コンテナ内に clone している ByteTrack リポジトリのコミットハッシュが古い(更新されてない)。
RUN git clone https://github.com/ifzhang/ByteTrack \
&& cd ByteTrack \
&& git checkout 3434c5e8bc6a5ae8ad530528ba8d9a431967f237 \
&& mkdir -p YOLOX_outputs/yolox_x_mix_det/track_vis \
&& sed -i 's/torch>=1.7/torch==1.9.1+cu111/g' requirements.txt \
&& sed -i 's/torchvision==0.10.0/torchvision==0.10.1+cu111/g' requirements.txt \
&& sed -i "s/'cuda'/0/g" tools/demo_track.py \
&& pip3 install pip --upgrade \
&& pip3 install -r requirements.txt -f https://download.pytorch.org/whl/torch_stable.html \
&& python3 setup.py develop \
&& pip3 install cython \
&& pip3 install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' \
&& pip3 install cython_bbox gdown \
&& ldconfig \
&& pip cache purge
https://github.com/ifzhang/ByteTrack/blob/8d52fbdf9cd03757d8dd02c0631e526d164bd726/Dockerfile#L24
&& git checkout 3434c5e8bc6a5ae8ad530528ba8d9a431967f237
を
&& git checkout 8d52fbdf9cd03757d8dd02c0631e526d164bd726
に置き換えた上で以下のコマンドでビルド、コンテナを起動した。
$ docker build -t bytetrack:latest .
(略)
$ mkdir -p pretrained && \
> mkdir -p YOLOX_outputs && \
> xhost +local: && \
> docker run --gpus all -it --rm \
> -v $PWD/pretrained:/workspace/ByteTrack/pretrained \
> -v $PWD/datasets:/workspace/ByteTrack/datasets \
> -v $PWD/YOLOX_outputs:/workspace/ByteTrack/YOLOX_outputs \
> -v /tmp/.X11-unix/:/tmp/.X11-unix:rw \
> --device /dev/video0:/dev/video0:mwr \
> --net=host \
> -e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
> -e DISPLAY=$DISPLAY \
> --privileged \
> bytetrack:latest
non-network local connections being added to access control list
=====================
== NVIDIA TensorRT ==
=====================
NVIDIA Release 21.09 (build 26679335)
NVIDIA TensorRT 8.0.3 (c) 2016-2021, NVIDIA CORPORATION. All rights reserved.
Container image (c) 2021, NVIDIA CORPORATION. All rights reserved.
https://developer.nvidia.com/tensorrt
This container image and its contents are governed by the NVIDIA Deep Learning Container License.
By pulling and using the container, you accept the terms and conditions of this license:
https://developer.nvidia.com/ngc/nvidia-deep-learning-container-license
To install Python sample dependencies, run /opt/tensorrt/python/python_setup.sh
To install the open-source samples corresponding to this TensorRT release version run /opt/tensorrt/install_opensource.sh.
To build the open source parsers, plugins, and samples for current top-of-tree on master or a different branch, run /opt/tensorrt/install_opensource.sh -b <branch>
See https://github.com/NVIDIA/TensorRT for more information.
ERROR: This container was built for NVIDIA Driver Release 470.57 or later, but
version 465.19.01 was detected and compatibility mode is UNAVAILABLE.
[[System has unsupported display driver / cuda driver combination (CUDA_ERROR_SYSTEM_DRIVER_MISMATCH) cuInit()=803]]
user@Obelisk-Desktop:/workspace/ByteTrack$
エラーが出てる。
ERROR: This container was built for NVIDIA Driver Release 470.57 or later, but version 465.19.01 was detected and compatibility mode is UNAVAILABLE.
使ってるマシンの NVIDIA Driver のバージョンが古いっぽい。
とりあえず無視して動かしてみる。
pretrained model を使って MOT20 のデータセットに対してトラッキングを動かしてみる。
データセットは https://motchallenge.net/ からダウンロードする。
wget https://motchallenge.net/data/MOT20.zip
unzip MOT20.zip
pretrained model は README.md 記載の以下からダウンロードする。
https://drive.google.com/file/d/1HX2_JpMOjOIj1Z9rJjoet9XNy_cCAs5U/view
データセットと pretrained model を配置して README.md に書いてる通り以下のコマンドを実行したが shared memory が足りないと怒られた。
$ python3 tools/track.py -f exps/example/mot/yolox_x_mix_mot20_ch.py -c pretrained/bytetrack_x_mot20.tar -b 1 -d 1 --fp16 --fuse --match_thresh 0.7 --mot20
(中略)
RuntimeError: DataLoader worker (pid 121) is killed by signal: Bus error. It is possible that dataloader's workers are out of shared memory. Please try to raise your shared memory limit.
デフォルトでコンテナに割り当てられるサイズが小さいらしい。起動時にサイズを指定してあげるといいっぽい。
https://qiita.com/gorogoroyasu/items/e71dd3c076af145c9b44
docker run
コマンドのオプションに --shm-size=8g
を付けて 8 GB 割り当てた。
$ df -h | grep shm
shm 8.0G 0 8.0G 0% /dev/shm
が、別のエラーが出た。
$ python3 tools/track.py -f exps/example/mot/yolox_x_mix_mot20_ch.py -c pretrained/bytetrack_x_mot20.tar -b 1 -d 1 --fp16 --fuse --match_thresh 0.7 --mot20
(中略)
RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.__version__ and your torchvision version with torchvision.__version__ and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.
そんな。。。
$ pip3 list --format columns | grep torch
torch 1.9.1+cu111
torch2trt 0.3.0
torchvision 0.10.1+rocm4.2
https://github.com/pytorch/vision#installation を確認する限り、
の組み合わせは合っているが、なぜか torchvision の方は +cu111
のパッケージをインストールしていない。
なぜか torchvision の方は +cu111 のパッケージをインストールしていない。
Dockerfile に問題があった。
RUN git clone https://github.com/ifzhang/ByteTrack \
&& cd ByteTrack \
&& git checkout 8d52fbdf9cd03757d8dd02c0631e526d164bd726 \
&& mkdir -p YOLOX_outputs/yolox_x_mix_det/track_vis \
&& sed -i 's/torch>=1.7/torch==1.9.1+cu111/g' requirements.txt \
&& sed -i 's/torchvision==0.10.0/torchvision==0.10.1+cu111/g' requirements.txt \
&& sed -i "s/'cuda'/0/g" tools/demo_track.py \
&& pip3 install pip --upgrade \
&& pip3 install -r requirements.txt -f https://download.pytorch.org/whl/torch_stable.html \
&& python3 setup.py develop \
&& pip3 install cython \
&& pip3 install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' \
&& pip3 install cython_bbox gdown \
&& ldconfig \
&& pip cache purge
だが、 requirements.txt
を確認すると、
torchvision>=0.10.0
と書かれている。 sed
がマッチングしてない。。。
あとで PR を出す。
https://github.com/Vertical-Beach/ai-edge-contest-5/issues/9#issuecomment-997967919 の問題を解決するように Dockerfile を書き直した。
Dockerfile の修正は以下の2箇所となった。
diff --git a/Dockerfile b/Dockerfile
index 1848e1f..deff2e2 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -21,10 +21,10 @@ RUN apt-get update && apt-get install -y \
RUN git clone https://github.com/ifzhang/ByteTrack \
&& cd ByteTrack \
- && git checkout 3434c5e8bc6a5ae8ad530528ba8d9a431967f237 \
+ && git checkout 8d52fbdf9cd03757d8dd02c0631e526d164bd726 \
&& mkdir -p YOLOX_outputs/yolox_x_mix_det/track_vis \
&& sed -i 's/torch>=1.7/torch==1.9.1+cu111/g' requirements.txt \
- && sed -i 's/torchvision==0.10.0/torchvision==0.10.1+cu111/g' requirements.txt \
+ && sed -i 's/torchvision>=0.10.0/torchvision==0.10.1+cu111/g' requirements.txt \
&& sed -i "s/'cuda'/0/g" tools/demo_track.py \
&& pip3 install pip --upgrade \
&& pip3 install -r requirements.txt -f https://download.pytorch.org/whl/torch_stable.html \
この状態で ByteTrack が動作することを確認した。
$ python3 tools/track.py -f exps/example/mot/yolox_x_mix_mot20_ch.py -c pretrained/bytetrack_x_mot20.tar -b 1 -d 1 --fp16 --fuse --match_thresh 0.7 --mot20
2021-12-20 15:01:59 | INFO | __main__:154 - Args: Namespace(batch_size=1, ckpt='pretrained/bytetrack_x_mot20.tar', conf=0.01, devices=1, dist_backend='nccl', dist_url=None, exp_file='exps/example/mot/yolox_x_mix_mot20_ch.py', experiment_name='yolox_x_mix_mot20_ch', fp16=True, fuse=True, local_rank=0, machine_rank=0, match_thresh=0.7, min_box_area=100, mot20=True, name=None, nms=0.7, num_machines=1, opts=[], seed=None, speed=False, test=False, track_buffer=30, track_thresh=0.6, trt=False, tsize=None)
2021-12-20 15:01:59 | INFO | __main__:164 - Model Summary: Params: 99.00M, Gflops: 985.27
2021-12-20 15:01:59 | INFO | yolox.data.datasets.mot:39 - loading annotations into memory...
2021-12-20 15:01:59 | INFO | yolox.data.datasets.mot:39 - Done (t=0.02s)
2021-12-20 15:01:59 | INFO | pycocotools.coco:88 - creating index...
2021-12-20 15:01:59 | INFO | pycocotools.coco:88 - index created!
2021-12-20 15:02:01 | INFO | __main__:186 - loading checkpoint
2021-12-20 15:02:01 | INFO | __main__:191 - loaded checkpoint done.
2021-12-20 15:02:01 | INFO | __main__:197 - Fusing model...
/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py:561: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the gradient for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more information.
if param.grad is not None:
46%|####6 | 2079/4479 [02:29<03:05, 12.93it/s]2021-12-20 15:04:37 | INFO | yolox.evaluators.mot_evaluator:39 - save results to ./YOLOX_outputs/yolox_x_mix_mot20_ch/track_results/MOT20-04.txt
69%|######8 | 3087/4479 [03:49<01:40, 13.87it/s]2021-12-20 15:05:54 | INFO | yolox.evaluators.mot_evaluator:39 - save results to ./YOLOX_outputs/yolox_x_mix_mot20_ch/track_results/MOT20-06.txt
82%|########2 | 3673/4479 [04:31<00:53, 15.06it/s]2021-12-20 15:06:34 | INFO | yolox.evaluators.mot_evaluator:39 - save results to ./YOLOX_outputs/yolox_x_mix_mot20_ch/track_results/MOT20-07.txt
100%|##########| 4479/4479 [05:32<00:00, 3.42it/s]2021-12-20 15:07:34 | INFO | yolox.evaluators.mot_evaluator:39 - save results to ./YOLOX_outputs/yolox_x_mix_mot20_ch/track_results/MOT20-08.txt
100%|##########| 4479/4479 [05:32<00:00, 13.47it/s]
2021-12-20 15:07:34 | INFO | yolox.evaluators.mot_evaluator:631 - Evaluate in main process...
2021-12-20 15:07:42 | INFO | yolox.evaluators.mot_evaluator:660 - Loading and preparing results...
2021-12-20 15:07:45 | INFO | yolox.evaluators.mot_evaluator:660 - DONE (t=3.01s)
2021-12-20 15:07:45 | INFO | pycocotools.coco:363 - creating index...
2021-12-20 15:07:45 | INFO | pycocotools.coco:363 - index created!
Running per image evaluation...
Evaluate annotation type *bbox*
COCOeval_opt.evaluate() finished in 1.77 seconds.
Accumulating evaluation results...
COCOeval_opt.accumulate() finished in 0.15 seconds.
2021-12-20 15:07:47 | INFO | __main__:218 -
Average forward time: 57.09 ms, Average track time: 12.25 ms, Average inference time: 69.34 ms
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000
gt_type
gt_files ['datasets/MOT20/train/MOT20-02/gt/gt.txt', 'datasets/MOT20/train/MOT20-05/gt/gt.txt', 'datasets/MOT20/train/MOT20-03/gt/gt.txt', 'datasets/MOT20/train/MOT20-01/gt/gt.txt']
2021-12-20 15:07:47 | INFO | __main__:235 - Found 4 groundtruths and 4 test files.
2021-12-20 15:07:47 | INFO | __main__:236 - Available LAP solvers ['lap', 'scipy']
2021-12-20 15:07:47 | INFO | __main__:237 - Default LAP solver 'lap'
2021-12-20 15:07:47 | INFO | __main__:238 - Loading files.
2021-12-20 15:08:00 | WARNING | __main__:122 - No ground truth for MOT20-04, skipping.
2021-12-20 15:08:00 | WARNING | __main__:122 - No ground truth for MOT20-06, skipping.
2021-12-20 15:08:00 | WARNING | __main__:122 - No ground truth for MOT20-07, skipping.
2021-12-20 15:08:00 | WARNING | __main__:122 - No ground truth for MOT20-08, skipping.
2021-12-20 15:08:00 | INFO | __main__:246 - Running metrics
Rcll Prcn GT MT PT ML FP FN IDs FM MOTA MOTP num_objects
OVERALL NaN NaN 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN 0
IDF1 IDP IDR Rcll Prcn GT MT PT ML FP FN IDs FM MOTA MOTP IDt IDa IDm num_objects
OVERALL NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0 NaN NaN 0 0 0 0
2021-12-20 15:08:00 | INFO | __main__:271 - Completed
tools/track.py
を実行してもトラッキング結果がファイル出力されるだけで可視化されない。
tools/demo_track.py
を実行するとトラッキングが実行された上で可視化結果 (.mp4) が出力される。
$ python3 tools/demo_track.py video -f exps/example/mot/yolox_x_mix_mot20_ch.py -c pretrained/bytetrack_x_mot20.tar --fp16 --fuse --save_result
2021-12-20 15:15:18.116 | INFO | __main__:main:316 - Args: Namespace(aspect_ratio_thresh=1.6, camid=0, ckpt='pretrained/bytetrack_x_mot20.tar', conf=None, demo='video', device=device(type='cuda'), exp_file='exps/example/mot/yolox_x_mix_mot20_ch.py', experiment_name='yolox_x_mix_mot20_ch', fp16=True, fps=30, fuse=True, match_thresh=0.8, min_box_area=10, mot20=False, name=None, nms=None, path='./videos/palace.mp4', save_result=True, track_buffer=30, track_thresh=0.5, trt=False, tsize=None)
2021-12-20 15:15:20.795 | INFO | __main__:main:326 - Model Summary: Params: 99.00M, Gflops: 985.27
2021-12-20 15:15:20.797 | INFO | __main__:main:334 - loading checkpoint
2021-12-20 15:15:21.130 | INFO | __main__:main:338 - loaded checkpoint done.
2021-12-20 15:15:21.130 | INFO | __main__:main:341 - Fusing model...
/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py:561: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the gradient for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more information.
if param.grad is not None:
2021-12-20 15:15:21.622 | INFO | __main__:imageflow_demo:248 - video save_path is ./YOLOX_outputs/yolox_x_mix_mot20_ch/track_vis/2021_12_20_15_15_21/palace.mp4
2021-12-20 15:15:21.623 | INFO | __main__:imageflow_demo:258 - Processing frame 0 (100000.00 fps)
2021-12-20 15:15:24.068 | INFO | __main__:imageflow_demo:258 - Processing frame 20 (17.77 fps)
2021-12-20 15:15:26.482 | INFO | __main__:imageflow_demo:258 - Processing frame 40 (18.02 fps)
2021-12-20 15:15:28.899 | INFO | __main__:imageflow_demo:258 - Processing frame 60 (18.05 fps)
2021-12-20 15:15:31.321 | INFO | __main__:imageflow_demo:258 - Processing frame 80 (18.04 fps)
2021-12-20 15:15:33.734 | INFO | __main__:imageflow_demo:258 - Processing frame 100 (18.07 fps)
2021-12-20 15:15:36.141 | INFO | __main__:imageflow_demo:258 - Processing frame 120 (18.08 fps)
2021-12-20 15:15:38.546 | INFO | __main__:imageflow_demo:258 - Processing frame 140 (18.09 fps)
2021-12-20 15:15:40.959 | INFO | __main__:imageflow_demo:258 - Processing frame 160 (18.06 fps)
2021-12-20 15:15:43.366 | INFO | __main__:imageflow_demo:258 - Processing frame 180 (18.06 fps)
2021-12-20 15:15:45.783 | INFO | __main__:imageflow_demo:258 - Processing frame 200 (18.04 fps)
2021-12-20 15:15:48.195 | INFO | __main__:imageflow_demo:258 - Processing frame 220 (18.03 fps)
2021-12-20 15:15:50.610 | INFO | __main__:imageflow_demo:258 - Processing frame 240 (18.02 fps)
2021-12-20 15:15:53.049 | INFO | __main__:imageflow_demo:258 - Processing frame 260 (18.00 fps)
2021-12-20 15:15:55.484 | INFO | __main__:imageflow_demo:258 - Processing frame 280 (17.98 fps)
2021-12-20 15:15:57.928 | INFO | __main__:imageflow_demo:258 - Processing frame 300 (17.96 fps)
2021-12-20 15:16:00.366 | INFO | __main__:imageflow_demo:258 - Processing frame 320 (17.93 fps)
2021-12-20 15:16:01.459 | INFO | __main__:imageflow_demo:298 - save results to ./YOLOX_outputs/yolox_x_mix_mot20_ch/track_vis/2021_12_20_15_15_21.txt
ByteTrack の公開実装を動かしてみる。
ここでは 2021/12/19 時点の main ブランチの HEAD (8d52fbdf) で確認を行う。
https://github.com/ifzhang/ByteTrack/tree/8d52fbdf9cd03757d8dd02c0631e526d164bd726