Meta Byte Track
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # ByteTrack-CPP-ncnn
  2. ## Installation
  3. Clone [ncnn](https://github.com/Tencent/ncnn) first, then please following [build tutorial of ncnn](https://github.com/Tencent/ncnn/wiki/how-to-build) to build on your own device.
  4. Install eigen-3.3.9 [[google]](https://drive.google.com/file/d/1rqO74CYCNrmRAg8Rra0JP3yZtJ-rfket/view?usp=sharing), [[baidu(code:ueq4)]](https://pan.baidu.com/s/15kEfCxpy-T7tz60msxxExg).
  5. ```shell
  6. unzip eigen-3.3.9.zip
  7. cd eigen-3.3.9
  8. mkdir build
  9. cd build
  10. cmake ..
  11. sudo make install
  12. ```
  13. ## Generate onnx file
  14. Use provided tools to generate onnx file.
  15. For example, if you want to generate onnx file of bytetrack_s_mot17.pth, please run the following command:
  16. ```shell
  17. cd <ByteTrack_HOME>
  18. python3 tools/export_onnx.py -f exps/example/mot/yolox_s_mix_det.py -c pretrained/bytetrack_s_mot17.pth.tar
  19. ```
  20. Then, a bytetrack_s.onnx file is generated under <ByteTrack_HOME>.
  21. ## Generate ncnn param and bin file
  22. Put bytetrack_s.onnx under ncnn/build/tools/onnx and then run:
  23. ```shell
  24. cd ncnn/build/tools/onnx
  25. ./onnx2ncnn bytetrack_s.onnx bytetrack_s.param bytetrack_s.bin
  26. ```
  27. Since Focus module is not supported in ncnn. Warnings like:
  28. ```shell
  29. Unsupported slice step !
  30. ```
  31. will be printed. However, don't worry! C++ version of Focus layer is already implemented in src/bytetrack.cpp.
  32. ## Modify param file
  33. Open **bytetrack_s.param**, and modify it.
  34. Before (just an example):
  35. ```
  36. 235 268
  37. Input images 0 1 images
  38. Split splitncnn_input0 1 4 images images_splitncnn_0 images_splitncnn_1 images_splitncnn_2 images_splitncnn_3
  39. Crop Slice_4 1 1 images_splitncnn_3 467 -23309=1,0 -23310=1,2147483647 -23311=1,1
  40. Crop Slice_9 1 1 467 472 -23309=1,0 -23310=1,2147483647 -23311=1,2
  41. Crop Slice_14 1 1 images_splitncnn_2 477 -23309=1,0 -23310=1,2147483647 -23311=1,1
  42. Crop Slice_19 1 1 477 482 -23309=1,1 -23310=1,2147483647 -23311=1,2
  43. Crop Slice_24 1 1 images_splitncnn_1 487 -23309=1,1 -23310=1,2147483647 -23311=1,1
  44. Crop Slice_29 1 1 487 492 -23309=1,0 -23310=1,2147483647 -23311=1,2
  45. Crop Slice_34 1 1 images_splitncnn_0 497 -23309=1,1 -23310=1,2147483647 -23311=1,1
  46. Crop Slice_39 1 1 497 502 -23309=1,1 -23310=1,2147483647 -23311=1,2
  47. Concat Concat_40 4 1 472 492 482 502 503 0=0
  48. ...
  49. ```
  50. * Change first number for 235 to 235 - 9 = 226(since we will remove 10 layers and add 1 layers, total layers number should minus 9).
  51. * Then remove 10 lines of code from Split to Concat, but remember the last but 2nd number: 503.
  52. * Add YoloV5Focus layer After Input (using previous number 503):
  53. ```
  54. YoloV5Focus focus 1 1 images 503
  55. ```
  56. After(just an exmaple):
  57. ```
  58. 226 328
  59. Input images 0 1 images
  60. YoloV5Focus focus 1 1 images 503
  61. ...
  62. ```
  63. ## Use ncnn_optimize to generate new param and bin
  64. ```shell
  65. # suppose you are still under ncnn/build/tools/onnx dir.
  66. ../ncnnoptimize bytetrack_s.param bytetrack_s.bin bytetrack_s_op.param bytetrack_s_op.bin 65536
  67. ```
  68. ## Copy files and build ByteTrack
  69. Copy or move 'src', 'include' folders and 'CMakeLists.txt' file into ncnn/examples. Copy bytetrack_s_op.param, bytetrack_s_op.bin and <ByteTrack_HOME>/videos/palace.mp4 into ncnn/build/examples. Then, build ByteTrack:
  70. ```shell
  71. cd ncnn/build/examples
  72. cmake ..
  73. make
  74. ```
  75. ## Run the demo
  76. You can run the ncnn demo with **5 FPS** (96-core Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz):
  77. ```shell
  78. ./bytetrack palace.mp4
  79. ```
  80. You can modify 'num_threads' to optimize the running speed in [bytetrack.cpp](https://github.com/ifzhang/ByteTrack/blob/2e9a67895da6b47b948015f6861bba0bacd4e72f/deploy/ncnn/cpp/src/bytetrack.cpp#L309) according to the number of your CPU cores:
  81. ```
  82. yolox.opt.num_threads = 20;
  83. ```
  84. ## Acknowledgement
  85. * [ncnn](https://github.com/Tencent/ncnn)