delete redundant codes

This commit is contained in:
zhaoting 2020-09-15 16:52:26 +08:00
parent 63ae2c3639
commit d421f49e60
62 changed files with 61 additions and 96 deletions

View File

@ -50,7 +50,7 @@ Dataset used: [CIFAR-10](<http://www.cs.toronto.edu/~kriz/cifar.html>)
- HardwareAscend/GPU
- Prepare hardware environment with Ascend or GPU processor.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -13,8 +13,8 @@
# limitations under the License.
# ============================================================================
import cv2
import numpy as np
import cv2
import mindspore.dataset as de
cv2.setNumThreads(0)

View File

@ -114,7 +114,7 @@ class BboxAssignSampleForRcnn(nn.Cell):
bboxes = self.select(self.cast(self.tile(self.reshape(self.cast(valid_mask, mstype.int32), \
(self.num_bboxes, 1)), (1, 4)), mstype.bool_), \
bboxes, self.check_anchor_two)
# 1 dim = gt, 2 dim = bbox
overlaps = self.iou(bboxes, gt_bboxes_i)
max_overlaps_w_gt_index, max_overlaps_w_gt = self.max_gt(overlaps)

View File

@ -166,15 +166,12 @@ if __name__ == '__main__':
parameter_name = x.name
if parameter_name.endswith('.bias'):
# all bias not using weight decay
# print('no decay:{}'.format(parameter_name))
no_decay_params.append(x)
elif parameter_name.endswith('.gamma'):
# bn weight bias not using weight decay, be carefully for now x not include BN
# print('no decay:{}'.format(parameter_name))
no_decay_params.append(x)
elif parameter_name.endswith('.beta'):
# bn weight bias not using weight decay, be carefully for now x not include BN
# print('no decay:{}'.format(parameter_name))
no_decay_params.append(x)
else:
decay_params.append(x)

View File

@ -54,7 +54,7 @@ For FP16 operators, if the input data type is FP32, the backend of MindSpore wil
- HardwareAscend/GPU
- Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend , please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -56,7 +56,7 @@ Dataset used: [MNIST](<http://yann.lecun.com/exdb/mnist/>)
- HardwareAscend/GPU/CPU
- Prepare hardware environment with Ascend, GPU, or CPU processor.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -22,8 +22,8 @@ class LeNet5(nn.Cell):
Lenet network
Args:
num_class (int): Num classes. Default: 10.
num_channel (int): Num channels. Default: 1.
num_class (int): Number of classes. Default: 10.
num_channel (int): Number of channels. Default: 1.
Returns:
Tensor, output tensor

View File

@ -21,7 +21,7 @@ class LeNet5(nn.Cell):
Lenet network
Args:
num_class (int): Num classes. Default: 10.
num_class (int): Number of classes. Default: 10.
Returns:
Tensor, output tensor

View File

@ -22,7 +22,7 @@ class LeNet5(nn.Cell):
Lenet network
Args:
num_class (int): Num classes. Default: 10.
num_class (int): Number of classes. Default: 10.
Returns:
Tensor, output tensor

View File

@ -118,7 +118,7 @@ class BboxAssignSampleForRcnn(nn.Cell):
bboxes = self.select(self.cast(self.tile(self.reshape(self.cast(valid_mask, mstype.int32), \
(self.num_bboxes, 1)), (1, 4)), mstype.bool_), \
bboxes, self.check_anchor_two)
# 1 dim = gt, 2 dim = bbox
overlaps = self.iou(bboxes, gt_bboxes_i)
max_overlaps_w_gt_index, max_overlaps_w_gt = self.max_gt(overlaps)

View File

@ -51,7 +51,7 @@ For FP16 operators, if the input data type is FP32, the backend of MindSpore wil
- HardwareAscend/GPU/CPU
- Prepare hardware environment with Ascend、GPU or CPU processor. If you want to try Ascend, please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -145,7 +145,7 @@ class MobileNetV2Backbone(nn.Cell):
MobileNetV2 architecture.
Args:
class_num (Cell): number of classes.
class_num (int): number of classes.
width_mult (int): Channels multiplier for round to 8/16 and others. Default is 1.
has_dropout (bool): Is dropout used. Default is false
inverted_residual_setting (list): Inverted residual settings. Default is None
@ -233,7 +233,7 @@ class MobileNetV2Head(nn.Cell):
MobileNetV2 architecture.
Args:
class_num (Cell): number of classes.
class_num (int): Number of classes. Default is 1000.
has_dropout (bool): Is dropout used. Default is false
Returns:
Tensor, output tensor.
@ -284,11 +284,13 @@ class MobileNetV2(nn.Cell):
MobileNetV2 architecture.
Args:
class_num (Cell): number of classes.
class_num (int): number of classes.
width_mult (int): Channels multiplier for round to 8/16 and others. Default is 1.
has_dropout (bool): Is dropout used. Default is false
inverted_residual_setting (list): Inverted residual settings. Default is None
round_nearest (list): Channel round to . Default is 8
backbone(nn.Cell): Backbone of MobileNetV2.
head(nn.Cell): Classification head of MobileNetV2.
Returns:
Tensor, output tensor.

View File

@ -29,8 +29,8 @@ class CrossEntropyWithLabelSmooth(_Loss):
CrossEntropyWith LabelSmooth.
Args:
smooth_factor (float): smooth factor, default=0.
num_classes (int): num classes
smooth_factor (float): smooth factor. Default is 0.
num_classes (int): number of classes. Default is 1000.
Returns:
None.

View File

@ -83,8 +83,8 @@ class CrossEntropyWithLabelSmooth(_Loss):
CrossEntropyWith LabelSmooth.
Args:
smooth_factor (float): smooth factor, default=0.
num_classes (int): num classes
smooth_factor (float): smooth factor for label smooth. Default is 0.
num_classes (int): number of classes. Default is 1000.
Returns:
None.

View File

@ -45,7 +45,7 @@ Dataset used: [imagenet](http://www.image-net.org/)
- HardwareGPU
- Prepare hardware environment with GPU processor.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -83,7 +83,7 @@ class SE(nn.Cell):
SE warpper definition.
Args:
num_out (int): Output channel.
num_out (int): Numbers of output channels.
ratio (int): middle output ratio.
Returns:
@ -301,7 +301,7 @@ class MobileNetV3(nn.Cell):
def _make_layer(self, kernel_size, exp_ch, out_channel, use_se, act_func, stride=1):
mid_planes = exp_ch
out_planes = out_channel
#num_in, num_mid, num_out, kernel_size, stride=1, act_type='relu', use_se=False):
layer = ResUnit(self.inplanes, mid_planes, out_planes,
kernel_size, stride=stride, act_type=act_func, use_se=use_se)
self.inplanes = out_planes

View File

@ -68,8 +68,8 @@ class CrossEntropyWithLabelSmooth(_Loss):
CrossEntropyWith LabelSmooth.
Args:
smooth_factor (float): smooth factor, default=0.
num_classes (int): num classes
smooth_factor (float): smooth factor for label smooth. Default is 0.
num_classes (int): number of classes. Default is 1000.
Returns:
None.

View File

@ -47,7 +47,6 @@ def create_dataset(dataset_path, config, do_train, repeat_num=1):
C.RandomCropDecodeResize(config.image_size),
C.RandomHorizontalFlip(prob=0.5),
C.RandomColorAdjust(brightness=0.4, saturation=0.5) # fast mode
# C.RandomColorAdjust(brightness=0.4, contrast=0.5, saturation=0.5, hue=0.2)
]
else:
trans = [

View File

@ -151,7 +151,7 @@ class _DatasetIter:
class _DatasetIterMSLoopSink(_DatasetIter):
"""Iter for context (device_target=Ascend)"""
"""Iter for context when device_target is Ascend"""
def __init__(self, dataset, sink_size, epoch_num, iter_first_order):
super().__init__(dataset, sink_size, epoch_num)
sink_count = 1
@ -179,7 +179,7 @@ class _DatasetIterMSLoopSink(_DatasetIter):
class _DatasetIterMS(_DatasetIter):
"""Iter for MS(enable_loop_sink=False)."""
"""Iter for MS when enable_loop_sink is False."""
def __init__(self, dataset, sink_size, epoch_num):
super().__init__(dataset, sink_size, epoch_num)
if sink_size > 0:

View File

@ -283,7 +283,7 @@ class ResNet(nn.Cell):
frequency=frequency, batch_size=batch_size)
self.bn1 = _bn(64)
self.relu = P.ReLU()
# self.maxpool = P.MaxPoolWithArgmax(padding="same", ksize=3, strides=2)
self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, pad_mode="same")
self.layer1 = self._make_layer(block,

View File

@ -56,7 +56,7 @@ For FP16 operators, if the input data type is FP32, the backend of MindSpore wil
- HardwareAscend/GPU
- Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend , please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -23,15 +23,12 @@ def get_param_groups(network):
parameter_name = x.name
if parameter_name.endswith('.bias'):
# all bias not using weight decay
# print('no decay:{}'.format(parameter_name))
no_decay_params.append(x)
elif parameter_name.endswith('.gamma'):
# bn weight bias not using weight decay, be carefully for now x not include BN
# print('no decay:{}'.format(parameter_name))
no_decay_params.append(x)
elif parameter_name.endswith('.beta'):
# bn weight bias not using weight decay, be carefully for now x not include BN
# print('no decay:{}'.format(parameter_name))
no_decay_params.append(x)
else:
decay_params.append(x)

View File

@ -40,7 +40,7 @@ Dataset used: [imagenet](http://www.image-net.org/)
- Hardware(GPU)
- Prepare hardware environment with GPU processor.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below:
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -66,7 +66,6 @@ def create_dataset(dataset_path, do_train, rank, group_size, repeat_num=1):
trans += [
toBGR(),
C.Rescale(1.0 / 255.0, 0.0),
# C.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
C.HWC2CHW(),
C2.TypeCast(mstype.float32)
]

View File

@ -79,7 +79,6 @@ class ShuffleV2Block(nn.Cell):
def channel_shuffle(self, x):
batchsize, num_channels, height, width = P.Shape()(x)
##assert (num_channels % 4 == 0)
x = P.Reshape()(x, (batchsize * num_channels // 2, 2, height * width,))
x = P.Transpose()(x, (1, 0, 2,))
x = P.Reshape()(x, (2, -1, num_channels // 2, height, width,))

View File

@ -162,7 +162,6 @@ def create_voc_label(is_training):
voc_dir = config.voc_dir
cls_map = {name: i for i, name in enumerate(config.coco_classes)}
sub_dir = 'train' if is_training else 'eval'
# sub_dir = 'train'
voc_dir = os.path.join(voc_dir, sub_dir)
if not os.path.isdir(voc_dir):
raise ValueError(f'Cannot find {sub_dir} dataset path.')

View File

@ -14,7 +14,6 @@
# ============================================================================
"""
#################train vgg16 example on cifar10########################
python train.py --data_path=$DATA_HOME --device_id=$DEVICE_ID
"""
import argparse
import datetime

View File

@ -146,7 +146,7 @@ def _preprocess_true_boxes(true_boxes, anchors, in_shape, num_classes,
# input_shape is [h, w]
true_boxes[..., 0:2] = boxes_xy / input_shape[::-1]
true_boxes[..., 2:4] = boxes_wh / input_shape[::-1]
# true_boxes = [xywh]
# true_boxes [x, y, w, h]
grid_shapes = [input_shape // 32, input_shape // 16, input_shape // 8]
# grid_shape [h, w]

View File

@ -153,7 +153,7 @@ def _preprocess_true_boxes(true_boxes, anchors, in_shape, num_classes,
# input_shape is [h, w]
true_boxes[..., 0:2] = boxes_xy / input_shape[::-1]
true_boxes[..., 2:4] = boxes_wh / input_shape[::-1]
# true_boxes = [xywh]
# true_boxes [x, y, w, h]
grid_shapes = [input_shape // 32, input_shape // 16, input_shape // 8]
# grid_shape [h, w]

View File

@ -44,7 +44,6 @@ def preprocess_fn(image, box, is_training):
num_layers = anchors.shape[0] // 3
anchor_mask = [[6, 7, 8], [3, 4, 5], [0, 1, 2]]
true_boxes = np.array(true_boxes, dtype='float32')
# input_shape = np.array([in_shape, in_shape], dtype='int32')
input_shape = np.array(in_shape, dtype='int32')
boxes_xy = (true_boxes[..., 0:2] + true_boxes[..., 2:4]) // 2.
boxes_wh = true_boxes[..., 2:4] - true_boxes[..., 0:2]

View File

@ -105,7 +105,7 @@ class BertPretrainEva(nn.Cell):
def get_enwiki_512_dataset(batch_size=1, repeat_count=1, distribute_file=''):
'''
Get enwiki seq_length=512 dataset
Get enwiki dataset when seq_length is 512.
'''
ds = de.TFRecordDataset([cfg.data_file], cfg.schema_file, columns_list=["input_ids", "input_mask", "segment_ids",
"masked_lm_positions", "masked_lm_ids",

View File

@ -490,7 +490,7 @@ class BertAttention(nn.Cell):
# use_relative_position, supplementary logic
if self.use_relative_positions:
# 'relations_keys' = [F|T, F|T, H]
# relations_keys is [F|T, F|T, H]
relations_keys = self._generate_relative_positions_embeddings()
relations_keys = self.cast_compute_type(relations_keys)
# query_layer_t is [F, B, N, H]
@ -533,7 +533,7 @@ class BertAttention(nn.Cell):
# use_relative_position, supplementary logic
if self.use_relative_positions:
# 'relations_values' = [F|T, F|T, H]
# relations_values is [F|T, F|T, H]
relations_values = self._generate_relative_positions_embeddings()
relations_values = self.cast_compute_type(relations_values)
# attention_probs_t is [F, B, N, T]

View File

@ -165,7 +165,6 @@ def LoadNewestCkpt(load_finetune_checkpoint_dir, steps_per_epoch, epoch_num, pre
name_ext = os.path.splitext(filename)
if name_ext[-1] != ".ckpt":
continue
#steps_per_epoch = ds.get_dataset_size()
if filename.find(prefix) == 0 and not filename[pre_len].isalpha():
index = filename[pre_len:].find("-")
if index == 0 and max_num == 0:

View File

@ -49,7 +49,7 @@ The classical first-order optimization algorithm, such as SGD, has a small amoun
- HardwareAscend/GPU
- Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend , please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -110,7 +110,7 @@ class BertPretrainEva(nn.Cell):
def get_enwiki_512_dataset(batch_size=1, repeat_count=1, distribute_file=''):
'''
Get enwiki seq_length=512 dataset
Get enwiki dataset when seq_length is 512.
'''
ds = de.TFRecordDataset([cfg.data_file], cfg.schema_file, columns_list=["input_ids", "input_mask", "segment_ids",
"masked_lm_positions", "masked_lm_ids",

View File

@ -566,7 +566,7 @@ class BertAttention(nn.Cell):
# use_relative_position, supplementary logic
if self.use_relative_positions:
# 'relations_keys' = [F|T, F|T, H]
# relations_keys is [F|T, F|T, H]
relations_keys = self._generate_relative_positions_embeddings()
relations_keys = self.cast_compute_type(relations_keys)
# query_layer_t is [F, B, N, H]
@ -609,7 +609,7 @@ class BertAttention(nn.Cell):
# use_relative_position, supplementary logic
if self.use_relative_positions:
# 'relations_values' = [F|T, F|T, H]
# relations_values is [F|T, F|T, H]
relations_values = self._generate_relative_positions_embeddings()
relations_values = self.cast_compute_type(relations_values)
# attention_probs_t is [F, B, N, T]

View File

@ -155,7 +155,7 @@ class _DatasetIter:
class _DatasetIterMSLoopSink(_DatasetIter):
"""Iter for context (device_target=Ascend)"""
"""Iter for context, the device_target is Ascend."""
def __init__(self, dataset, sink_size, epoch_num, iter_first_order):
super().__init__(dataset, sink_size, epoch_num)

View File

@ -198,7 +198,7 @@ class THOR(Optimizer):
g = F.depend(g, fake_G)
new_grads = new_grads + (g, pooler_bias)
# for cls1 fc layer: mlm
# cls1 fully connect layer for masked language model(mlm)
mlm_fc_idx = encoder_layers_num * self.num_hidden_layers + 8
matrix_idx = self.num_hidden_layers * 6 + 4
g = gradients[mlm_fc_idx]
@ -327,7 +327,7 @@ class THOR(Optimizer):
g = self.cast(g, mstype.float32)
new_grads = new_grads + (g, pooler_bias)
# for cls1 fc layer: mlm
# cls1 fully connect layer for masked language model(mlm)
mlm_fc_idx = encoder_layers_num * self.num_hidden_layers + 8
matrix_idx = self.num_hidden_layers * 6 + 4
g = gradients[mlm_fc_idx]

View File

@ -203,7 +203,7 @@ class THOR(Optimizer):
g = F.depend(g, fake_G)
new_grads = new_grads + (g, pooler_bias)
# for cls1 fc layer: mlm
# cls1 fully connect layer for masked language model(mlm)
mlm_fc_idx = encoder_layers_num * self.num_hidden_layers + 8
matrix_idx = self.num_hidden_layers * 6 + 4
g = gradients[mlm_fc_idx]
@ -333,7 +333,7 @@ class THOR(Optimizer):
g = self.cast(g, mstype.float32)
new_grads = new_grads + (g, pooler_bias)
# for cls1 fc layer: mlm
# cls1 fully connect layer for masked language model(mlm)
mlm_fc_idx = encoder_layers_num * self.num_hidden_layers + 8
matrix_idx = self.num_hidden_layers * 6 + 4
g = gradients[mlm_fc_idx]

View File

@ -129,7 +129,6 @@ def LoadNewestCkpt(load_finetune_checkpoint_dir, steps_per_epoch, epoch_num, pre
name_ext = os.path.splitext(filename)
if name_ext[-1] != ".ckpt":
continue
# steps_per_epoch = ds.get_dataset_size()
if filename.find(prefix) == 0 and not filename[pre_len].isalpha():
index = filename[pre_len:].find("-")
if index == 0 and max_num == 0:

View File

@ -14,7 +14,6 @@
# ============================================================================
"""
#################train lstm example on aclImdb########################
python eval.py --ckpt_path=./lstm-20-390.ckpt
"""
import argparse
import os

View File

@ -103,7 +103,7 @@ class ImdbParser():
vocab = set(chain(*tokenized_features))
self.__vacab[seg] = vocab
# word_to_idx: {'hello': 1, 'world':111, ... '<unk>': 0}
# word_to_idx looks like {'hello': 1, 'world':111, ... '<unk>': 0}
word_to_idx = {word: i + 1 for i, word in enumerate(vocab)}
word_to_idx['<unk>'] = 0
self.__word2idx[seg] = word_to_idx
@ -147,7 +147,7 @@ class ImdbParser():
def get_datas(self, seg):
"""
return features, labels, and weight
get features, labels, and weight by gensim.
"""
features = np.array(self.__features[seg]).astype(np.int32)
labels = np.array(self.__labels[seg]).astype(np.int32)

View File

@ -14,7 +14,6 @@
# ============================================================================
"""
#################train lstm example on aclImdb########################
python train.py --preprocess=true --aclimdb_path=your_imdb_path --glove_path=your_glove_path
"""
import argparse
import os

View File

@ -472,7 +472,7 @@ More detail about LR scheduler could be found in `src/utils/lr_scheduler.py`.
- HardwareAscend/GPU
- Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend , please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -94,7 +94,6 @@ class TileBeam(nn.Cell):
# add an dim
input_tensor = self.expand(input_tensor, 1)
# get tile shape: [1, beam, ...]
# shape = self.shape(input_tensor)
tile_shape = (1,) + (self.beam_width,)
for _ in range(len(shape) - 1):
tile_shape = tile_shape + (1,)
@ -349,7 +348,7 @@ class BeamSearchDecoder(nn.Cell):
# add length penalty scores
penalty_len = self.length_penalty(state_length)
# return penalty_len
# get penalty length
log_probs = self.real_div(state_log_probs, penalty_len)
# sort according to scores

View File

@ -383,7 +383,6 @@ class BertNetworkWithLoss_td(nn.Cell):
if is_predistill:
new_param_dict = {}
for key, value in param_dict.items():
# new_key = re.sub('tinybert_', 'bert_', key)
new_key = re.sub('tinybert_', 'bert_', 'bert.' + key)
new_param_dict[new_key] = value
load_param_into_net(self.bert, new_param_dict)
@ -391,7 +390,6 @@ class BertNetworkWithLoss_td(nn.Cell):
new_param_dict = {}
for key, value in param_dict.items():
new_key = re.sub('tinybert_', 'bert_', key)
# new_key = re.sub('tinybert_', 'bert_', 'bert.'+ key)
new_param_dict[new_key] = value
load_param_into_net(self.bert, new_param_dict)
self.cast = P.Cast()

View File

@ -502,7 +502,7 @@ class BertAttention(nn.Cell):
attention_scores = self.matmul_trans_b(query_layer, key_layer)
# use_relative_position, supplementary logic
if self.use_relative_positions:
# 'relations_keys' = [F|T, F|T, H]
# relations_keys is [F|T, F|T, H]
relations_keys = self._generate_relative_positions_embeddings()
relations_keys = self.cast_compute_type(relations_keys)
# query_layer_t is [F, B, N, H]
@ -539,7 +539,7 @@ class BertAttention(nn.Cell):
context_layer = self.matmul(attention_probs, value_layer)
# use_relative_position, supplementary logic
if self.use_relative_positions:
# 'relations_values' = [F|T, F|T, H]
# relations_values is [F|T, F|T, H]
relations_values = self._generate_relative_positions_embeddings()
relations_values = self.cast_compute_type(relations_values)
# attention_probs_t is [F, B, N, T]

View File

@ -258,7 +258,7 @@ class BeamSearchDecoder(nn.Cell):
# add length penalty scores
penalty_len = self.length_penalty(state_length)
# return penalty_len
# get penalty length
log_probs = self.real_div(state_log_probs, penalty_len)
# sort according to scores

View File

@ -55,7 +55,7 @@ class ClipGradients(nn.Cell):
grads,
clip_type,
clip_value):
"""return grads"""
"""Defines the gradients clip."""
if clip_type != 0 and clip_type != 1:
return grads

View File

@ -156,6 +156,7 @@ class WideDeepModel(nn.Cell):
emb64_multi_size = 20900
indicator_size = 16
deep_dim_list = [1024, 1024, 1024, 1024, 1024]
wide_reg_coef = [0.0, 0.0]
deep_reg_coef = [0.0, 0.0]
wide_lr = 0.2

View File

@ -43,7 +43,7 @@ Dataset used: [Oxford-IIIT Pet](https://www.robots.ox.ac.uk/~vgg/data/pets/)
- HardwareAscend/GPU)
- Prepare hardware environment with Ascend or GPU. If you want to try Ascend, please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -335,7 +335,6 @@ class GhostNet(nn.Cell):
self.blocks = []
for layer_cfg in self.cfgs:
#print (layer_cfg)
self.blocks.append(self._make_layer(kernel_size=layer_cfg[0],
exp_ch=_make_divisible(
self.inplanes * layer_cfg[3]),

View File

@ -48,7 +48,7 @@ Dataset used: [Oxford-IIIT Pet](https://www.robots.ox.ac.uk/~vgg/data/pets/)
- HardwareAscend/GPU
- Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend, please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -105,7 +105,7 @@ class SE(nn.Cell):
SE warpper definition.
Args:
num_out (int): Output channel.
num_out (int): output channel.
ratio (int): middle output ratio.
Returns:

View File

@ -36,7 +36,7 @@ Dataset used: [Oxford-IIIT Pet](https://www.robots.ox.ac.uk/~vgg/data/pets/)
- HardwareAscend/GPU
- Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend, please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -23,7 +23,7 @@ Dataset used: [COCO2017](<http://images.cocodataset.org/>)
- HardwareAscend/GPU
- Prepare hardware environment with Ascend or GPU processor. If you want to try Ascend, please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get the resources.
- Framework
- [MindSpore](http://10.90.67.50/mindspore/archive/20200506/OpenSource/me_vm_x86/)
- [MindSpore](https://www.mindspore.cn/install/en)
- For more information, please check the resources below
- [MindSpore tutorials](https://www.mindspore.cn/tutorial/zh-CN/master/index.html)
- [MindSpore API](https://www.mindspore.cn/api/zh-CN/master/index.html)

View File

@ -84,7 +84,6 @@ class ConvBNReLU(nn.Cell):
def construct(self, x):
output = self.features(x)
# print(output.shape)
return output
@ -267,8 +266,6 @@ class GhostModule(nn.Cell):
def construct(self, x):
x1 = self.primary_conv(x)
x2 = self.cheap_operation(x1)
# print(x1.shape)
# print(x2.shape)
return self.concat((x1, x2))
@ -342,7 +339,6 @@ class GhostBottleneck(nn.Cell):
out = self.add(shortcut, out)
if self.last_relu:
out = self.relu(out)
# print(out.shape)
return out
def _get_pad(self, kernel_size):
@ -410,7 +406,6 @@ class InvertedResidual(nn.Cell):
x = self.add(identity, x)
if self.last_relu:
x = self.relu(x)
# print(x.shape)
return x
@ -675,7 +670,6 @@ class SSDWithGhostNet(nn.Cell):
def __init__(self, model_cfgs, multiplier=1., round_nearest=8):
super(SSDWithGhostNet, self).__init__()
self.cfgs = model_cfgs['cfg']
# self.inplanes = 16 ## for "1x"
self.inplanes = 20 # for "1.3x"
first_conv_in_channel = 3
first_conv_out_channel = _make_divisible(multiplier * self.inplanes)
@ -686,7 +680,6 @@ class SSDWithGhostNet(nn.Cell):
layer_index = 0
for layer_cfg in self.cfgs:
# print(layer_cfg)
if layer_index == 11:
hidden_dim = int(round(self.inplanes * 6))
self.expand_layer_conv_11 = ConvBNReLU(
@ -711,7 +704,6 @@ class SSDWithGhostNet(nn.Cell):
def _make_layer(self, kernel_size, exp_ch, out_channel, use_se, act_func, stride=1):
mid_planes = exp_ch
out_planes = out_channel
# num_in, num_mid, num_out, kernel_size, stride=1, act_type='relu', use_se=False):
layer = GhostBottleneck(self.inplanes, mid_planes, out_planes,
kernel_size, stride=stride, act_type=act_func, use_se=use_se)
self.inplanes = out_planes

View File

@ -23,10 +23,8 @@ from mindspore import context, Tensor
from mindspore.communication.management import init
from mindspore.train.callback import CheckpointConfig, ModelCheckpoint, LossMonitor, TimeMonitor
from mindspore.train import Model, ParallelMode
# from mindspore.context import ParallelMode
from mindspore.train.serialization import load_checkpoint, load_param_into_net
from src.ssd_ghostnet import SSD300, SSDWithLossCell, TrainingWrapper, ssd_ghostnet
# from src.config_ghostnet_1x import config
from src.config_ghostnet_13x import config
from src.dataset import create_ssd_dataset, data_to_mindrecord_byte_image, voc_data_to_mindrecord
from src.lr_schedule import get_lr
@ -124,7 +122,6 @@ def main():
backbone = ssd_ghostnet()
ssd = SSD300(backbone=backbone, config=config)
# print(ssd)
net = SSDWithLossCell(ssd, config)
init_net_param(net)

View File

@ -149,7 +149,6 @@ if __name__ == "__main__":
# pass mr_api arguments
os.environ['graph_api_args'] = args.graph_api_args
# import mr_api
try:
mr_api = import_module(args.mindrecord_script + '.mr_api')
except ModuleNotFoundError:

View File

@ -13,22 +13,19 @@
# limitations under the License.
# ============================================================================
"""wide and deep model"""
import numpy as np
from mindspore import nn
from mindspore import Parameter, ParameterTuple
import mindspore.common.dtype as mstype
from mindspore.ops import functional as F
from mindspore.ops import composite as C
from mindspore.ops import operations as P
# from mindspore.nn import Dropout
from mindspore.nn.optim import Adam, FTRL
# from mindspore.nn.metrics import Metric
from mindspore.common.initializer import Uniform, initializer
# from mindspore.train.callback import ModelCheckpoint, CheckpointConfig
from mindspore.parallel._utils import _get_device_num, _get_parallel_mode, _get_gradients_mean
from mindspore.context import ParallelMode
from mindspore.nn.wrap.grad_reducer import DistributedGradReducer
from mindspore.communication.management import get_group_size
import numpy as np
np_type = np.float32
ms_type = mstype.float32
@ -110,8 +107,6 @@ class DenseLayer(nn.Cell):
def construct(self, x):
x = self.act_func(x)
# if self.training:
# x = self.dropout(x)
x = self.mul(x, self.scale_coef)
if self.convert_dtype:
x = self.cast(x, mstype.float16)

View File

@ -13,6 +13,7 @@
# limitations under the License.
# ============================================================================
"""fused layernorm"""
import numpy as np
from mindspore.ops import operations as P
from mindspore.ops import functional as F
from mindspore.common.parameter import Parameter
@ -21,8 +22,6 @@ from mindspore.ops.primitive import constexpr
import mindspore.common.dtype as mstype
from mindspore.nn.cell import Cell
import numpy as np
__all__ = ['FusedLayerNorm']

View File

@ -13,10 +13,10 @@
# limitations under the License.
# ============================================================================
"""Dataset module."""
import numpy as np
from PIL import Image
import mindspore.dataset as de
import mindspore.dataset.vision.c_transforms as C
import numpy as np
from .ei_dataset import HwVocRawDataset
from .utils import custom_transforms as tr