Commit e7cce7d3 authored by Rayyyyy's avatar Rayyyyy
Browse files

Add multi_nodes shell.

parent a246df9c
...@@ -111,43 +111,48 @@ python setup.py develop ...@@ -111,43 +111,48 @@ python setup.py develop
│ ├── train_HR_sub # 生成的 │ ├── train_HR_sub # 生成的
``` ```
项目提供了tiny_datasets进行快速上手测试, 如需使用tiny_datasets, 下面的生成步骤的数据路径需进行对应修改。 Tips: 项目提供了tiny_datasets进行快速上手测试, 如需使用tiny_datasets, 下面的数据路径需进行对应修改。
### 预处理数据集 ### 预处理数据集
#### 1.【可选】生成多尺寸图片 #### 1.【可选】生成多尺寸图片
针对 DF2K 数据集, 我们使用多尺寸缩放策略,对 HR 图像进行下采样, 获得多尺寸的标准参考(Ground-Truth)图像。 <br>
使用 [scripts/generate_multiscale_DF2K.py](scripts/generate_multiscale_DF2K.py) 脚本快速生成多尺寸的图像。<br>
如果只想简单试试而不进行准确训练, 那么该过程可选。 如果只想简单试试而不进行准确训练, 那么该过程可选。
针对 DF2K 数据集, 我们使用多尺寸缩放策略,对 HR 图像进行下采样, 获得多尺寸的标准参考(Ground-Truth)图像。
使用 [scripts/generate_multiscale_DF2K.py](scripts/generate_multiscale_DF2K.py) 脚本快速生成多尺寸的图像。
```bash ```bash
# example # example
python scripts/generate_multiscale_DF2K.py --input datasets/DF2K/DF2K_HR --output datasets/DF2K/DF2K_multiscale python scripts/generate_multiscale_DF2K.py --input datasets/DF2K/DF2K_HR --output datasets/DF2K/DF2K_multiscale
``` ```
#### 2.【可选】裁切为子图像 #### 2.【可选】裁切为子图像
使用脚本 [scripts/extract_subimages.py](scripts/extract_subimages.py) 将 DF2K 图像裁切为子图像, 以加快 IO 和处理速度。<br>
如果你的 IO 够好或储存空间有限, 那么此步骤是可选的。 如果你的 IO 够好或储存空间有限, 那么此步骤是可选的。
使用[scripts/extract_subimages.py](scripts/extract_subimages.py) 将 DF2K 图像裁切为子图像, 以加快 IO 和处理速度。
```bash ```bash
# example # example
python scripts/extract_subimages.py --input datasets/DF2K/DF2K_HR --output datasets/DF2K/DF2K_HR_sub --crop_size 400 --step 200 python scripts/extract_subimages.py --input datasets/DF2K/DF2K_HR --output datasets/DF2K/DF2K_HR_sub --crop_size 400 --step 200
``` ```
#### 3. 准备元信息 txt #### 3. 准备元信息 txt
1. 使用 [scripts/generate_meta_info.py](scripts/generate_meta_info.py) 生成包含图像路径的 txt 文件。
您需要准备一个包含图像路径的 txt 文件。 2. 还可以合并多个文件夹的图像路径到一个元信息(meta_info)txt, 示例参考如下:
使用脚本 [scripts/generate_meta_info.py](scripts/generate_meta_info.py) 生成包含图像路径的 txt 文件。<br>
你还可以合并多个文件夹的图像路径到一个元信息(meta_info)txt, 示例参考如下:
```bash ```bash
python scripts/generate_meta_info.py --input datasets/DF2K/DF2K_HR, datasets/DF2K/DF2K_multiscale --root datasets/DF2K, datasets/DF2K --meta_info datasets/DF2K/meta_info/meta_info_DF2Kmultiscale.txt # meta_info.txt 内容示例
# DF2K_HR_sub/000001_s001.png
# DF2K_HR_sub/000001_s002.png
# DF2K_HR_sub/000001_s003.png
python scripts/generate_meta_info.py --input datasets/DF2K/DF2K_HR, datasets/DF2K/DF2K_multiscale --root datasets/DF2K, datasets/DF2K --meta_info datasets/DF2K/meta_info/meta_info_DF2Kmultiscale.txt
``` ```
## 训练 ## 训练
### 完整训练 ### 完整训练
1. 下载预训练模型 [ESRGAN](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth), 将模型放到 `experiments/pretrained_models`目录下。
1. 下载预先训练的模型 [ESRGAN](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth), 将模型放到 `experiments/pretrained_models`目录下。
```bash ```bash
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth -P experiments/pretrained_models wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth -P experiments/pretrained_models
``` ```
...@@ -163,7 +168,7 @@ train: ...@@ -163,7 +168,7 @@ train:
type: disk type: disk
``` ```
如果需要指定预训练路径到其他文件, `pretrain_network_g` 参数对应的值, 当前默认保存为`experiments/train_RealESRNetx4plus_1000k_B12G4_fromESRGAN/model/net_g_1000000.pth` 如果需要指定预训练路径到其他文件, 请修改 `pretrain_network_g` 参数, 当前默认保存为`experiments/train_RealESRNetx4plus_1000k_B12G4_fromESRGAN/model/net_g_1000000.pth`
3. 如果你想在训练过程中执行验证, 就取消注释这些内容并进行相应的修改: 3. 如果你想在训练过程中执行验证, 就取消注释这些内容并进行相应的修改:
```yml ```yml
...@@ -275,17 +280,21 @@ train: ...@@ -275,17 +280,21 @@ train:
#### 单机多卡 #### 单机多卡
默认auto_resume模式, 根据完整训练或者微调训练, 修改-opt参数对应的yml文件。当前默认为完整训练 默认auto_resume模式, 根据完整训练或者微调训练, 修改-opt参数对应的yml文件。当前默认为完整训练
```bash ```bash
bash train_multi.sh bash train.sh
``` ```
#### 单机单卡 #### 多机多卡
默认auto_resume模式 使用多节点的情况下,需要将使用节点写入hostfile文件, 多节点每个节点一行, 例如: c1xxxxxx slots=4。
默认auto_resume模式, 如需训练别的yaml,请修改`$REAL-ESRGAN_ROOT/single_process.sh`中CONFIG参数。
```bash ```bash
bash train.sh bash run_train_multi.sh
``` ```
## 推理 ## 推理
下载预训练模型[RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth), 将其放入 weights文件夹下, 测试结果存默认保存在results文件夹下。 下载预训练模型[RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth), 将其放入 weights文件夹下, 测试结果默认保存在results文件夹下。
```bash ```bash
# 下载预训练模型 # 下载预训练模型
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights
...@@ -312,7 +321,7 @@ python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance ...@@ -312,7 +321,7 @@ python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance
图像超分 图像超分
### 热点应用行业 ### 热点应用行业
网安,交通,政府,工业 交通,政府,工业
## 源码仓库及问题反馈 ## 源码仓库及问题反馈
https://developer.hpccube.com/codes/modelzoo/real-esrgan_pytorch https://developer.hpccube.com/codes/modelzoo/real-esrgan_pytorch
......
...@@ -5,6 +5,6 @@ modelName=real-esrgan_pytorch ...@@ -5,6 +5,6 @@ modelName=real-esrgan_pytorch
# 模型描述 # 模型描述
modelDescription=通过使用更实用的退化过程合成训练对, 扩展强大的ESRGAN以恢复一般的真实世界LR图像。 modelDescription=通过使用更实用的退化过程合成训练对, 扩展强大的ESRGAN以恢复一般的真实世界LR图像。
# 应用场景 # 应用场景
appScenario=推理,训练,图像超分,网安,交通,政府,工业 appScenario=推理,训练,图像超分,交通,政府,工业
# 框架类型 # 框架类型
frameType=PyTorch frameType=PyTorch
ulimit -u 200000
echo "START TIME: $(date)"
hostfile=./hostfile
np=$(cat $hostfile|sort|uniq |wc -l)
np=$(($np*4))
echo $np
nodename=$(cat $hostfile |sed -n "1p")
export dist_url=`echo $nodename | awk '{print $1}'`
which mpirun
# 添加pythonlib环境, 用户需修改为自己的环境变量地址
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/path/of/conda/envs/{env_name}/lib
export PYTHON=python3
# -np 显卡数量
# -x 将变量传递到single_process.sh脚本中
mpirun -np $np --allow-run-as-root --hostfile hostfile --bind-to none -x dist_url -x PYTHON `pwd`/single_process.sh
echo "END TIME: $(date)"
#!/bin/bash
# NCCL相关的DEBUG信息显示
export NCCL_DEBUG=INFO
export NCCL_NET_PLUGIN=none
export HSA_FORCE_FINE_GRAIN_PCIE=1
export USE_MIOPEN_BATCHNORM=1
export NCCL_P2P_LEVEL=5
export WORLD_SIZE=$OMPI_COMM_WORLD_SIZE
export NCCL_PLUGIN_P2P=ucx
export NCCL_SHM_DISABLE=1
export NCCL_IB_DISABLE=0 #不适用ib
export NCCL_IB_HCA=mlx5_0
export NCCL_CROSS_NIC=1
export RCCL_NCHANNELS=4
export MASTER_ADDR=$dist_url
export MASTER_PORT=4321
export LOCAL_RANK=$OMPI_COMM_WORLD_LOCAL_RANK
lrank=$OMPI_COMM_WORLD_LOCAL_RANK
CONFIG="options/train_realesrnet_x4plus.yml"
APP="python3 -u realesrgan/train.py -opt $CONFIG --auto_resume"
case $(expr $lrank % 4) in
[0])
export HIP_VISIBLE_DEVICES=0,1,2,3
export UCX_NET_DEVICES=mlx5_0:1
export UCX_IB_PCI_BW=mlx5_0:50Gbs
NCCL_SOCKET_IFNAME=ib0 numactl --cpunodebind=0 --membind=0 ${APP}
;;
[1])
export HIP_VISIBLE_DEVICES=0,1,2,3
export UCX_NET_DEVICES=mlx5_1:1
export UCX_IB_PCI_BW=mlx5_1:50Gbs
NCCL_SOCKET_IFNAME=ib0 numactl --cpunodebind=1 --membind=1 ${APP}
;;
[2])
export HIP_VISIBLE_DEVICES=0,1,2,3
export UCX_NET_DEVICES=mlx5_2:1
export UCX_IB_PCI_BW=mlx5_2:50Gbs
NCCL_SOCKET_IFNAME=ib0 numactl --cpunodebind=2 --membind=2 ${APP}
;;
[3])
export HIP_VISIBLE_DEVICES=0,1,2,3
export UCX_NET_DEVICES=mlx5_3:1
export UCX_IB_PCI_BW=mlx5_3:50Gbs
NCCL_SOCKET_IFNAME=ib0 numactl --cpunodebind=3 --membind=3 ${APP}
;;
esac
#!/bin/bash #!/bin/bash
export HIP_VISIBLE_DEVICES=0,1,2,3 # 自行修改为训练的卡号和数量
export HSA_FORCE_FINE_GRAIN_PCIE=1 export HSA_FORCE_FINE_GRAIN_PCIE=1
export USE_MIOPEN_BATCHNORM=1 export USE_MIOPEN_BATCHNORM=1
python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --auto_resume echo "Training start ..."
## train multi
# python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --auto_resume
## train single
# python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --auto_resume
## finetune
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --launcher pytorch --auto_resume
\ No newline at end of file
#!/bin/bash
export HIP_VISIBLE_DEVICES=0,1,2,3 # 自行修改为训练的卡号和数量
export HSA_FORCE_FINE_GRAIN_PCIE=1
export USE_MIOPEN_BATCHNORM=1
echo "Training start ..."
## train
# python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --auto_resume
## finetune
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --launcher pytorch --auto_resume
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment