CosMix环境配置
CoSMix: Compositional Semantic Mix for Domain Adaptation in 3D LiDAR Segmentation [ECCV2022]
【已有docker, 一和二可以不看】
docker pull stoneyshi/cuda11.1-cudnn8-python3.6-pytorch1.8.1-ubuntu18.04:cosmix_pretrain
一、基础环境
Python3.8
CUDA 11.1
pytorch 1.8.0
pytorch-lightning 1.4.1
conda create -n cosmix python=3.8
conda activate cosmix
# CUDA 11.1 二选一(使用conda)
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge
# CUDA 11.1 二选一(使用pip)
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
二、其他需要的环境
2.1 MinkowskiEnginge
官网:Minkowski
(1)pip安装
sudo apt install build-essential python3-dev libopenblas-dev
pip install torch ninja
pip install -U MinkowskiEngine --install-option="--blas=openblas" -v --no-deps
# For pip installation from the latest source
# pip install -U git+https://github.com/NVIDIA/MinkowskiEngine --no-deps
其他自定义安装命令:
# Uncomment some options if things don't work
# export CXX=c++; # set this if you want to use a different C++ compiler
# export CUDA_HOME=/usr/local/cuda-11.1; # or select the correct cuda version on your system.
pip install -U git+https://github.com/NVIDIA/MinkowskiEngine -v --no-deps \
# \ # uncomment the following line if you want to force cuda installation
# --install-option="--force_cuda" \
# \ # uncomment the following line if you want to force no cuda installation. force_cuda supercedes cpu_only
# --install-option="--cpu_only" \
# \ # uncomment the following line to override to openblas, atlas, mkl, blas
# --install-option="--blas=openblas" \
(2)Conda安装
conda create -n py3-mink python=3.8
conda activate py3-mink
conda install openblas-devel -c anaconda
conda install pytorch=1.9.0 torchvision cudatoolkit=11.1 -c pytorch -c nvidia
# Install MinkowskiEngine
# Uncomment the following line to specify the cuda home. Make sure `$CUDA_HOME/nvcc --version` is 11.X
# export CUDA_HOME=/usr/local/cuda-11.1
pip install -U git+https://github.com/NVIDIA/MinkowskiEngine -v --no-deps --install-option="--blas_include_dirs=${CONDA_PREFIX}/include" --install-option="--blas=openblas"
# Or if you want local MinkowskiEngine
git clone https://github.com/NVIDIA/MinkowskiEngine.git
cd MinkowskiEngine
python setup.py install --blas_include_dirs=${CONDA_PREFIX}/include --blas=openblas
(3)检验是否装好
python
import MinkowskiEngine as ME
2.2 open3d 0.13.0
官网:open3d
pip install open3d
2.3 pytorch-lightning 1.4.1
2.4 wandb
2.5 tqdm
pip install pytorch-lightning
pip install wandb
pip install tqdm
2.6 常见报错
2.6.1 pytorch-lightning版本
pip install pytorch-lightning==1.4.1
2.6.2 torchmetrics版本
pip install torchmetrics==0.5
2.6.3 jaccard_score() got an unexpected keyword argument ‘zero_division’
在……lib/python3.7/site-packages/sklearn/metrics/_classification.py
这个文件里改两行:
Index: ml/lib/python3.7/site-packages/sklearn/metrics/_classification.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- ml/lib/python3.7/site-packages/sklearn/metrics/_classification.py (date 1593790417022)
+++ ml/lib/python3.7/site-packages/sklearn/metrics/_classification.py (date 1593790417022)
@@ -680,7 +680,7 @@
def jaccard_score(y_true, y_pred, labels=None, pos_label=1,
- average='binary', sample_weight=None):
+ average='binary', sample_weight=None, zero_division='warn'):
"""Jaccard similarity coefficient score
The Jaccard index [1], or Jaccard similarity coefficient, defined as
@@ -803,7 +803,7 @@
denominator = np.array([denominator.sum()])
jaccard = _prf_divide(numerator, denominator, 'jaccard',
- 'true or predicted', average, ('jaccard',),)
+ 'true or predicted', average, ('jaccard',), zero_division=zero_division)
if average is None:
return jaccard
if average == 'weighted':
2.6.4 SemanticKITTI路径
class SemanticKITTIDataset(BaseDataset):
def __init__(self,
version: str = 'full',
phase: str = 'train',
dataset_path: str = '/apdcdphfs/share_1594194/datasets/SemanticKITTI/dataset/sequences',
mapping_path: str = '_resources/semantic-kitti.yaml',
记得把SemanticKITTI/data/sequences
改成SemanticKITTI/dataset/sequences
2.6.5 OSError: libGL.so.1: cannot open shared object file: No such file or directory
apt-get update
apt-get install ffmpeg libsm6 libxext6 -y
三、预训练
先把数据集(SynLiDAR、SemanticKITTI)下好,然后做一些软链接
cd cosmix-uda
mkdir data
cd data
ln -s /root/data/dataset/SynLiDAR/sequences SynLiDAR
ln -s /root/syy/dataset/SemanticKITTI/dataset SemanticKITTI
3.1 先对SynLiDAR进行预训练,得到pretrained_model
model:
name: 'MinkUNet34'
in_feat_size: 1
out_classes: 19
dataset:
version: 'mini'
name: 'SynLiDAR'
dataset_path: 'data/SynLiDAR' # 注意最后不能有/
mapping_path: '_resources/synlidar_semantickitti.yaml'
target: 'SemanticKITTI'
voxel_size: 0.05
num_pts: 80000
ignore_label: -1
augment_data: true
pipeline:
epochs: 100
steps: null
gpus: [0]
precision: 32
loss: 'SoftDICELoss'
seed: 1234
save_dir: 'experiments/pretrained/synlidar/semantickitti'
validate_target: true
dataloader:
batch_size: 4
num_workers: 16
optimizer:
name: 'SGD'
lr: 0.01
scheduler:
name: 'ExponentialLR'
lightning:
check_val_every_n_epoch: 5
clear_cache_int: 1
resume_checkpoint: null
val_check_interval: 1.0
num_sanity_val_steps: 2
wandb:
run_name: 'SOURCE-WARMUP-SynLiDAR2SemanticKITTI'
project_name: 'cosmix-uda'
entity_name: 'stoneyshi'
offline: false
记得把entity_name改成自己的wandb账号名字,然后数据集路径、输入输出路径都检查一下,GPU个数检查一下。
python train_source.py --config_file configs/source/synlidar2semantickitti.yaml
3.2 下载训好的pretrained_model
现在这个SynLiDAR是小的,真正完整数据集有250+GB,所以可以直接下预训练好的模型:
SynLiDAR预训练模型
解压到cosmix-uda/pretrained_models/
这个路径下。后面调用的时候要记得改模型路径。
四、域自适应 SynLiDAR 2 SemanticKITTI
model:
name: 'MinkUNet34'
in_feat_size: 1
out_classes: 19
source_dataset:
version: 'mini'
name: 'SynLiDAR'
dataset_path: 'data/SynLiDAR'
mapping_path: '_resources/synlidar_semantickitti.yaml'
weights_path: '_weights/synlidar2semantickitti_correct.npy'
target: null
voxel_size: 0.05
num_pts: 80000
ignore_label: -1
augment_data: false
target_dataset:
version: 'full'
name: 'SemanticKITTI'
dataset_path: 'data/SemanticKITTI/sequences'
mapping_path: '_resources/semantic-kitti.yaml'
target: null
voxel_size: 0.05
num_pts: 80000
ignore_label: -1
augment_data: false
masked_dataset:
augment_data: true
augment_mask_data: true
remove_overlap: false
pipeline:
epochs: 16 # 3
steps: null
gpus: [0]
precision: 32
seed: 1234
save_dir: 'experiments/cosmix/synlidar/semantickitti'
dataloader:
train_batch_size: 3 # 16>>>3 , 2>>>24 , 3>>>16 , 4>>>12
val_batch_size: 8
num_workers: 24
optimizer:
name: 'SGD'
lr: 0.001
scheduler:
name: null
lightning:
check_val_every_n_epoch: 1
clear_cache_int: 1
resume_checkpoint: null
val_check_interval: 1.0
num_sanity_val_steps: 2
wandb:
run_name: 'CoSMix-adaptation-SynLiDAR2SemanticKITTI'
project_name: 'cosmix-uda'
entity_name: 'stoneyshi'
offline: false
adaptation:
student_checkpoint: '/root/data/mycode/cosmix-uda/pretrained_models/pretrained_models/synlidar/semantickitti/pretrained_model.ckpt'
teacher_checkpoint: '/root/data/mycode/cosmix-uda/pretrained_models/pretrained_models/synlidar/semantickitti/pretrained_model.ckpt'
filtering: 'confidence'
adaptive_weight: false
oracle_rate: 0.0
shuffle_batches: false
compositional: false
source_filtering: false
propagation: false
propagation_size: 0
weighted_sampling: true
self_paced: false
is_mix3d: false
is_mix3d_pseudo: false
selection_perc: 0.5
remove_class: null
target_confidence_th: 0.90
losses:
source_criterion: 'SoftDICELoss'
target_criterion: 'SoftDICELoss'
other_criterion: null
source_weight: 1.0
target_weight: 1.0
other_weight: 0.
momentum:
base_tau: 0.9
final_tau: 0.9
update_every: 500
To adapt with CoSMix on SynLiDAR2SemanticKITTI run
python adapt_cosmix.py --config_file configs/adaptation/synlidar2semantickitti_cosmix.yaml
五、评估及可视化
5.1 评估预训练模型
python eval.py --config_file configs/synlidar2semantickitti.yaml --resume_path PATH-TO-EXPERIMENT
用--eval_source
对源数据和--eval_target
目标数据进行评估。这会遍历PATH-TO-EXPERIMENT/checkpoints/
里的所有模型。
5.2 评估adaptation模型
python eval.py --config_file configs/config-file-of-the-experiment.yaml --resume_path PATH-TO-EXPERIMENT --is_student
--is_student
指定要评估的模型是学生模型。
可以通过添加来保存未来可视化的预测--save_predictions