1. 在永丰服务器上部署环境
1️⃣ 在 /data 下准备目录
mkdir -p /data/ccsun cd /data/ccsun
2️⃣ 下载并安装 Miniconda(不碰 /)
wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.12.0-Linux-x86_64.sh
bash Miniconda3-py38_4.12.0-Linux-x86_64.sh
当安装器问你:
Miniconda3 will now be installed into this location:
👉 一定要手动输入:
/data/ccsun/miniconda3
⚠️ 不要用默认路径(默认会去 $HOME,很可能在 /)
3️⃣ 初始化 conda(仅对你自己)
/data/ccsun/miniconda3/bin/conda init source ~/.bashrc
验证:
which conda
应该看到:
/data/ccsun/miniconda3/bin/conda
2、pip 也要确认写到 /data(很关键)
1️⃣ 确认 pip 路径
which pip
应该是:
/data/ccsun/miniconda3/envs/segman/bin/pip
如果不是,不要继续安装。
2️⃣ pip 安装 segman 相关依赖(安全)
pip install --no-cache-dir torch torchvision pip install --no-cache-dir mmcv-full pip install --no-cache-dir mmsegmentation
--no-cache-dir 的作用是:
-
避免 pip 把缓存写到 ~/.cache(通常在
/)
✅ Step 1:强制把 NumPy 降级到 1.x(必须)
推荐版本:1.26.4(最稳)
pip uninstall -y numpy pip install numpy==1.26.4 \ --no-cache-dir \ -i https://pypi.org/simple
验证:
python - << 'EOF' import numpy print(numpy.__version__) EOF
应输出:
1.26.4
3️⃣ 用命令行参数强制覆盖清华源(关键)
⚠️ 注意:这一步必须写完整
pip install torch==2.1.2 torchvision==0.16.2 \ --no-cache-dir \ --index-url https://pypi.org/simple \ --extra-index-url https://download.pytorch.org/whl/cu118
后续所有安装都照这个模板(非常重要)
openmim
pip install -U openmim \ --no-cache-dir \ --index-url https://pypi.org/simple
mmcv-full
mim install mmcv-full \ --index-url https://pypi.org/simple \ --extra-index-url https://download.openmmlab.com/mmcv/dist/cu118/torch2.1
natten
pip install natten==0.17.3+torch210cu118 \ --no-cache-dir \ --index-url https://pypi.org/simple \ --extra-index-url https://natten-wheel.s3.amazonaws.com
3. 当网络不好时,强制使用清华源创建conda环境
conda create -n segman python=3.10 \
-c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main \
--override-channels
conda activate segman
安装torch2.1.2+cuda11.8
如果服务器无法连接外网,登录,download.pytorch.org/whl/torch_stable.html
找到/cu118/ 里面的的 _Linux_x86_64 .whl
torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2下载下来
进入你上传的目录cd后挨个安装:
pip install torch-2.1.2+cu118-cp310-cp310-linux_x86_64.whl
pip install -U openmim
mim install mmcv-full
或者是/ mim install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.1.2/index.html
pip install -v -e .
安装Natten
可以在任意一台能正常访问外网的电脑(Windows/macOS/Linux 都可以)手动下载 .whl 文件。浏览器直接下载(最简单)
复制链接,直接粘贴进浏览器地址栏:
natten Index of packages: https://shi-labs.com/natten/wheels/
浏览器会自动下载 .whl 文件(虽然打开是乱码,但下载下来是对的)。
如果浏览器直接显示乱码,不触发下载:右键 → 另存为 → 保存为 .whl。
上传完成后,在服务器安装,进入你上传的目录cd后安装:
pip install natten-0.17.3+torch210cu118-cp310-cp310-linux_x86_64.whl
To support torch>=2.1.0, you also need to import from packaging import version and replace Line 75 of /miniconda3/envs/segman/lib/python3.10/site-packages/mmcv/parallel/_functions.py with the following:
if version.parse(torch.__version__) >= version.parse('2.1.0'):
streams = [_get_stream(torch.device("cuda", device)) for device in target_gpus]
else:
streams = [_get_stream(device) for device in target_gpus]
cd kernels/selective_scan && pip install . --no-build-isolation
cd至项目目录
pip install -r requirements.txt
二、
1.3.1修改数据集配置
(1)在mmseg/datasets目录下找到postdam.py,这是对应于postdam数据集的类文件,直接将其复制一份,新命名为mydataset.py或者其他名字(我这里是ganzhe_dataset.py)
在ganzhe_dataset.py中修改类名、分类信息、数据集图片后缀、是否忽略0标签这四个地方,由于我的数据集只需要对背景和甘蔗这两个类别进行分割,所以只需要写两个类即可。不同的数据集对应着不同的类,要修改的地方都是大同小异,针对postdam这个数据类会配置以后就可以举一反三。
注意:是否忽略0标签(reduce_zero_label)这个参数,该参数设置为true后,数值为0的标签(通常设置为背景类)不会参与loss计算,由于我的数据集就只有两个类别,所以我默认还是计算背景损失的
(2)将自己新建的ganzhe_dataset.py进行注册,通俗的讲就是修改mmseg/datasets/_init_.py这个文件,只需要将对应的py文件import一下,并在数据集支持列表中添加自己新建的数据集类即可,即新增红色框圈起来的两个位置:
(3)在configs/_base_/datasets文件夹下新建一个数据集配置文件(.py),方法也是先找到postdam.py这个文件直接复制粘贴,然后重命名为ganzhe_dataset.py,并修改相关的配置信息,包括数据集的位置、数据增强方法等信息,这里我主要修改数据集的位置信息,其他参数默认不变,还是那句话,不同的数据集配置文件可能配置信息有差异,但是都是大同小异,学会一个后举一反三。
————————————————
版权声明:本文为优快云博主「小白一只~」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/weixin_56911377/article/details/133350567
conda activate segman
cd /storage_server/disk5/sunchenxi/SegMAN-main/segmentation/
二、训练
多卡训练(失败)
CUDA_VISIBLE_DEVICES=1,2,3 bash tools/dist_train.sh local_configs/segman/base/segman_b_daye.py 3 --work-dir outputs/daye_v6
bash tools/dist_train.sh local_configs/segman/base/segman_b_ade.py 2 --work-dir outputs/daye_v6
单卡训练
python tools/train.py local_configs/segman/base/segman_b_daye.py --work-dir outputs/daye_v6
tools / train.py
# cfg.gpu_ids = args.gpu_ids[0:1]
cfg.gpu_ids = [torch.device(f'cuda:{i}') for i in cfg.gpu_ids]
三、训练策略
12.18
adam,160k Iterations,test: whole, loss:nan
后续策略可做调整:
✅ 必须做(否则容易 NaN)
loss_decode=dict( type='CrossEntropyLoss', ignore_index=255 )
✅ 强烈建议
cat_max_ratio=0.95
✅ 针对“小目标 + 类不平衡”的下一步(不是现在必须)
等你 loss 正常后,可以考虑:
-
class_weight(给 D / DS 更高权重) -
或换
OHEM/FocalLoss
但 现在不要加,否则你排错会更难。
-
根据你 6 类夹杂的真实比例,直接算一组 class_weight
-
或帮你设计一套 “专门压 D / DS 类漏检”的 loss 组合
-
或帮你对比 SegMAN vs MaskFormer 在你任务上的结构性优劣
四、环境验证(必做)
-
检查 torch + CUDA:
python - << 'EOF'
import torch
print("torch version:", torch.__version__)
print("CUDA available:", torch.cuda.is_available())
EOF
-
检查 mmcv-full CUDA 功能:
python - << 'EOF'
from mmcv.ops import get_compiling_cuda_version, get_compiler_version
print("CUDA version:", get_compiling_cuda_version())
EOF
-
检查 mmseg:
python - << 'EOF'
from mmseg.apis import init_segmentor
print("mmseg import ok")
EOF
-
检查 natten:
python - << 'EOF'
import natten
print("natten import ok")
EOF
-
检查 Selective Scan:
python - << 'EOF'
from selective_scan import some_module_name # 替换为实际模块
print("Selective Scan OK")
EOF
四、注意事项
-
NumPy 必须
<2.0,否则 mmcv / mmseg / natten 都会报错pip install "numpy<2" --no-cache-dir -
TMPDIR / PIP_CACHE_DIR 指向 /data,避免
/分区爆满 -
不要升级 mmcv / mmseg / torch / numpy,保持组合一致
651

被折叠的 条评论
为什么被折叠?



