# 克隆、装环境
git clone git@github.com:open-mmlab/mmsegmentation.git
cd mmsegmentation
pip install -v -e .

# 进行测试
mim download mmsegmentation --config pspnet_r50-d8_512x1024_40k_cityscapes --dest .
python demo/image_demo.py demo/demo.png configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cuda:0 --out-file result.jpg
# 查看是否可以生成result.jpg
rm pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth result.jpg

# 激活环境
conda activate openmmlab

# 修改各类文件
文件修改结果请见"configs"、"mmseg"


# 训练方式
tmux new -t train
# 单卡
python tools/train.py configs/danet/my_danet_r50-d8_512x512_40k_voc12aug.py --work-dir work_dirs/my_danet_r50-d8_512x512_40k_voc12aug_class_2/
# 多卡
alg="my_danet_r50-d8_512x512_40k_voc12aug"
tag="_class_3"
mul="_mul"
mkdir ./work_dirs_mul/$alg$tag/
bash tools/dist_train.sh configs/danet/$alg.py 3 --work-dir ./work_dirs$mul/$alg$tag/ --deterministic


# 传输图片
# 背景为255
rsync -avtP -e "ssh -p 1005" /home/zub/Desktop/Seg/Pics/Label_Generate_1/* root@temp.2018xjtu.tk:/root/Seg_new/data/my_dataset/ann_dir/validation 
rsync -avtP -e "ssh -p 1005" /home/zub/Desktop/Seg/Pics/Label_Generate_1/* root@temp.2018xjtu.tk:/root/Seg_new/data/my_dataset/ann_dir/training    
# 背景为0
rsync -avtP -e "ssh -p 1005" /home/zub/Desktop/Seg/important_Pics/Label_Generate_1/* root@temp.2018xjtu.tk:/root/Seg_new/data/my_dataset/ann_dir/validation 
rsync -avtP -e "ssh -p 1005" /home/zub/Desktop/Seg/important_Pics/Label_Generate_1/* root@temp.2018xjtu.tk:/root/Seg_new/data/my_dataset/ann_dir/training
# 原始图片
rsync -avtP -e "ssh -p 1005" /home/zub/Desktop/Seg/Pics/Ori/* root@temp.2018xjtu.tk:/root/Seg_new/data/my_dataset/img_dir/validation 
rsync -avtP -e "ssh -p 1005" /home/zub/Desktop/Seg/Pics/Ori/* root@temp.2018xjtu.tk:/root/Seg_new/data/my_dataset/img_dir/training 

# 测试方式
# 单卡
XXX=iter_4000
best=best_mIoU_iter_12000
mul="" # 多卡为"_mul"
# 测试某一个模型结果
rm data/my_dataset/result/$XXX/*
mkdir -p data/my_dataset/result/$XXX/
python tools/test.py configs/danet/my_danet_r50-d8_512x512_40k_voc12aug.py \
    work_dirs$mul/my_danet_r50-d8_512x512_40k_voc12aug_class_2/$XXX.pth \
    --show-dir data/my_dataset/result/$XXX/
    # --out data/my_dataset/result
# 测试最佳模型结果
rm data/my_dataset/result/$best/*
mkdir -p data/my_dataset/result/$best/
python tools/test.py configs/danet/my_danet_r50-d8_512x512_40k_voc12aug.py \
    work_dirs$mul/my_danet_r50-d8_512x512_40k_voc12aug_class_2/$best.pth \
    --show-dir data/my_dataset/result/$best/
    # --out data/my_dataset/result

# 多卡
XXX="iter_10000"
alg="my_danet_r50-d8_512x512_40k_voc12aug"
tag="_class_3"
mul="_mul"

rm data/my_dataset/result/$alg/$XXX$tag/*
mkdir -p data/my_dataset/result/$alg/$XXX$tag/
python tools/test.py configs/danet/$alg.py \
    work_dirs$mul/$alg/$XXX.pth \
    --show-dir data/my_dataset/result/$alg/$XXX$tag/  --opacity 1
    
XXX="iter_40000"
tag_of_file="_train_199_test_Max" # _test_MAX
alg="my_danet_r50-d8_512x512_40k_voc12aug"
tag="_class_3"
mul="_mul"
# rm data/my_dataset/result/$XXX$tag_of_file/*
mkdir -p data/my_dataset/result/$XXX$tag_of_file/
python tools/test.py configs/danet/my_danet_r50-d8_512x512_40k_voc12aug.py \
    work_dirs$mul/$alg$tag/$XXX.pth \
    --show-dir data/my_dataset/result/$XXX$tag_of_file/  --opacity 1
    # --out data/my_dataset/result

tag_of_file="_train_Max_test_Max" # _test_MAX
mkdir -p data/my_dataset/result/my_danet_r50-d8_512x512_40k_voc12aug_class_309_13__02_26_$tag_of_file/
python tools/test.py configs/danet/my_danet_r50-d8_512x512_40k_voc12aug.py \
    work_dirs_mul/my_danet_r50-d8_512x512_40k_voc12aug_class_309_13__02_26/iter_40000.pth \
    --show-dir data/my_dataset/result/my_danet_r50-d8_512x512_40k_voc12aug_class_309_13__02_26_$tag_of_file/  --opacity 1
    # --out data/my_dataset/result  
    

    
