Skip to content
Snippets Groups Projects
Unverified Commit f7d92f9f authored by i-robot's avatar i-robot Committed by Gitee
Browse files

!2199 ssd_mobilenetV1_gpu_PR

Merge pull request !2199 from 陈宇凡/master
parents 0d0acc9a 5af4f484
No related branches found
No related tags found
No related merge requests found
......@@ -254,6 +254,7 @@ Then you can run everything just like on ascend.
│ ├── local_adapter.py ## local adapter
│ ├── moxing_adapter.py ## moxing adapter
├─ config
├─ ssd_mobilenet_v1_300_config_gpu.yaml ## parameter configuration
├─ ssd_mobilenet_v1_fpn_config.yaml ## parameter configuration
├─ ssd_resnet50_fpn_config.yaml ## parameter configuration
├─ ssd_vgg16_config.yaml ## parameter configuration
......@@ -692,6 +693,24 @@ mAP: 0.23657619676441116
| configuration | ssd_vgg16_config.yaml | ssd_vgg16_config_gpu.yaml |
| Scripts | <https://gitee.com/mindspore/models/tree/master/official/cv/ssd> |
| Parameters | GPU |
| ------------------- | ------------------------------------------------------ |
| Model Version | SSD MobileNetV1 |
| Resource | GPU(Tesla V100 PCIE),CPU 2.1GHz 64 cores,Memory 128G |
| Uploaded Date | 03/03/2022 (month/day/year) |
| MindSpore Version | 1.5.0 |
| Dataset | COCO2017 |
| Training Parameters | epoch = 500, batch_size = 32 |
| Optimizer | Momentum |
| Loss Function | Sigmoid Cross Entropy,SmoothL1Loss |
| Speed | 8pcs: 108 ms/step |
| Total time | 8pcs: 6.87hours |
| outputs | mAP |
| Accuracy | IoU=0.50: 21.5% |
| Model for inference | 88M(.ckpt file) |
| configuration | ssd_mobilenet_v1_300_config_gpu.yaml |
| Scripts | <https://gitee.com/mindspore/models/tree/master/official/cv/ssd> |
## [Description of Random Situation](#contents)
In dataset.py, we set the seed inside “create_dataset" function. We also use random seed in train.py.
......
......@@ -202,6 +202,7 @@ bash run_eval_gpu.sh [DATASET] [CHECKPOINT_PATH] [DEVICE_ID] [CONFIG_PATH]
│ ├──local_adapter.py ## 本地设备配置
│ ├──moxing_adapter.py ## modelarts设备配置
├─ config
├─ ssd_mobilenet_v1_300_config_gpu.yaml ## 参数配置
├─ ssd_mobilenet_v1_fpn_config.yaml ## 参数配置
├─ ssd_resnet50_fpn_config.yaml ## 参数配置
├─ ssd_vgg16_config.yaml ## 参数配置
......@@ -579,6 +580,24 @@ mAP: 0.23657619676441116
| 参数文件 | ssd_vgg16_config.yaml | ssd_vgg16_config_gpu.yaml |
| 脚本链接 | <https://gitee.com/mindspore/models/tree/master/official/cv/ssd> |
| 参数 | GPU |
| ------------------- | ------------------------------------------------------ |
| 网络 | SSD MobileNetV1 |
| 资源 | GPU(Tesla V100 PCIE),CPU 2.1GHz 64 cores,Memory 128G |
| 上传日期 | 03/03/2022 (month/day/year) |
| 昇思版本 | 1.5.0 |
| 数据集 | COCO2017 |
| 训练参数 | epoch = 500, batch_size = 32 |
| 优化器 | Momentum |
| 损失函数 | Sigmoid Cross Entropy,SmoothL1Loss |
| 性能 | 8pcs: 108 ms/step |
| 训练耗时 | 8pcs: 6.87hours |
| 推理输出 | mAP |
| 评价指标 | IoU=0.50: 21.5% |
| 推理模型大小 | 88M(.ckpt file) |
| 参数文件 | ssd_mobilenet_v1_300_config_gpu.yaml |
| 脚本链接 | <https://gitee.com/mindspore/models/tree/master/official/cv/ssd> |
# 随机情况说明
dataset.py中设置了“create_dataset”函数内的种子,同时还使用了train.py中的随机种子。
......
# Builtin Configurations(DO NOT CHANGE THESE CONFIGURATIONS unless you know exactly what you are doing)
enable_modelarts: False
# Url for modelarts
data_url: ""
train_url: ""
checkpoint_url: ""
# Path for local
run_distribute: False
enable_profiling: False
data_path: "/DATA_1/cyf"
output_path: "/cache/train"
load_path: "/cache/checkpoint_path/"
device_target: "GPU"
checkpoint_path: "./checkpoint/"
checkpoint_file_path: "ssd-500_458.ckpt"
# ==============================================================================
# Training options
model_name: "ssd_mobilenet_v1"
img_shape: [300, 300]
num_ssd_boxes: 1917
match_threshold: 0.5
nms_threshold: 0.6
min_score: 0.1
max_boxes: 100
all_reduce_fusion_config: [29, 58, 89]
use_float16: True
# learing rate settings
lr_init: 0.001
lr_end_rate: 0.001
warmup_epochs: 2
momentum: 0.9
weight_decay: 0.00015
ssd_vgg_bn: False
pretrain_vgg_bn: False
# network
num_addition_layers: 4
extras_strides: [1, 1, 2, 2, 2, 2]
num_default: [3, 6, 6, 6, 6, 6]
extras_in_channels: [256, 512, 1024, 512, 256, 256]
extras_out_channels: [512, 1024, 512, 256, 256, 128]
extras_strides: [1, 1, 2, 2, 2, 2]
extras_ratio: [0.2, 0.2, 0.2, 0.25, 0.5, 0.25]
feature_size: [19, 10, 5, 3, 2, 1]
min_scale: 0.2
max_scale: 0.95
aspect_ratios: [[], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3]]
steps: [16, 32, 64, 100, 150, 300]
prior_scaling: [0.1, 0.2]
gamma: 2.0
alpha: 0.75
dataset: "coco"
lr: 0.05
mode_sink: "sink"
device_id: 0
device_num: 1
epoch_size: 500
batch_size: 32
loss_scale: 1024
pre_trained: ""
pre_trained_epoch_size: 0
save_checkpoint_epochs: 10
only_create_dataset: False
eval_start_epoch: 40
eval_interval: 1
run_eval: False
filter_weight: False
freeze_layer: None
save_best_ckpt: True
result_path: ""
img_path: ""
drop: False
# `mindrecord_dir` and `coco_root` are better to use absolute path.
feature_extractor_base_param: ""
checkpoint_filter_list: ['multi_loc_layers', 'multi_cls_layers']
mindrecord_dir: "/DATA_1/cyf/MindRecord_COCO"
coco_root: "/DATA_1/cyf/"
train_data_type: "train2017"
val_data_type: "val2017"
instances_set: "annotations/instances_{}.json"
classes: ['background', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
'train', 'truck', 'boat', 'traffic light', 'fire hydrant',
'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog',
'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra',
'giraffe', 'backpack', 'umbrella', 'handbag', 'tie',
'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball',
'kite', 'baseball bat', 'baseball glove', 'skateboard',
'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup',
'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza',
'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed',
'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote',
'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink',
'refrigerator', 'book', 'clock', 'vase', 'scissors',
'teddy bear', 'hair drier', 'toothbrush']
num_classes: 81
# The annotation.json position of voc validation dataset.
voc_json: "annotations/voc_instances_val.json"
# voc original dataset.
voc_root: "/data/voc_dataset"
# if coco or voc used, `image_dir` and `anno_path` are useless.
image_dir: ""
anno_path: ""
file_name: "ssd"
file_format: "AIR"
---
# Help description for each configuration
enable_modelarts: "Whether training on modelarts, default: False"
data_url: "Dataset url for obs"
train_url: "Training output url for obs"
checkpoint_url: "The location of checkpoint for obs"
data_path: "Dataset path for local"
output_path: "Training output path for local"
load_path: "The location of checkpoint for obs"
device_target: "Target device type, available: [Ascend, GPU, CPU]"
enable_profiling: "Whether enable profiling while training, default: False"
num_classes: "Class for dataset"
batch_size: "Batch size for training and evaluation"
epoch_size: "Total training epochs."
keep_checkpoint_max: "keep the last keep_checkpoint_max checkpoint"
checkpoint_path: "The location of the checkpoint file."
checkpoint_file_path: "The location of the checkpoint file."
......@@ -18,7 +18,7 @@
import os
import mindspore as ms
from mindspore import Tensor
from src.ssd import SSD300, SsdInferWithDecoder, ssd_mobilenet_v2, ssd_mobilenet_v1_fpn, ssd_resnet50_fpn, ssd_vgg16
from src.ssd import SSD300, SsdInferWithDecoder, ssd_mobilenet_v2, ssd_mobilenet_v1_fpn, ssd_mobilenet_v1, ssd_resnet50_fpn, ssd_vgg16
from src.dataset import create_ssd_dataset, create_mindrecord
from src.eval_utils import apply_eval
from src.box_utils import default_boxes
......@@ -38,6 +38,8 @@ def ssd_eval(dataset_path, ckpt_path, anno_json):
net = ssd_mobilenet_v1_fpn(config=config)
elif config.model_name == "ssd_resnet50_fpn":
net = ssd_resnet50_fpn(config=config)
elif config.model_name == "ssd_mobilenet_v1":
net = ssd_mobilenet_v1(config=config)
else:
raise ValueError(f'config.model: {config.model_name} is not supported')
net = SsdInferWithDecoder(net, Tensor(default_boxes), config)
......
......@@ -18,7 +18,7 @@ import numpy as np
import mindspore as ms
from mindspore import Tensor
from src.ssd import SSD300, SsdInferWithDecoder, ssd_mobilenet_v2, ssd_mobilenet_v1_fpn, ssd_resnet50_fpn, ssd_vgg16
from src.ssd import SSD300, SsdInferWithDecoder, ssd_mobilenet_v2, ssd_mobilenet_v1_fpn, ssd_mobilenet_v1, ssd_resnet50_fpn, ssd_vgg16
from src.model_utils.config import config
from src.model_utils.moxing_adapter import moxing_wrapper
from src.box_utils import default_boxes
......@@ -49,6 +49,8 @@ def run_export():
net = ssd_mobilenet_v1_fpn(config=config)
elif config.model_name == "ssd_resnet50_fpn":
net = ssd_resnet50_fpn(config=config)
elif config.model_name == "ssd_mobilenet_v1":
net = ssd_mobilenet_v1(config=config)
else:
raise ValueError(f'config.model: {config.model_name} is not supported')
......
......@@ -87,5 +87,39 @@ class MobileNetV1(nn.Cell):
output = self.fc(output)
return output
class FeatureSelector(nn.Cell):
"""
Select specific layers from an entire feature list
"""
def __init__(self, feature_idxes):
super(FeatureSelector, self).__init__()
self.feature_idxes = feature_idxes
def construct(self, feature_list):
selected = ()
for i in self.feature_idxes:
selected = selected + (feature_list[i],)
return selected
class MobileNetV1Feature(nn.Cell):
"""
MobileNetV1 with FPN as SSD backbone.
"""
def __init__(self, config):
super(MobileNetV1Feature, self).__init__()
self.mobilenet_v1 = MobileNetV1(features_only=True)
self.selector = FeatureSelector([14, 26])
self.layer_indexs = [14, 26]
def construct(self, x):
features = self.mobilenet_v1(x)
features = self.selector(features)
return features
def mobilenet_v1(class_num=1001):
return MobileNetV1(class_num)
def mobilenet_v1_Feature(config):
return MobileNetV1Feature(config)
......@@ -24,6 +24,7 @@ from mindspore.communication.management import get_group_size
import mindspore.ops as ops
from .fpn import mobilenet_v1_fpn, resnet50_fpn
from .vgg16 import vgg16
from .mobilenet_v1 import mobilenet_v1_Feature
def _make_divisible(v, divisor, min_value=None):
......@@ -367,6 +368,56 @@ class SsdMobilenetV1Fpn(nn.Cell):
pred_label = ops.cast(pred_label, ms.float32)
return pred_loc, pred_label
class SsdMobilenetV1Feature(nn.Cell):
"""
SSD Network using mobilenetV1 with fpn to extract features
Args:
config (dict): The default config of SSD.
is_training (bool): Used for training, default is True.
Returns:
Tensor, localization predictions.
Tensor, class conf scores.
Examples:backbone
SsdMobilenetV1Feature(config, True).
"""
def __init__(self, config, is_training=True):
super(SsdMobilenetV1Feature, self).__init__()
self.multi_box = MultiBox(config)
self.activation = ops.Sigmoid()
self.feature_extractor = mobilenet_v1_Feature(config)
in_channels = config.extras_in_channels
out_channels = config.extras_out_channels
strides = config.extras_strides
residual_list = []
for i in range(2, len(in_channels)):
residual = ConvBNReLU(in_channels[i], out_channels[i], stride=strides[i],
)
residual_list.append(residual)
self.multi_residual = nn.layer.CellList(residual_list)
self.multi_box = MultiBox(config)
self.is_training = is_training
if not is_training:
self.activation = ops.Sigmoid()
def construct(self, x):
feature, output = self.feature_extractor(x)
multi_feature = (feature, output)
feature = output
for residual in self.multi_residual:
feature = residual(feature)
multi_feature += (feature,)
pred_loc, pred_label = self.multi_box(multi_feature)
if not self.training:
pred_label = self.activation(pred_label)
pred_loc = ops.cast(pred_loc, ms.float32)
pred_label = ops.cast(pred_label, ms.float32)
return pred_loc, pred_label
class SsdResNet50Fpn(nn.Cell):
"""
SSD Network using ResNet50 with fpn to extract features
......@@ -633,6 +684,9 @@ class SsdInferWithDecoder(nn.Cell):
def ssd_mobilenet_v1_fpn(**kwargs):
return SsdMobilenetV1Fpn(**kwargs)
def ssd_mobilenet_v1(**kwargs):
return SsdMobilenetV1Feature(**kwargs)
def ssd_resnet50_fpn(**kwargs):
return SsdResNet50Fpn(**kwargs)
......
......@@ -25,7 +25,7 @@ from mindspore.train import Model
from mindspore.context import ParallelMode
from mindspore.common import set_seed, dtype
from src.ssd import SSD300, SsdInferWithDecoder, SSDWithLossCell, TrainingWrapper, ssd_mobilenet_v2,\
ssd_mobilenet_v1_fpn, ssd_resnet50_fpn, ssd_vgg16
ssd_mobilenet_v1_fpn, ssd_mobilenet_v1, ssd_resnet50_fpn, ssd_vgg16
from src.dataset import create_ssd_dataset, create_mindrecord
from src.lr_schedule import get_lr
from src.init_params import init_net_param, filter_checkpoint_parameter_by_list
......@@ -54,6 +54,15 @@ def ssd_model_build():
param_dict["network.feature_extractor.mobilenet_v1." + x] = param_dict[x]
del param_dict[x]
ms.load_param_into_net(ssd.feature_extractor.mobilenet_v1.network, param_dict)
elif config.model_name == "ssd_mobilenet_v1":
ssd = ssd_mobilenet_v1(config=config)
init_net_param(ssd)
if config.feature_extractor_base_param != "":
param_dict = ms.load_checkpoint(config.feature_extractor_base_param)
for x in list(param_dict.keys()):
param_dict["network.feature_extractor.mobilenet_v1." + x] = param_dict[x]
del param_dict[x]
ms.load_param_into_net(ssd.feature_extractor.mobilenet_v1.network, param_dict)
elif config.model_name == "ssd_resnet50_fpn":
ssd = ssd_resnet50_fpn(config=config)
init_net_param(ssd)
......@@ -83,6 +92,10 @@ def set_graph_kernel_context(device_target, model):
# Enable graph kernel for default model ssd300 on GPU back-end.
ms.set_context(enable_graph_kernel=True,
graph_kernel_flags="--enable_parallel_fusion --enable_expand_ops=Conv2D")
if device_target == "GPU" and model == "ssd_mobilenet_v1":
# Enable graph kernel for default model ssd300 on GPU back-end.
ms.context.set_context(enable_graph_kernel=True,
graph_kernel_flags="--enable_parallel_fusion --enable_expand_ops=Conv2D")
@moxing_wrapper()
def train_net():
......
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