108 Star 865 Fork 1.5K

MindSpore/models

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Contents

ICNet Description

ICNet(Image Cascade Network) propose a full convolution network which incorporates multi-resolution branches under proper label guidance to address the challenge of real-time semantic segmentation.

paper from ECCV2018

Model Architecture

ICNet takes cascade image inputs (i.e., low-, medium- and high resolution images), adopts cascade feature fusion unit and is trained with cascade label guidance.The input image with full resolution (e.g., 1024×2048 in Cityscapes) is downsampled by factors of 2 and 4, forming cascade input to medium- and high-resolution branches.

Dataset

used Dataset :Cityscape Dataset Website (please download 1st and 3rd zip)

It contains 5,000 finely annotated images split into training, validation and testing sets with 2,975, 500, and 1,525 images respectively.

Environmental requirements

Scription Description

Script and Sample Code

.
└─ICNet
    ├── ascend310_infer
    │   ├── build.sh
    │   ├── CMakeLists.txt
    │   ├── inc
    │   │   └── utils.h
    │   └── src
    │       ├── main.cc
    │       └── utils.cc
    ├── eval.py                                    # validation
    ├── export.py                                  # export mindir
    ├── postprocess.py                             # 310 infer calculate accuracy
    ├── README.md                                  # descriptions about ICNet
    ├── Res50V1_PRE                                # scripts for pretrain
    │   ├── scripts
    │   │   └── run_distribute_train.sh
    │   ├── src
    │   │   ├── config.py
    │   │   ├── CrossEntropySmooth.py
    │   │   ├── dataset.py
    │   │   ├── lr_generator.py
    │   │   └── resnet50_v1.py
    │   └── train.py
    ├── scripts
    │   ├── run_distribute_train8p.sh              # multi cards distributed training in ascend
    │   ├── run_eval.sh                            # validation script
    │   └── run_infer_310.sh                       # 310 infer script
    ├── src
    │   ├── cityscapes_mindrecord.py               # create mindrecord dataset
    │   ├── __init__.py
    │   ├── logger.py                              # logger
    │   ├── losses.py                              # used losses
    │   ├── loss.py                                # loss
    │   ├── lr_scheduler.py                        # lr
    │   ├── metric.py                              # metric
    │   ├── models
    │   │   ├── icnet_1p.py                        # net single card
    │   │   ├── icnet_dc.py                        # net multi cards
    │   │   ├── icnet.py                           # validation card
    │   │   └── resnet50_v1.py                     # backbone
    │   ├── model_utils
    │   │   └── icnet.yaml                         # config
    │   └── visualize.py                           # inference visualization
    └── train.py                                   # train

Script Parameters

Set script parameters in src/model_utils/icnet.yaml .

Model

name: "icnet"
backbone: "resnet50v1"
base_size: 1024    # during augmentation, shorter size will be resized between [base_size*0.5, base_size*2.0]
crop_size: 960     # end of augmentation, crop to training

Optimizer

init_lr: 0.02
momentum: 0.9
weight_decay: 0.0001

Training

train_batch_size_percard: 4
valid_batch_size: 1
cityscapes_root: "/data/cityscapes/" # set dataset path
epochs: 160
val_epoch: 1
mindrecord_dir: ''                   # set mindrecord path
pretrained_model_path: '/root/ResNet50V1B-150_625.ckpt' # use the latest checkpoint file after pre-training
save_checkpoint_epochs: 5
keep_checkpoint_max: 10

Training Process

Prepare Datast

  • Convert dataset to Mindrecord
    python cityscapes_mindrecord.py [DATASET_PATH] [MINDRECORD_PATH]
  • Note:

[MINDRCORD_PATH] in script should be consistent with 'mindrecord_dir' in config file.

Pre-training

The folder Res50V1_PRE contains the scripts for pre-training and its dataset is image net. More details in GENet_Res50

  • Usage:
    bash run_distribute_train.sh [RANK_TABLE_FILE] [DATASET_PATH]
  • Notes:

The hccl.json file specified by [RANK_TABLE_FILE] is used when running distributed tasks. You can use hccl_tools to generate this file.

Training

  • Train on a single card
    bash scripts/run_train1p.sh [PROJECT_PATH] [DEVICE_ID]
  • Run distributed train in ascend processor environment
    bash scripts/run_distribute_train8p.sh [RANK_TABLE_FILE] [PROJECT_PATH]

Training Result

The training results will be saved in the example path, The folder name starts with "ICNet-".You can find the checkpoint file and similar results below in LOG(0-7)/log.txt.

# distributed training result(8p)
epoch: 1 step: 93, loss is 0.5659234
epoch time: 672111.671 ms, per step time: 7227.007 ms
epoch: 2 step: 93, loss is 1.0220546
epoch time: 66850.354 ms, per step time: 718.821 ms
epoch: 3 step: 93, loss is 0.49694514
epoch time: 70490.510 ms, per step time: 757.962 ms
epoch: 4 step: 93, loss is 0.74727297
epoch time: 73657.396 ms, per step time: 792.015 ms
epoch: 5 step: 93, loss is 0.45953503
epoch time: 97117.785 ms, per step time: 1044.277 ms

Evaluation Process

Evaluation

Check the checkpoint path used for evaluation before running the following command.

    bash run_eval.sh [DATASET_PATH] [CHECKPOINT_PATH] [PROJECT_PATH] [DEVICE_ID]

Evaluation Result

The results at eval/log were as follows:

Found 500 images in the folder /data/cityscapes/leftImg8bit/val
pretrained....
2021-06-01 19:03:54,570 semantic_segmentation INFO: Start validation, Total sample: 500
avgmiou 0.69962835
avg_pixacc 0.94285786
avgtime 0.19648232793807982

310 infer

Before inference, please refer to MindSpore Inference with C++ Deployment Guide to set environment variables.

    bash run_infer_310.sh [The path of the MINDIR for 310 infer] [The path of the dataset for 310 infer]  0
  • Note: Before executing 310 infer, create the MINDIR/AIR model using "python export.py --ckpt-file [The path of the CKPT for exporting]".

Model Description

Performance

Distributed Training Performance

Parameter ICNet
resources Ascend 910;CPU 2.60GHz, 192core;memory:755G
Upload date 2021.6.1
mindspore version mindspore1.2.0
training parameter epoch=160,batch_size=4
optimizer SGD optimizer,momentum=0.9,weight_decay=0.0001
loss function SoftmaxCrossEntropyLoss
training speed epoch time:21469.152 ms(8pcs) per step time :330.851 ms(8pcs)
total time 1h20m34s(8pcs)
Script URL
Random number seed set_seed = 1234

Description of Random Situation

The seed in the create_icnet_dataset function is set in cityscapes_mindrecord.py, and the random seed in train.py is also used for weight initialization.

ModelZoo Homepage

Please visit the official website homepage.

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mindspore/models.git
git@gitee.com:mindspore/models.git
mindspore
models
models
master

搜索帮助