forked from mindspore-Ecosystem/mindspore
!14788 add supplementary notes of mobilenetv2 and ssd in README
From: @zhao_ting_v Reviewed-by: @oacjiewen,@c_34 Signed-off-by: @c_34
This commit is contained in:
commit
d2514950ec
|
@ -39,8 +39,7 @@ void CastCPUKernel<S, T>::InitKernel(const CNodePtr &kernel_node) {
|
|||
}
|
||||
|
||||
template <typename S, typename T>
|
||||
bool CastCPUKernel<S, T>::Launch(const std::vector<kernel::AddressPtr> &inputs,
|
||||
const std::vector<kernel::AddressPtr> & /*workspace*/,
|
||||
bool CastCPUKernel<S, T>::Launch(const std::vector<kernel::AddressPtr> &inputs, const std::vector<kernel::AddressPtr> &,
|
||||
const std::vector<kernel::AddressPtr> &outputs) {
|
||||
S *input = reinterpret_cast<S *>(inputs[0]->addr);
|
||||
T *output = reinterpret_cast<T *>(outputs[0]->addr);
|
||||
|
|
|
@ -91,6 +91,32 @@ You can start training using python or shell scripts. The usage of shell scripts
|
|||
- GPU: sh run_trian.sh GPU [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH] [CKPT_PATH] [FREEZE_LAYER] [FILTER_HEAD]
|
||||
- CPU: sh run_trian.sh CPU [DATASET_PATH] [CKPT_PATH] [FREEZE_LAYER] [FILTER_HEAD]
|
||||
|
||||
`DATASET_PATH` is the train dataset path. We use `ImageFolderDataset` as default dataset, which is a source dataset that reads images from a tree of directories. The directory structure is as follows, and you should use `DATASET_PATH=dataset/train` for training and `DATASET_PATH=dataset/val` for evaluation:
|
||||
|
||||
```path
|
||||
└─dataset
|
||||
└─train
|
||||
├─class1
|
||||
├─0001.jpg
|
||||
......
|
||||
└─xxxx.jpg
|
||||
......
|
||||
├─classx
|
||||
├─0001.jpg
|
||||
......
|
||||
└─xxxx.jpg
|
||||
└─val
|
||||
├─class1
|
||||
├─0001.jpg
|
||||
......
|
||||
└─xxxx.jpg
|
||||
......
|
||||
├─classx
|
||||
├─0001.jpg
|
||||
......
|
||||
└─xxxx.jpg
|
||||
```
|
||||
|
||||
`CKPT_PATH` `FREEZE_LAYER` and `FILTER_HEAD` are optional, when set `CKPT_PATH`, `FREEZE_LAYER` must be set. `FREEZE_LAYER` should be in ["none", "backbone"], and if you set `FREEZE_LAYER`="backbone", the parameter in backbone will be freezed when training and the parameter in head will not be load from checkpoint. if `FILTER_HEAD`=True, the parameter in head will not be load from checkpoint.
|
||||
|
||||
> RANK_TABLE_FILE is HCCL configuration file when running on Ascend.
|
||||
|
|
|
@ -97,6 +97,32 @@ MobileNetV2总体网络架构如下:
|
|||
- GPU: sh run_trian.sh GPU [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH] [CKPT_PATH] [FREEZE_LAYER] [FILTER_HEAD]
|
||||
- CPU: sh run_trian.sh CPU [DATASET_PATH] [CKPT_PATH] [FREEZE_LAYER] [FILTER_HEAD]
|
||||
|
||||
`DATASET_PATH`是训练的路径. 我们使用`ImageFolderDataset` 作为默认数据处理方式, 这种数据处理方式是从原始目录中读取图片,目录结构如下, 训练时设置`DATASET_PATH=dataset/train`,验证时设置`DATASET_PATH=dataset/val`:
|
||||
|
||||
```path
|
||||
└─dataset
|
||||
└─train
|
||||
├─class1
|
||||
├─0001.jpg
|
||||
......
|
||||
└─xxxx.jpg
|
||||
......
|
||||
├─classx
|
||||
├─0001.jpg
|
||||
......
|
||||
└─xxxx.jpg
|
||||
└─val
|
||||
├─class1
|
||||
├─0001.jpg
|
||||
......
|
||||
└─xxxx.jpg
|
||||
......
|
||||
├─classx
|
||||
├─0001.jpg
|
||||
......
|
||||
└─xxxx.jpg
|
||||
```
|
||||
|
||||
`CKPT_PATH` `FREEZE_LAYER` 和 `FILTER_HEAD` 是可选择的选项, 如果设置`CKPT_PATH`, `FREEZE_LAYER` 也必须同时设置. `FREEZE_LAYER` 可以是 ["none", "backbone"], 如果设置 `FREEZE_LAYER`="backbone", 训练过程中backbone中的参数会被冻结,同时不会从checkpoint中加载head部分的参数. 如果`FILTER_HEAD`=True, 不会从checkpoint中加载head部分的参数.
|
||||
|
||||
> RANK_TABLE_FILE 是在Ascned上运行分布式任务时HCCL的配置文件
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
from src.image_classification import get_network
|
||||
|
||||
def create_network(name, *args, **kwargs):
|
||||
if name == "renext50":
|
||||
get_network("renext50", *args, **kwargs)
|
||||
return net
|
||||
raise NotImplementedError(f"{name} is not implemented in the repo")
|
||||
if name != "renext50":
|
||||
raise NotImplementedError(f"{name} is not implemented in the repo")
|
||||
net = get_network(*args, **kwargs)
|
||||
return net
|
||||
|
|
|
@ -78,7 +78,7 @@ Dataset used: [COCO2017](<http://images.cocodataset.org/>)
|
|||
|
||||
1. If coco dataset is used. **Select dataset to coco when run script.**
|
||||
|
||||
Change the `coco_root` and other settings you need in `src/config.py`. The directory structure is as follows:
|
||||
Change the `coco_root` and other settings you need in `src/config_xxx.py`. The directory structure is as follows:
|
||||
|
||||
```shell
|
||||
.
|
||||
|
@ -91,7 +91,7 @@ Dataset used: [COCO2017](<http://images.cocodataset.org/>)
|
|||
```
|
||||
|
||||
2. If VOC dataset is used. **Select dataset to voc when run script.**
|
||||
Change `classes`, `num_classes`, `voc_json` and `voc_root` in `src/config.py`. `voc_json` is the path of json file with coco format for evaluation, `voc_root` is the path of VOC dataset, the directory structure is as follows:
|
||||
Change `classes`, `num_classes`, `voc_json` and `voc_root` in `src/config_xxx.py`. `voc_json` is the path of json file with coco format for evaluation, `voc_root` is the path of VOC dataset, the directory structure is as follows:
|
||||
|
||||
```shell
|
||||
.
|
||||
|
@ -117,15 +117,15 @@ Dataset used: [COCO2017](<http://images.cocodataset.org/>)
|
|||
train2017/0000001.jpg 0,259,401,459,7 35,28,324,201,2 0,30,59,80,2
|
||||
```
|
||||
|
||||
Each row is an image annotation which split by space, the first column is a relative path of image, the others are box and class infomations of the format [xmin,ymin,xmax,ymax,class]. We read image from an image path joined by the `image_dir`(dataset directory) and the relative path in `anno_path`(the TXT file path), `image_dir` and `anno_path` are setting in `src/config.py`.
|
||||
Each row is an image annotation which split by space, the first column is a relative path of image, the others are box and class infomations of the format [xmin,ymin,xmax,ymax,class]. We read image from an image path joined by the `image_dir`(dataset directory) and the relative path in `anno_path`(the TXT file path), `image_dir` and `anno_path` are setting in `src/config_xxx.py`.
|
||||
|
||||
## [Quick Start](#contents)
|
||||
|
||||
### Prepare the model
|
||||
|
||||
1. Chose the model by changing the `using_model` in `src/confgi.py`. The optional models are: `ssd300`, `ssd_mobilenet_v1_fpn`, `ssd_mobilenet_v1_fpn`, `ssd_resnet50_fpn`.
|
||||
2. Change the dataset config in the corresponding config. `src/config_ssd300.py`, `src/config_ssd_mobilenet_v1_fpn.py`, `src/config_ssd_resnet50_fpn.py`, `src/config_ssd_vgg16.py`.
|
||||
3. If you are running with `ssd_mobilenet_v1_fpn`, you need a pretrained model for `mobilenet_v1`. Set the checkpoint path to `feature_extractor_base_param` in `src/config_ssd_mobilenet_v1_fpn.py`. For more detail about training mobilnet_v1, please refer to the mobilenetv1 model.
|
||||
1. Chose the model by changing the `using_model` in `src/config.py`. The optional models are: `ssd300`, `ssd_mobilenet_v1_fpn`, `ssd_vgg16`, `ssd_resnet50_fpn`.
|
||||
2. Change the dataset config in the corresponding config. `src/config_xxx.py`, `xxx` is the corresponding backbone network name
|
||||
3. If you are running with `ssd_mobilenet_v1_fpn` or `ssd_resnet50_fpn`, you need a pretrained model for `mobilenet_v1` or `resnet50`. Set the checkpoint path to `feature_extractor_base_param` in `src/config_xxx.py`. For more detail about training pre-trained model, please refer to the corresponding backbone network.
|
||||
|
||||
### Run the scripts
|
||||
|
||||
|
@ -325,7 +325,7 @@ You can add `run_eval` to start shell and set it True, if you want evaluation wh
|
|||
You can train your own model based on either pretrained classification model or pretrained detection model. You can perform transfer training by following steps.
|
||||
|
||||
1. Convert your own dataset to COCO or VOC style. Otherwise you have to add your own data preprocess code.
|
||||
2. Change config.py according to your own dataset, especially the `num_classes`.
|
||||
2. Change config_xxx.py according to your own dataset, especially the `num_classes`.
|
||||
3. Prepare a pretrained checkpoint. You can load the pretrained checkpoint by `pre_trained` argument. Transfer training means a new training job, so just keep `pre_trained_epoch_size` same as default value `0`.
|
||||
4. Set argument `filter_weight` to `True` while calling `train.py`, this will filter the final detection box weight from the pretrained model.
|
||||
5. Build your own bash scripts using new config and arguments for further convenient.
|
||||
|
|
Loading…
Reference in New Issue