WXL's blog

Talk is cheap, show me your work.

0%

安装pytorch_lightning

安装pytorch-lightning本是一件很容易的事情,随便一查都是一个指令:

1
pip install pytorch-lightning

但是,我之前所使用的torch是1.6版本的,官方最低支持的是torch1.7版本的:

参考链接:https://github.com/PyTorchLightning/pytorch-lightning#continuous-integration

所以我需要重新弄一个torch1.8版本的环境,并重新安装之前的所有包。

创建虚拟环境

创建一个python为3.7版本的环境:

1
conda create -n torch18 python=3.7

安装pytorch

我的CUDA版本为10.2,就装一个10.2版本的torch吧:

1
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch

安装torchreid

1
2
3
4
5
6
7
8
# 先安装Cython,scipy,numpy,tensorboard
conda install Cython scipy numpy tensorboard
# 安装opencv-python,gdown
pip install opencv-python gdown
# 安装torch reid
git clone https://github.com/KaiyangZhou/deep-person-reid.git
cd deep-person-reid/
python setup.py develop

安装torch-sparse,torch-scatter,torch-cluster

参考这篇博客:torch-sparse,torch-scatter,torch-cluster的安装

注意,安装完torch-scatter,torch-sparse,torch-cluster了之后,不要使用pip install torch-geometric,使用如下指令安装:

1
conda install pyg -c pyg -c conda-forge

参考:https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html

安装pytorch-lightning

1
pip install pytorch-lightning

安装lapsolver

1
2
3
4
5
6
7
8
9
10
11
# 先安装pytest-runner
conda install pytest-runner
# 安装cmake
pip install cmake
# 克隆源码
git clone --recursive https://github.com/cheind/py-lapsolver.git
cd py-lapsolver
# build
python setup.py develop
# test:
python setup.py test

其他

1
2
3
4
5
pip install scikit-image
conda install GitPython
pip install sacred
pip install motmetrics
pip install pulp

安装tracking_wo_bnw:

1
2
3
git clone https://github.com/phil-bergmann/tracking_wo_bnw
cd tracking_wo_bnw
pip3 install -e .

修改文件:

tracktor.datasets.factory.py

tracktor.datasets.mot15_sequence.py

tracktor.datasets.mot_sequence.py

tracktor.datasets.mot_wrapper.py

遇到的问题

安装完毕之后,我有这样一段代码:

1
2
3
4
5
6
7
import pytorch-lightning as pl

class Net(pl.LightningModule):
def __init__(self, **hparams):
super().__init__()
self.hparams = hparams
print(self.hparams)

报错:

1
2
3
4
5
  File "xxx", line xx, in __init__
self.hparams = hparams
File "xxx", line xx, in __setattr__
object.__setattr__(self, name, value)
AttributeError: can't set attribute

解决方法:

self.hparams=hparams换为self.hparams.update(hparams)

参考:

https://github.com/PyTorchLightning/pytorch-lightning/discussions/7525

行行好,赏一杯咖啡吧~