Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
qizhi_xd_tyl 3f4e8daffc | 2 years ago | |
---|---|---|
ascend310_infer | 2 years ago | |
preprocess | 2 years ago | |
scripts | 2 years ago | |
src | 2 years ago | |
README.md | 2 years ago | |
config.yaml | 2 years ago | |
midas_eval.py | 2 years ago | |
midas_export.py | 2 years ago | |
midas_run.py | 2 years ago | |
midas_train.py | 2 years ago | |
mixdata.json | 2 years ago | |
postprocess.py | 2 years ago |
Midas全称为Towards Robust Monocular Depth Estimation:Mixing Datasets for Zero-shot Cross-dataset Transfer,用来估计图片的深度信息,使用了五个不同的训练数据集,五个训练数据集混合策略为多目标优化,其中包括作者自制的3D电影数据集,使用6个和训练集完全不同的测试集进行验证。本次只使用ReDWeb数据集进行训练。
Midas模型网络具体细节可参考Towards Robust Monocular Depth Estimation:Mixing Datasets for
Zero-shot Cross-dataset Transfer,Midas模型网络的Pytorch版本实现,可参考(https://github.com/intel-isl/MiDaS)。
Midas的总体网络架构如下:
链接
使用的数据集:ReDWeb
采用混合精度的训练方法使用支持单精度和半精度数据来提高深度学习神经网络的训练速度,同时保持单精度训练所能达到的网络精度。混合精度训练提高计算速度、减少内存使用的同时,支持在特定硬件上训练更大的模型或实现更大批次的训练。
以FP16算子为例,如果输入数据类型为FP32,MindSpore后台会自动降低精度来处理数据。用户可打开INFO日志,搜索“reduce precision”查看精度降低的算子。
通过官方网站安装MindSpore后,您可以按照如下步骤进行训练和评估:
预训练模型
当开始训练之前需要获取mindspore图像网络预训练模型,使用在resnext101上训练出来的预训练模型resnext101_32x8d_wsl,下载完pth文件之后,运行src/utils/pth2ckpt.py
将pth文件转换为ckpt文件,转换完之后将ckpt文件命名为midas_resnext_101_WSL.ckpt
并存放于midas/ckpt/
目录下即可.
数据集准备
midas网络模型使用ReDWeb数据集用于训练,使用Sintel,KITTI,TUM数据集进行推理,数据集可通过ReDWeb,Sintel,Kitti,TUM官方网站下载使用.
Sintel数据集需要分别下载原图和深度图,放入到Sintel数据集文件夹中。TUM数据集根据处理函数得到associate.txt进行匹配数据。所有处理函数在preprocess文件夹下,具体可参考preprocess文件夹下的readme.md。
下载完数据集之后,按如下目录格式存放数据集和代码并将midas/mixdata.json
和数据集放到data/
目录下即可:
└── midas
└── data
├── mixdata.json
├── ReDWeb_V1
| ├─ Imgs
| └─ RDs
├── Kitti_raw_data
| ├─ 2011_09_26_drive_0002_sync
| | ├─depth
| | └─image
| ├─ ...
| | ├─depth
| | └─image
| ├─ 2011_10_03_drive_0047_sync
| | ├─depth
| | └─image
├── TUM
| ├─ rgbd_dataset_freiburg2_desk_with_person
| | ├─ associate.txt
| | ├─ depth.txt
| | ├─ rgb.txt
| | ├─ rgb
| | | ├─ rgb
| | | ├─ 1311870426.504412.png
| | | ├─ ...
| | | └─ 1311870426.557430.png
| | | ├─ depth
| | | ├─ 1311870427.207687.png
| | | ├─ ...
| | | └─ 1311870427.376229.png
├── Sintel
| ├─ depth
| ├─ final_left
| └─ occlusions
Ascend处理器环境运行
# 分布式训练
用法:sh run_distribute_train.sh 8
# 单机训练
用法:sh run_standalone_train.sh [DEVICE_ID]
# 运行评估示例
用法:sh run_eval.sh [DEVICE_ID]
└──midas
├── README.md
├── ascend310_infer
├── inc
└── utils.sh # 310头文件
├── src
├── main.cc # 310主函数
└── utils.cc # 310函数
├── build.sh # 编译310环境
└── CMakeLists.txt # 310推理环境
├── scripts
├── run_distribute_train.sh # 启动Ascend分布式训练(8卡)
├── run_eval.sh # 启动Ascend评估
├── run_standalone_train.sh # 启动Ascend单机训练(单卡)
└── run_infer_310.sh # 启动Ascend的310推理
├── src
├── utils
├── loadImgDepth.py # 读取数据集
└── transforms.py # 图像处理转换
├─config.py # 训练配置
├── cunstom_op.py # 网络操作
├── blocks_ms.py # 网络组件
├── loss.py # 损失函数定义
├── util.py # 读取图片工具
└── midas_net.py # 主干网络定义
├── config.yaml # 训练参数配置文件
├── midas_eval.py # 评估网络
├── midas_export.py # 模型导出
├── midas_run.py # 模型运行
├── postprocess.py # 310后处理
└── midas_train.py # 训练网络
在config.yaml中配置相关参数。
device_target: 'Ascend' #服务器的类型,有CPU,GPU,Ascend
device_id: 7 #卡的编号
run_distribute: False #是否进行分布式并行训练
is_modelarts: False #是否在云上训练
no_backbone_params_lr: 0.00001 #1e-5
no_backbone_params_end_lr: 0.00000001 #1e-8
backbone_params_lr: 0.0001 #1e-4
backbone_params_end_lr: 0.0000001 #1e-7
power: 0.5 #PolynomialDecayLR种控制lr参数
epoch_size: 400 #总epoch
batch_size: 8 #batch_size
lr_decay: False #是否采用动态学习率
train_data_dir: '/midas/' #训练集根路径
width_per_group: 8 #网络参数
groups: 32
in_channels: 64
features: 256
layers: [3, 4, 23, 3]
img_width: 384 #输入网络的图片宽度
img_height: 384 #输入网络的图片高度
nm_img_mean: [0.485, 0.456, 0.406] #图片预处理正则化参数
nm_img_std: [0.229, 0.224, 0.225]
resize_target: True #如果为True,修改image, mask, target的尺寸,否则只修改image尺寸
keep_aspect_ratio: False #保持纵横比
ensure_multiple_of: 32 #图片尺寸为32倍数
resize_method: "upper_bound" #resize模式
datapath_TUM: '/data/TUM' #TUM数据集地址
datapath_Sintel: '/data/sintel/sintel-data' #Sintel数据集地址
datapath_ETH3D: '/data/ETH3D/ETH3D-data' #ETH3D数据集地址
datapath_Kitti: '/data/Kitti_raw_data' #Kitti数据集地址
datapath_DIW: '/data/DIW' #DIW数据集地址
datapath_NYU: ['/data/NYU/nyu.mat','/data/NYU/splits.mat'] #NYU数据集地址
ann_file: 'val.json' #存放推理结果的文件地址
ckpt_path: '/midas/ckpt/Midas_0-600_56_1.ckpt' #存放推理使用的ckpt地址
data_name: 'all' #需要推理的数据集名称,有 Sintel,Kitti,TUM,DIW,ETH3D,all
input_path: '/midas/input' #输入图片的路径
output_path: '/midas/output' #模型输出图片的路径
model_weights: '/ckpt/Midas_0-600_56_1.ckpt'#模型参数路径
file_format: "AIR" #AIR/MIDIR
# 分布式训练
用法:sh run_distribute_train.sh 8
# 单机训练
用法:sh run_standalone_train.sh [DEVICE_ID]
# 运行评估示例
用法:sh run_eval.sh [DEVICE_ID] [DATA_NAME]
分布式训练结果(8P)
epoch: 1 step: 56, loss is 579.5216
epoch time: 1497998.993 ms, per step time: 26749.982 ms
epoch: 2 step: 56, loss is 773.3644
epoch time: 74565.443 ms, per step time: 1331.526 ms
epoch: 3 step: 56, loss is 270.76688
epoch time: 63373.872 ms, per step time: 1131.676 ms
epoch: 4 step: 56, loss is 319.71643
epoch time: 61290.421 ms, per step time: 1094.472 ms
...
epoch time: 58586.128 ms, per step time: 1046.181 ms
epoch: 396 step: 56, loss is 8.707727
epoch time: 63755.860 ms, per step time: 1138.498 ms
epoch: 397 step: 56, loss is 8.139318
epoch time: 47222.517 ms, per step time: 843.259 ms
epoch: 398 step: 56, loss is 10.746628
epoch time: 23364.224 ms, per step time: 417.218 ms
epoch: 399 step: 56, loss is 7.4859796
epoch time: 24304.195 ms, per step time: 434.003 ms
epoch: 400 step: 56, loss is 8.2024975
epoch time: 23696.833 ms, per step time: 423.158 ms
可通过改变config.yaml文件中的"data_name"进行对应的数据集推理,默认为全部数据集。
# 评估
sh run_eval.sh [DEVICE_ID] [DATA_NAME]
打开val.json查看推理的结果,如下所示:
{"Kitti": 24.222 "Sintel":0.323 "TUM":15.08 }
python midas_export.py
参数在config.yaml文件中设置
在执行推理前,mindir文件必须通过midas_export.py
脚本导出。以下展示了使用mindir模型执行推理的示例。
# Ascend310 inference
bash run_infer_310.sh [MODEL_PATH] [DATA_PATH] [DATASET_NAME] [DEVICE_ID]
MODEL_PATH
mindir文件路径DATA_PATH
推理数据集路径DATASET_NAME
推理数据集名称,名称分别为Kitti,TUM,Sintel。DEVICE_ID
可选,默认值为0。推理结果保存在脚本执行的当前路径,你可以在result_val.json中看到以下精度计算结果。
{"Kitti": 18.27 "Sintel":0.314 "TUM":13.27 }
Parameters | Ascend 910 |
---|---|
模型版本 | Midas |
资源 | Ascend 910;CPU:2.60GHz,192核;内存:755G |
上传日期 | 2021-06-24 |
MindSpore版本 | 1.2.0 |
数据集 | ReDWeb |
预训练模型 | ResNeXt_101_WSL |
训练参数 | epoch=400, batch_size=8, no_backbone_lr=1e-4,backbone_lr=1e-5 |
优化器 | Adam |
损失函数 | 自定义损失函数 |
速度 | 8pc: 423.4 ms/step |
训练性能 | "Kitti": 24.222 "Sintel":0.323 "TUM":15.08 |
请浏览官网主页。
MiDaS采用多目标混合策略实现5个数据集的混合训练,自制3DMovies数据集,由于每个数据的的深度图不一致,提出具有深度和偏移不变性的损失函数得到每张图像的相对深度, 然后以disparity map作为输入训练模型
Python C++ Shell Text
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》