update README

This commit is contained in:
zhu_wenyong 2021-05-03 12:43:20 +08:00
parent 81cd26bdc8
commit f217a201ea
2 changed files with 279 additions and 146 deletions

View File

@ -1,60 +1,59 @@
# Contents
- [FCN 介绍](#FCN-介绍)
- [模型架构](#模型架构)
- [数据集](#数据集)
- [环境要求](#环境要求)
- [快速开始](#快速开始)
- [脚本介绍](#脚本介绍)
- [脚本以及简单代码](#脚本以及简单代码)
- [脚本参数](#脚本参数)
- [训练步骤](#训练步骤)
- [训练](#训练)
- [评估步骤](#评估步骤)
- [评估](#评估)
- [模型介绍](#模型介绍)
- [性能](#性能)
- [评估性能](#评估性能)
- [如何使用](#如何使用)
- [教程](#教程)
- [随机事件介绍](#随机事件介绍)
- [ModelZoo 主页](#ModelZoo-主页)
- [FCN Description](#fcn-description)
- [Model Architecture](#model-architecture)
- [Dataset](#dataset)
- [Environment Requirements](#environment-requirements)
- [Quick Start](#quick-start)
- [Script Description](#script-description)
- [Script and Sample Code](#script-and-sample-code)
- [Script Parameters](#script-parameters)
- [Data Generation](#data-generation)
- [Training Data](#training-data)
- [Training Process](#training-process)
- [Training](#training)
- [Evaluation Process](#evaluation-process)
- [Evaluation](#evaluation)
- [Model Description](#model-description)
- [Performance](#performance)
- [Evaluation Performance](#evaluation-performance)
- [Inference Performance](#inference-performance)
- [Description of Random Situation](#description-of-random-situation)
- [ModelZoo Homepage](#modelzoo-homepage)
# [FCN 介绍](#contents)
# [FCN Description](#contents)
FCN主要用用于图像分割领域是一种端到端的分割方法。FCN丢弃了全连接层使得其能够处理任意大小的图像且减少了模型的参数量提高了模型的分割速度。FCN在编码部分使用了VGG的结构在解码部分中使用反卷积/上采样操作恢复图像的分辨率。FCN-8s最后使用8倍的反卷积/上采样操作将输出分割图恢复到与输入图像相同大小。
FCN is mainly used in the field of image segmentation, which is an end-to-end segmentation method. FCN changes the last full connected layers of VGG to process images of any size, reduce the parameters and improve the segmentation speed of the model. FCN uses VGG structure in the encoding part and deconvolution / up sampling operation in the decoding part to recover the image resolution. Finally, FCN8s uses 8 times deconvolution / up sampling operation to restore the output image to the same size as the input image.
[Paper]: Long, Jonathan, Evan Shelhamer, and Trevor Darrell. "Fully convolutional networks for semantic segmentation." Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2015.
# [模型架构](#contents)
# [Model Architecture](#contents)
FCN-8s使用丢弃全连接操作的VGG16作为编码部分并分别融合VGG16中第3,4,5个池化层特征最后使用stride=8的反卷积获得分割图像。
FCN8s uses VGG16 without the full connected layers as the encoding part, and fuses the features of the 3rd, 4th and 5th pooling layers in VGG16 respectively. Finally, the deconvolution of stride 8 is used to obtain the segmented image.
# [数据集](#contents)
# [Dataset](#contents)
Dataset used:
[PASCAL VOC 2012](<http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html>)
[SBD](<http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz>)
# [Environment Requirements](#contents)
# [环境要求](#contents)
- 硬件Ascend/GPU
- 需要准备具有Ascend或GPU处理能力的硬件环境.
- 框架
- HardwareAscend
- Prepare hardware environment with Ascend processor.
- Architecture
- [MindSpore](https://www.mindspore.cn/install/en)
- 如需获取更多信息,请查看如下链接
- For more information, please check the resources below
- [MindSpore Tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
- [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
# [快速开始](#contents)
# [Quick Start](#contents)
在通过官方网站安装MindSpore之后你可以通过如下步骤开始训练以及评估
After installing MindSpore through the official website, you can start training and evaluation by following these steps
- running on Ascend with default parameters
```python
```bash
# run training example
python train.py --device_id device_id
@ -62,13 +61,12 @@ Dataset used:
python eval.py --device_id device_id
```
# [脚本介绍](#contents)
# [Script Description](#contents)
## [脚本以及简单代码](#contents)
## [Script and Sample Code](#contents)
```python
├── model_zoo
├── README.md // descriptions about all the models
```bash
├── cv
├── FCN8s
├── README.md // descriptions about FCN
├── scripts
@ -90,9 +88,9 @@ Dataset used:
├── eval.py // evaluation script
```
## [脚本参数](#contents)
## [Script Parameters](#contents)
训练以及评估的参数可以在config.py中设置
Parameters for both training and evaluation can be set in config.py.
- config for FCN8s
@ -124,15 +122,15 @@ Dataset used:
'ckpt_dir': './ckpt',
```
如需获取更多信息,请查看`config.py`.
For more information, see `config.py`.
## [生成数据步骤](#contents)
## [Data Generation](#contents)
### 训练数据
### Training Data
- build mindrecord training data
```python
```bash
sh build_data.sh
or
python src/data/build_seg_data.py --data_root=/home/sun/data/Mindspore/benchmark_RELEASE/dataset \
@ -140,55 +138,43 @@ Dataset used:
--dst_path=dataset/MINDRECORED_NAME.mindrecord \
--num_shards=1 \
--shuffle=True
data_root: 训练数据集的总目录包含两个子目录img和cls_pngimg目录下存放训练图像cls_png目录下存放标签mask图像
data_lst: 存放训练样本的名称列表文档,每行一个样本。
dst_path: 生成mindrecord数据的目标位置
```
## [训练步骤](#contents)
## [Training Process](#contents)
### 训练
### Training
- running on Ascend with default parameters
```python
```bash
python train.py --device_id device_id
```
训练时训练过程中的epch和step以及此时的loss和精确度会呈现在终端上
Checkpoints will be stored in the default path
```python
epoch: * step: **, loss is ****
...
```
## [Evaluation Process](#contents)
此模型的checkpoint会在默认路径下存储
### Evaluation
## [评估步骤](#contents)
- Evaluated on Pascal VOC 2012 validation set using Ascend
### 评估
Before running the command, check the path of the checkpoint used for evaluation. Please set the absolute path of the checkpoint
- 在Ascend上使用PASCAL VOC 2012 验证集进行评估
在使用命令运行前请检查用于评估的checkpoint的路径。请设置路径为到checkpoint的绝对路径如 "/data/workspace/mindspore_dataset/FCN/FCN/model_new/FCN8s-500_82.ckpt"。
```python
```bash
python eval.py
```
以上的python命令会在终端上运行你可以在终端上查看此次评估的结果。测试集的精确度会以如下方式呈现
After running the above command, you can see the evaluation results on the terminal. The accuracy on the test set is presented as follows:
```python
mean IoU 0.6467
```bash
mean IoU 0.6425
```
# [模型介绍](#contents)
# [Model Description](#contents)
## [性能](#contents)
## [Performance](#contents)
### 评估性能
#### FCN8s on PASCAL VOC 2012
### Evaluation Performance
| Parameters | Ascend
| -------------------------- | -----------------------------------------------------------
@ -196,7 +182,7 @@ Dataset used:
| Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8
| uploaded Date | 12/30/2020 (month/day/year)
| MindSpore Version | 1.1.0-alpha
| Dataset | PASCAL VOC 2012 and SBD
| Dataset | PASCAL VOC 2012
| Training Parameters | epoch=500, steps=330, batch_size = 32, lr=0.015
| Optimizer | Momentum
| Loss Function | Softmax Cross Entropy
@ -213,85 +199,18 @@ Dataset used:
| ------------------- | ---------------------------
| Model Version | FCN-8s
| Resource | Ascend 910; OS Euler2.8
| Uploaded Date | 10/29/2020 (month/day/year)
| Uploaded Date | 12/30/2020 (month/day/year)
| MindSpore Version | 1.1.0-alpha
| Dataset | PASCAL VOC 2012
| batch_size | 16
| outputs | probability
| mean IoU | 64.67
| mean IoU | 64.25
## [如何使用](#contents)
# [Description of Random Situation](#contents)
### 教程
We set the random seeds in train.py.
如果你需要在不同硬件平台如GPUAscend 910 或者 Ascend 310使用训练好的模型你可以参考这个 [Link](https://www.mindspore.cn/tutorial/training/en/master/advanced_use/migrate_3rd_scripts.html)。以下是一个简单例子的步骤介绍:
# [ModelZoo Homepage](#contents)
- Running on Ascend
```
# Set context
context.set_context(mode=context.GRAPH_MODE, device_target=args_opt.device_target, save_graphs=False)
context.set_auto_parallel_context(device_num=device_num,parallel_mode=ParallelMode.DATA_PARALLEL)
init()
# Load dataset
dataset = data_generator.SegDataset(image_mean=cfg.image_mean,
image_std=cfg.image_std,
data_file=cfg.data_file,
batch_size=cfg.batch_size,
crop_size=cfg.crop_size,
max_scale=cfg.max_scale,
min_scale=cfg.min_scale,
ignore_label=cfg.ignore_label,
num_classes=cfg.num_classes,
num_readers=2,
num_parallel_calls=4,
shard_id=args.rank,
shard_num=args.group_size)
dataset = dataset.get_dataset(repeat=1)
# Define model
net = FCN8s(n_class=cfg.num_classes)
loss_ = loss.SoftmaxCrossEntropyLoss(cfg.num_classes, cfg.ignore_label)
# optimizer
iters_per_epoch = dataset.get_dataset_size()
total_train_steps = iters_per_epoch * cfg.train_epochs
lr_scheduler = CosineAnnealingLR(cfg.base_lr,
cfg.train_epochs,
iters_per_epoch,
cfg.train_epochs,
warmup_epochs=0,
eta_min=0)
lr = Tensor(lr_scheduler.get_lr())
# loss scale
manager_loss_scale = FixedLossScaleManager(cfg.loss_scale, drop_overflow_update=False)
optimizer = nn.Momentum(params=net.trainable_params(), learning_rate=lr, momentum=0.9, weight_decay=0.0001,
loss_scale=cfg.loss_scale)
model = Model(net, loss_fn=loss_, loss_scale_manager=manager_loss_scale, optimizer=optimizer, amp_level="O3")
# callback for saving ckpts
time_cb = TimeMonitor(data_size=iters_per_epoch)
loss_cb = LossMonitor()
cbs = [time_cb, loss_cb]
if args.rank == 0:
config_ck = CheckpointConfig(save_checkpoint_steps=cfg.save_steps,
keep_checkpoint_max=cfg.keep_checkpoint_max)
ckpoint_cb = ModelCheckpoint(prefix=cfg.model, directory=cfg.ckpt_dir, config=config_ck)
cbs.append(ckpoint_cb)
model.train(cfg.train_epochs, dataset, callbacks=cbs)
# [随机事件介绍](#contents)
我们在train.py中设置了随机种子
# [ModelZoo 主页](#contents)
请查看官方网站 [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).
Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).

View File

@ -0,0 +1,214 @@
# 目录
- [FCN 介绍](#FCN-介绍)
- [模型架构](#模型架构)
- [数据集](#数据集)
- [环境要求](#环境要求)
- [快速开始](#快速开始)
- [脚本介绍](#脚本介绍)
- [脚本以及简单代码](#脚本以及简单代码)
- [脚本参数](#脚本参数)
- [生成数据步骤](#生成数据步骤)
- [训练数据](#训练数据)
- [训练步骤](#训练步骤)
- [训练](#训练)
- [评估步骤](#评估步骤)
- [评估](#评估)
- [模型介绍](#模型介绍)
- [性能](#性能)
- [评估性能](#评估性能)
- [推理性能](#推理性能)
- [随机事件介绍](#随机事件介绍)
- [ModelZoo 主页](#ModelZoo-主页)
# [FCN 介绍](#目录)
FCN主要用用于图像分割领域是一种端到端的分割方法。FCN丢弃了全连接层使得其能够处理任意大小的图像且减少了模型的参数量提高了模型的分割速度。FCN在编码部分使用了VGG的结构在解码部分中使用反卷积/上采样操作恢复图像的分辨率。FCN-8s最后使用8倍的反卷积/上采样操作将输出分割图恢复到与输入图像相同大小。
[论文]: Long, Jonathan, Evan Shelhamer, and Trevor Darrell. "Fully convolutional networks for semantic segmentation." Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2015.
# [模型架构](#目录)
FCN8s使用丢弃全连接操作的VGG16作为编码部分并分别融合VGG16中第3,4,5个池化层特征最后使用stride=8的反卷积获得分割图像。
# [数据集](#目录)
使用的数据集:
[PASCAL VOC 2012](<http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html>)
# [环境要求](#目录)
- 硬件Ascend
- 需要准备具有Ascend处理能力的硬件环境.
- 框架
- [MindSpore](https://www.mindspore.cn/install/en)
- 如需获取更多信息,请查看如下链接:
- [MindSpore 教程](https://www.mindspore.cn/tutorial/training/en/master/index.html)
- [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
# [快速开始](#目录)
在通过官方网站安装MindSpore之后你可以通过如下步骤开始训练以及评估
- 用默认参数在Ascend上运行
```bash
# 训练
python train.py --device_id device_id
# 评估
python eval.py --device_id device_id
```
# [脚本介绍](#目录)
## [脚本以及简单代码](#目录)
```bash
├── cv
├── FCN8s
├── README.md // FCN8s相关说明
├── scripts
├── run_train.sh
├── run_standalone_train.sh
├── run_eval.sh
├── build_data.sh
├── src
│ ├──data
│ ├──build_seg_data.py // 创建数据
│ ├──dataset.py // 载入数据
│ ├──nets
│ ├──FCN8s.py // FCN8s网络结构
│ ├──loss
│ ├──loss.py // 损失函数
│ ├──utils
│ ├──lr_scheduler.py // 学习率设置
├── train.py // 训练脚本
├── eval.py // 评估脚本
```
## [脚本参数](#目录)
训练以及评估的参数可以在config.py中设置
- FCN8s配置
```python
# 数据
'data_file': '/data/workspace/mindspore_dataset/FCN/FCN/dataset/MINDRECORED_NAME.mindrecord', # path and name of one mindrecord file
'batch_size': 32,
'crop_size': 512,
'image_mean': [103.53, 116.28, 123.675],
'image_std': [57.375, 57.120, 58.395],
'min_scale': 0.5,
'max_scale': 2.0,
'ignore_label': 255,
'num_classes': 21,
# 优化
'train_epochs': 500,
'base_lr': 0.015,
'loss_scale': 1024.0,
# 模型
'model': 'FCN8s',
'ckpt_vgg16': '',
'ckpt_pre_trained': '',
# 训练
'save_steps': 330,
'keep_checkpoint_max': 5,
'ckpt_dir': './ckpt',
```
如需获取更多信息,请查看`config.py`.
## [生成数据步骤](#目录)
### 训练数据
- 创建mindrecord训练数据
```bash
sh build_data.sh
or
python src/data/build_seg_data.py --data_root=/home/sun/data/Mindspore/benchmark_RELEASE/dataset \
--data_lst=/home/sun/data/Mindspore/benchmark_RELEASE/dataset/trainaug.txt \
--dst_path=dataset/MINDRECORED_NAME.mindrecord \
--num_shards=1 \
--shuffle=True
```
## [训练步骤](#目录)
### 训练
- 用默认参数在Ascend上训练
```bash
python train.py --device_id device_id
```
此模型的checkpoint会在默认路径下存储
## [评估步骤](#目录)
### 评估
- 在Ascend上使用PASCAL VOC 2012 验证集进行评估
在使用命令运行前请检查用于评估的checkpoint的路径。请设置路径为到checkpoint的绝对路径。
```bash
python eval.py
```
以上的python命令会在终端上运行你可以在终端上查看此次评估的结果。测试集的精确度会以如下方式呈现
```bash
mean IoU 0.6425
```
# [模型介绍](#目录)
## [性能](#目录)
### 评估性能
| 参数 | Ascend
| -------------------------- | -----------------------------------------------------------
| 模型版本 | FCN-8s
| 资源 | Ascend 910; CPU 2.60GHz, 192核; 内存 755G; 系统 Euler2.8
| 上传日期 | 12/30/2020
| MindSpore版本 | 1.1.0-alpha
| 数据集 | PASCAL VOC 2012
| 训练参数 | epoch=500, steps=330, batch_size = 32, lr=0.015
| 优化器 | Momentum
| 损失函数 | Softmax交叉熵
| 输出 | 概率
| 损失 | 0.038
| 速度 | 1pc: 564.652 毫秒/步;
| 脚本 | [FCN 脚本](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/FCN8s)
### 推理性能
| 参数 | Ascend
| ------------------- | ---------------------------
| 模型版本 | FCN-8s
| 资源 | Ascend 910; 系统 Euler2.8
| 上传日期 | 12/30/2020
| MindSpore版本 | 1.1.0-alpha
| 数据集 | PASCAL VOC 2012
| 批大小 | 16
| 输出 | 概率
| 平均 IoU | 64.25
# [随机事件介绍](#目录)
我们在train.py中设置了随机种子
# [ModelZoo 主页](#目录)
请查看官方网站 [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).