1.安装cuda和cudnn
注意不要用pytorch自带的免安装cuda和cudnn,因为在trackformer代码中需要调用CUDA_HOME,如果免安装,会导致CUDA_HOME为NONE,参考这篇博客,安装cuda和cudnn。
2.配置python环境
建议使用python3.7,我使用3.8的时候遇到一些版本问题,在github上trackformer的Issues栏中同样有人询问,用3.7和3.9均可复现,作者建议3.7版本。
conda create -n Trackformer python=3.7 -y
3.安装Pytorch
我的cuda版本是11.7。参考这篇博客安装各自对应版本。
4.下载项目
5.配置环境和工具
(1)安装requirements.txt
pip install -r requirements.txt
报错显示failed building wheel for lapsolver;
运行以下代码,安装cmake后再安装lapsolver
pip install cmake
pip install lapsolver==1.1.0
(2)安装pycocotools
pip install pycocotools
(3)安装gcc编译器
参考这篇博客
(4)安装ffmpeg
参考这篇博客
(5)安装MultiScaleDeformableAttention
python src/trackformer/models/ops/setup.py build --build-base=src/trackformer/models/ops/ install
(6)下载预训练文件
点击这里,下载trackformer_models_v1.zip文件,解压,将mot17_crowdhuman_deformable_multi_frame文件移动到Trackformer工程models文件夹下
6.将视频转换为图片
ffmpeg -i data/snakeboard/snakeboard.mp4 -vf fps=30 data/snakeboard/%06d.png
7.开始检测
python src/track.py with dataset_name=DEMO data_root_dir=data/snakeboard output_dir=data/snakeboard write_images=pretty
(1)报错及解决
报错a:ImportError: Bad git executable.
解决:点击进入git\cmd.py,在22行左右插入以下代码
os.environ['GIT_PYTHON_REFRESH'] = 'quiet'
报错b:NotImplementedError: cannot instantiate 'PosixPath' on your system
解决:作者是在Linux上进行训练的,不同操作系统处理路径的方式有差异,修改代码。
点击进入pathlib.py修改1030行左右的代码
def __new__(cls, *args, **kwargs):
# 源码
# if cls is Path:
# cls = WindowsPath if os.name == 'nt' else PosixPath
# self = cls._from_parts(args, init=False)
# if not self._flavour.is_supported:
# raise NotImplementedError("cannot instantiate %r on your system"
# % (cls.__name__,))
# self._init()
# return self
# 修改
if cls is Path:
# cls = WindowsPath if os.name == 'nt' else PosixPath
cls = WindowsPath
self = cls._from_parts(args, init=False)
# Windows doesn't support PosixPath
if type(self) == PosixPath:
cls = WindowsPath
self = cls._from_parts(args, init=False)
if not self._flavour.is_supported:
raise NotImplementedError("cannot instantiate %r on your system"
% (cls.__name__,))
self._init()
return self