固件与驱动版本:1.0.12 CANN版本:5.0.4alpha005
Python:Pyhton3.7.16


import os
import mindspore
from mindspore import Model, context
import ipywidgets as wgs
class SSDWithMobileNetV2(nn.Cell):
"""
MobileNetV2 architecture for SSD backbone.
Args:
width_mult (int): Channels multiplier for round to 8/16 and others. Default is 1.
inverted_residual_setting (list): Inverted residual settings. Default is None
round_nearest (list): Channel round to. Default is 8
Returns:
Tensor, the 13th feature after ConvBNReLU in MobileNetV2.
Tensor, the last feature in MobileNetV2.
Examples:
>>> SSDWithMobileNetV2()
"""
def __init__(self, width_mult=1.0, inverted_residual_setting=None, round_nearest=8):
super(SSDWithMobileNetV2, self).__init__()
block = InvertedResidual
input_channel = 32
last_channel = 1280
if inverted_residual_setting is None:
inverted_residual_setting = [
# t, c, n, s
[1, 16, 1, 1],
[6, 24, 2, 2],
[6, 32, 3, 2],
[6, 64, 4, 2],
[6, 96, 3, 1],
[6, 160, 3, 2],
[6, 320, 1, 1],
]
if len(inverted_residual_setting[0]) != 4:
raise ValueError("inverted_residual_setting should be non-empty "
"or a 4-element list, got {}".format(inverted_residual_setting))
#building first layer
input_channel = _make_divisible(input_channel * width_mult, round_nearest)
self.last_channel = _make_divisible(last_channel * max(1.0, width_mult), round_nearest)
features = [ConvBNReLU(3, input_channel, stride=2)]
# building inverted residual blocks
layer_index = 0
for t, c, n, s in inverted_residual_setting:
output_channel = _make_divisible(c * width_mult, round_nearest)
for i in range(n):
if layer_index == 13:
hidden_dim = int(round(input_channel * t))
self.expand_layer_conv_13 = ConvBNReLU(input_channel, hidden_dim, kernel_size=1)
stride = s if i == 0 else 1
features.append(block(input_channel, output_channel, stride, expand_ratio=t))
input_channel = output_channel
layer_index += 1
# building last several layers
features.append(ConvBNReLU(input_channel, self.last_channel, kernel_size=1))
self.features_1 = nn.SequentialCell(features[:14])
self.features_2 = nn.SequentialCell(features[14:])
def construct(self, x):
out = self.features_1(x)
expand_layer_conv_13 = self.expand_layer_conv_13(out)
out = self.features_2(out)
return expand_layer_conv_13, out
def get_out_channels(self):
return self.last_channel
def ssd_model_build():
if model_name == "ssd300":
backbone = ssd_mobilenet_v2()
ssd = SSD300(backbone=backbone)
init_net_param(ssd)
else:
raise ValueError(f'config.model: {model_name} is not supported')
return ssd
ssd = ssd_model_build()
固件与驱动版本:1.0.12 CANN版本:5.0.4alpha005
Python:Pyhton3.7.16
import os
import mindspore
from mindspore import Model, context
import ipywidgets as wgs
class SSDWithMobileNetV2(nn.Cell):
"""
MobileNetV2 architecture for SSD backbone.
Args:
width_mult (int): Channels multiplier for round to 8/16 and others. Default is 1.
inverted_residual_setting (list): Inverted residual settings. Default is None
round_nearest (list): Channel round to. Default is 8
Returns:
Tensor, the 13th feature after ConvBNReLU in MobileNetV2.
Tensor, the last feature in MobileNetV2.
Examples:
>>> SSDWithMobileNetV2()
"""
def __init__(self, width_mult=1.0, inverted_residual_setting=None, round_nearest=8):
super(SSDWithMobileNetV2, self).__init__()
block = InvertedResidual
input_channel = 32
last_channel = 1280
if inverted_residual_setting is None:
inverted_residual_setting = [
# t, c, n, s
[1, 16, 1, 1],
[6, 24, 2, 2],
[6, 32, 3, 2],
[6, 64, 4, 2],
[6, 96, 3, 1],
[6, 160, 3, 2],
[6, 320, 1, 1],
]
if len(inverted_residual_setting[0]) != 4:
raise ValueError("inverted_residual_setting should be non-empty "
"or a 4-element list, got {}".format(inverted_residual_setting))
#building first layer
input_channel = _make_divisible(input_channel * width_mult, round_nearest)
self.last_channel = _make_divisible(last_channel * max(1.0, width_mult), round_nearest)
features = [ConvBNReLU(3, input_channel, stride=2)]
# building inverted residual blocks
layer_index = 0
for t, c, n, s in inverted_residual_setting:
output_channel = _make_divisible(c * width_mult, round_nearest)
for i in range(n):
if layer_index == 13:
hidden_dim = int(round(input_channel * t))
self.expand_layer_conv_13 = ConvBNReLU(input_channel, hidden_dim, kernel_size=1)
stride = s if i == 0 else 1
features.append(block(input_channel, output_channel, stride, expand_ratio=t))
input_channel = output_channel
layer_index += 1
# building last several layers
features.append(ConvBNReLU(input_channel, self.last_channel, kernel_size=1))
self.features_1 = nn.SequentialCell(features[:14])
self.features_2 = nn.SequentialCell(features[14:])
def construct(self, x):
out = self.features_1(x)
expand_layer_conv_13 = self.expand_layer_conv_13(out)
out = self.features_2(out)
return expand_layer_conv_13, out
def get_out_channels(self):
return self.last_channel
def ssd_model_build():
if model_name == "ssd300":
backbone = ssd_mobilenet_v2()
ssd = SSD300(backbone=backbone)
init_net_param(ssd)
else:
raise ValueError(f'config.model: {model_name} is not supported')
return ssd
ssd = ssd_model_build()
--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) /tmp/ipykernel_2447/3361837525.py in <module> ----> 1 ssd = ssd_model_build() /tmp/ipykernel_2447/524008363.py in ssd_model_build() 3 def ssd_model_build(): 4 if model_name == "ssd300": ----> 5 backbone = ssd_mobilenet_v2() 6 ssd = SSD300(backbone=backbone) 7 init_net_param(ssd) /tmp/ipykernel_2447/2467046382.py in ssd_mobilenet_v2(**kwargs) 1 def ssd_mobilenet_v2(**kwargs): ----> 2 return SSDWithMobileNetV2(**kwargs) /tmp/ipykernel_2447/1099657946.py in __init__(self, width_mult, inverted_residual_setting, round_nearest) 15 """ 16 def __init__(self, width_mult=1.0, inverted_residual_setting=None, round_nearest=8): ---> 17 super(SSDWithMobileNetV2, self).__init__() 18 block = InvertedResidual 19 input_channel = 32 ~/miniconda3/envs/mindspore_py37/lib/python3.7/site-packages/mindspore/nn/cell.py in __init__(self, auto_prefix, flags) 117 self.exist_names = set("") 118 self.exist_objs = set() --> 119 init_pipeline() 120 121 # call gc to release GE session resources used by non-used cell objects RuntimeError: mindspore/core/utils/ms_context.cc:130 CreateTensorPrintThread] Get acltdt handle failed