Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
929ef67b
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
929ef67b
编写于
5月 25, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
5月 25, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1411 pylint warning clean
Merge pull request !1411 from liubuyu/master
上级
c8f69f5d
107794fa
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
61 addition
and
75 deletion
+61
-75
tests/st/control/test_multigraph_sink.py
tests/st/control/test_multigraph_sink.py
+7
-7
tests/st/control/test_while.py
tests/st/control/test_while.py
+2
-3
tests/st/mem_reuse/check_file.py
tests/st/mem_reuse/check_file.py
+3
-3
tests/st/mem_reuse/resnet.py
tests/st/mem_reuse/resnet.py
+11
-12
tests/st/mem_reuse/resnet_cifar_memreuse.py
tests/st/mem_reuse/resnet_cifar_memreuse.py
+4
-4
tests/st/mem_reuse/resnet_cifar_normal.py
tests/st/mem_reuse/resnet_cifar_normal.py
+4
-4
tests/st/networks/models/resnetv1_5.py
tests/st/networks/models/resnetv1_5.py
+11
-16
tests/st/summary/test_davinci_summary.py
tests/st/summary/test_davinci_summary.py
+1
-1
tests/st/tbe_networks/export_geir.py
tests/st/tbe_networks/export_geir.py
+1
-5
tests/st/tbe_networks/resnet.py
tests/st/tbe_networks/resnet.py
+11
-12
tests/st/tbe_networks/resnet_cifar.py
tests/st/tbe_networks/resnet_cifar.py
+3
-3
tests/st/tbe_networks/test_resnet_cifar_1p.py
tests/st/tbe_networks/test_resnet_cifar_1p.py
+2
-3
tests/st/tbe_networks/test_resnet_cifar_8p.py
tests/st/tbe_networks/test_resnet_cifar_8p.py
+1
-2
未找到文件。
tests/st/control/test_multigraph_sink.py
浏览文件 @
929ef67b
...
...
@@ -21,7 +21,7 @@ from mindspore.common import ms_function
from
mindspore.common.tensor
import
Tensor
def
setup_module
(
module
):
def
setup_module
():
context
.
set_context
(
mode
=
context
.
PYNATIVE_MODE
,
device_target
=
"Ascend"
)
...
...
@@ -33,7 +33,7 @@ c5 = Tensor([14], mstype.int32)
@
ms_function
def
simple_if
(
x
,
y
,
z
):
def
simple_if
(
x
,
y
):
if
x
<
y
:
x
=
x
+
1
else
:
...
...
@@ -43,7 +43,7 @@ def simple_if(x, y, z):
@
ms_function
def
if_by_if
(
x
,
y
,
z
):
def
if_by_if
(
x
,
y
):
if
x
<
y
:
x
=
x
+
1
if
y
>
x
:
...
...
@@ -66,7 +66,7 @@ def if_in_if(x, y, z):
@
ms_function
def
simple_while
(
x
,
y
,
z
):
def
simple_while
(
x
,
y
):
y
=
y
+
4
while
x
<
y
:
x
=
x
+
1
...
...
@@ -137,13 +137,13 @@ def while_in_while_in_while(x, y, z):
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
env_onecard
def
test_simple_if
():
output
=
simple_if
(
c1
,
c2
,
c3
)
output
=
simple_if
(
c1
,
c2
)
expect
=
Tensor
([
6
],
mstype
.
int32
)
assert
output
==
expect
def
test_if_by_if
():
output
=
if_by_if
(
c1
,
c2
,
c3
)
output
=
if_by_if
(
c1
,
c2
)
expect
=
Tensor
([
8
],
mstype
.
int32
)
assert
output
==
expect
...
...
@@ -163,7 +163,7 @@ def test_if_in_if():
@
pytest
.
mark
.
platform_arm_ascend_training
@
pytest
.
mark
.
env_onecard
def
test_simple_while
():
output
=
simple_while
(
c1
,
c2
,
c3
)
output
=
simple_while
(
c1
,
c2
)
expect
=
Tensor
([
21
],
mstype
.
int32
)
assert
output
==
expect
...
...
tests/st/control/test_while.py
浏览文件 @
929ef67b
...
...
@@ -18,7 +18,7 @@ from mindspore.common import dtype as mstype
@
ms_function
def
t1_while
(
x
,
y
,
z
):
def
t1_while
(
x
,
y
):
y
=
y
+
4
while
x
<
y
:
x
=
x
+
1
...
...
@@ -30,9 +30,8 @@ def test_net():
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
)
c1
=
Tensor
([
2
],
mstype
.
int32
)
c2
=
Tensor
([
14
],
mstype
.
int32
)
c3
=
Tensor
([
1
],
mstype
.
int32
)
expect
=
Tensor
([
21
],
mstype
.
int32
)
ret
=
t1_while
(
c1
,
c2
,
c3
)
ret
=
t1_while
(
c1
,
c2
)
assert
ret
==
expect
...
...
tests/st/mem_reuse/check_file.py
浏览文件 @
929ef67b
...
...
@@ -19,8 +19,8 @@ curr_path = os.path.abspath(os.curdir)
file_memreuse
=
curr_path
+
"/mem_reuse_check/memreuse.ir"
file_normal
=
curr_path
+
"/mem_reuse_check/normal_mem.ir"
checker
=
os
.
path
.
exists
(
file_memreuse
)
assert
checker
==
True
assert
checker
,
True
checker
=
os
.
path
.
exists
(
file_normal
)
assert
checker
==
True
assert
checker
,
True
checker
=
filecmp
.
cmp
(
file_memreuse
,
file_normal
)
assert
checker
==
True
assert
checker
,
True
tests/st/mem_reuse/resnet.py
浏览文件 @
929ef67b
...
...
@@ -99,8 +99,7 @@ class ResidualBlock(nn.Cell):
def
__init__
(
self
,
in_channels
,
out_channels
,
stride
=
1
,
down_sample
=
False
):
stride
=
1
):
super
(
ResidualBlock
,
self
).
__init__
()
out_chls
=
out_channels
//
self
.
expansion
...
...
@@ -188,7 +187,7 @@ class ResidualBlockWithDown(nn.Cell):
class
MakeLayer0
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer0
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
1
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
stride
)
...
...
@@ -204,7 +203,7 @@ class MakeLayer0(nn.Cell):
class
MakeLayer1
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer1
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
stride
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
1
)
...
...
@@ -222,7 +221,7 @@ class MakeLayer1(nn.Cell):
class
MakeLayer2
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer2
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
stride
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
1
)
...
...
@@ -244,7 +243,7 @@ class MakeLayer2(nn.Cell):
class
MakeLayer3
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer3
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
stride
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
1
)
...
...
@@ -260,7 +259,7 @@ class MakeLayer3(nn.Cell):
class
ResNet
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
num_classes
=
100
,
batch_size
=
32
):
def
__init__
(
self
,
block
,
num_classes
=
100
,
batch_size
=
32
):
super
(
ResNet
,
self
).
__init__
()
self
.
batch_size
=
batch_size
self
.
num_classes
=
num_classes
...
...
@@ -271,10 +270,10 @@ class ResNet(nn.Cell):
self
.
relu
=
P
.
ReLU
()
self
.
maxpool
=
nn
.
MaxPool2d
(
kernel_size
=
3
,
stride
=
2
,
pad_mode
=
"same"
)
self
.
layer1
=
MakeLayer0
(
block
,
layer_num
[
0
],
in_channels
=
64
,
out_channels
=
256
,
stride
=
1
)
self
.
layer2
=
MakeLayer1
(
block
,
layer_num
[
1
],
in_channels
=
256
,
out_channels
=
512
,
stride
=
2
)
self
.
layer3
=
MakeLayer2
(
block
,
layer_num
[
2
],
in_channels
=
512
,
out_channels
=
1024
,
stride
=
2
)
self
.
layer4
=
MakeLayer3
(
block
,
layer_num
[
3
],
in_channels
=
1024
,
out_channels
=
2048
,
stride
=
2
)
self
.
layer1
=
MakeLayer0
(
block
,
in_channels
=
64
,
out_channels
=
256
,
stride
=
1
)
self
.
layer2
=
MakeLayer1
(
block
,
in_channels
=
256
,
out_channels
=
512
,
stride
=
2
)
self
.
layer3
=
MakeLayer2
(
block
,
in_channels
=
512
,
out_channels
=
1024
,
stride
=
2
)
self
.
layer4
=
MakeLayer3
(
block
,
in_channels
=
1024
,
out_channels
=
2048
,
stride
=
2
)
self
.
pool
=
P
.
ReduceMean
(
keep_dims
=
True
)
self
.
squeeze
=
P
.
Squeeze
(
axis
=
(
2
,
3
))
...
...
@@ -298,4 +297,4 @@ class ResNet(nn.Cell):
def
resnet50
(
batch_size
,
num_classes
):
return
ResNet
(
ResidualBlock
,
[
3
,
4
,
6
,
3
],
num_classes
,
batch_size
)
return
ResNet
(
ResidualBlock
,
num_classes
,
batch_size
)
tests/st/mem_reuse/resnet_cifar_memreuse.py
浏览文件 @
929ef67b
...
...
@@ -114,9 +114,9 @@ class CrossEntropyLoss(nn.Cell):
def
construct
(
self
,
logits
,
label
):
label
=
self
.
one_hot
(
label
,
F
.
shape
(
logits
)[
1
],
self
.
one
,
self
.
zero
)
loss
=
self
.
cross_entropy
(
logits
,
label
)[
0
]
loss
=
self
.
mean
(
loss
,
(
-
1
,))
return
loss
loss
_func
=
self
.
cross_entropy
(
logits
,
label
)[
0
]
loss
_func
=
self
.
mean
(
loss_func
,
(
-
1
,))
return
loss
_func
if
__name__
==
'__main__'
:
...
...
@@ -146,4 +146,4 @@ if __name__ == '__main__':
res
=
model
.
eval
(
eval_dataset
)
print
(
"result: "
,
res
)
checker
=
os
.
path
.
exists
(
"./memreuse.ir"
)
assert
checker
==
True
assert
checker
,
True
tests/st/mem_reuse/resnet_cifar_normal.py
浏览文件 @
929ef67b
...
...
@@ -114,9 +114,9 @@ class CrossEntropyLoss(nn.Cell):
def
construct
(
self
,
logits
,
label
):
label
=
self
.
one_hot
(
label
,
F
.
shape
(
logits
)[
1
],
self
.
one
,
self
.
zero
)
loss
=
self
.
cross_entropy
(
logits
,
label
)[
0
]
loss
=
self
.
mean
(
loss
,
(
-
1
,))
return
loss
loss
_func
=
self
.
cross_entropy
(
logits
,
label
)[
0
]
loss
_func
=
self
.
mean
(
loss_func
,
(
-
1
,))
return
loss
_func
if
__name__
==
'__main__'
:
...
...
@@ -146,4 +146,4 @@ if __name__ == '__main__':
res
=
model
.
eval
(
eval_dataset
)
print
(
"result: "
,
res
)
checker
=
os
.
path
.
exists
(
"./normal_memreuse.ir"
)
assert
checker
==
True
assert
checker
,
True
tests/st/networks/models/resnetv1_5.py
浏览文件 @
929ef67b
...
...
@@ -95,8 +95,7 @@ class ResidualBlock(nn.Cell):
def
__init__
(
self
,
in_channels
,
out_channels
,
stride
=
1
,
down_sample
=
False
):
stride
=
1
):
super
(
ResidualBlock
,
self
).
__init__
()
out_chls
=
out_channels
//
self
.
expansion
...
...
@@ -184,7 +183,7 @@ class ResidualBlockWithDown(nn.Cell):
class
MakeLayer0
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer0
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
1
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
stride
)
...
...
@@ -200,7 +199,7 @@ class MakeLayer0(nn.Cell):
class
MakeLayer1
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer1
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
stride
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
1
)
...
...
@@ -218,7 +217,7 @@ class MakeLayer1(nn.Cell):
class
MakeLayer2
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer2
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
stride
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
1
)
...
...
@@ -240,7 +239,7 @@ class MakeLayer2(nn.Cell):
class
MakeLayer3
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer3
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
stride
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
1
)
...
...
@@ -256,7 +255,7 @@ class MakeLayer3(nn.Cell):
class
ResNet
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
num_classes
=
100
,
batch_size
=
32
):
def
__init__
(
self
,
block
,
num_classes
=
100
,
batch_size
=
32
):
super
(
ResNet
,
self
).
__init__
()
self
.
batch_size
=
batch_size
self
.
num_classes
=
num_classes
...
...
@@ -267,14 +266,10 @@ class ResNet(nn.Cell):
self
.
relu
=
P
.
ReLU
()
self
.
maxpool
=
nn
.
MaxPool2d
(
kernel_size
=
3
,
stride
=
2
,
pad_mode
=
"SAME"
)
self
.
layer1
=
MakeLayer0
(
block
,
layer_num
[
0
],
in_channels
=
64
,
out_channels
=
256
,
stride
=
1
)
self
.
layer2
=
MakeLayer1
(
block
,
layer_num
[
1
],
in_channels
=
256
,
out_channels
=
512
,
stride
=
2
)
self
.
layer3
=
MakeLayer2
(
block
,
layer_num
[
2
],
in_channels
=
512
,
out_channels
=
1024
,
stride
=
2
)
self
.
layer4
=
MakeLayer3
(
block
,
layer_num
[
3
],
in_channels
=
1024
,
out_channels
=
2048
,
stride
=
2
)
self
.
layer1
=
MakeLayer0
(
block
,
in_channels
=
64
,
out_channels
=
256
,
stride
=
1
)
self
.
layer2
=
MakeLayer1
(
block
,
in_channels
=
256
,
out_channels
=
512
,
stride
=
2
)
self
.
layer3
=
MakeLayer2
(
block
,
in_channels
=
512
,
out_channels
=
1024
,
stride
=
2
)
self
.
layer4
=
MakeLayer3
(
block
,
in_channels
=
1024
,
out_channels
=
2048
,
stride
=
2
)
self
.
pool
=
P
.
ReduceMean
(
keep_dims
=
True
)
self
.
fc
=
fc_with_initialize
(
512
*
block
.
expansion
,
num_classes
)
...
...
@@ -298,4 +293,4 @@ class ResNet(nn.Cell):
def
resnet50
(
batch_size
,
num_classes
):
return
ResNet
(
ResidualBlock
,
[
3
,
4
,
6
,
3
],
num_classes
,
batch_size
)
return
ResNet
(
ResidualBlock
,
num_classes
,
batch_size
)
tests/st/summary/test_davinci_summary.py
浏览文件 @
929ef67b
...
...
@@ -18,7 +18,7 @@ import numpy as np
from
apply_momentum
import
ApplyMomentum
import
mindspore.context
as
context
import
mindspore.nn
as
nn
import
mindspore.nn
as
wrap
from
mindspore.nn
import
wrap
from
mindspore
import
Tensor
,
Model
from
mindspore.common.api
import
ms_function
from
mindspore.nn.loss
import
SoftmaxCrossEntropyWithLogits
...
...
tests/st/tbe_networks/export_geir.py
浏览文件 @
929ef67b
...
...
@@ -13,12 +13,10 @@
# limitations under the License.
# ============================================================================
import
numpy
as
np
from
resnet_torch
import
resnet50
from
mindspore
import
Tensor
from
mindspore.train.serialization
import
save
,
load
,
_check_filedir_or_create
,
_chg_model_file_name_if_same_exist
,
\
_read_file_last_line
,
context
,
export
from
mindspore.train.serialization
import
context
,
export
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
)
...
...
@@ -26,6 +24,4 @@ context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
def
test_resnet50_export
(
batch_size
=
1
,
num_classes
=
5
):
input_np
=
np
.
random
.
uniform
(
0.0
,
1.0
,
size
=
[
batch_size
,
3
,
224
,
224
]).
astype
(
np
.
float32
)
net
=
resnet50
(
batch_size
,
num_classes
)
# param_dict = load_checkpoint("./resnet50-1_103.ckpt")
# load_param_into_net(net, param_dict)
export
(
net
,
Tensor
(
input_np
),
file_name
=
"./me_resnet50.pb"
,
file_format
=
"GEIR"
)
tests/st/tbe_networks/resnet.py
浏览文件 @
929ef67b
...
...
@@ -99,8 +99,7 @@ class ResidualBlock(nn.Cell):
def
__init__
(
self
,
in_channels
,
out_channels
,
stride
=
1
,
down_sample
=
False
):
stride
=
1
):
super
(
ResidualBlock
,
self
).
__init__
()
out_chls
=
out_channels
//
self
.
expansion
...
...
@@ -188,7 +187,7 @@ class ResidualBlockWithDown(nn.Cell):
class
MakeLayer0
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer0
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
1
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
stride
)
...
...
@@ -204,7 +203,7 @@ class MakeLayer0(nn.Cell):
class
MakeLayer1
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer1
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
stride
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
1
)
...
...
@@ -222,7 +221,7 @@ class MakeLayer1(nn.Cell):
class
MakeLayer2
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer2
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
stride
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
1
)
...
...
@@ -244,7 +243,7 @@ class MakeLayer2(nn.Cell):
class
MakeLayer3
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
in_channels
,
out_channels
,
stride
):
def
__init__
(
self
,
block
,
in_channels
,
out_channels
,
stride
):
super
(
MakeLayer3
,
self
).
__init__
()
self
.
a
=
ResidualBlockWithDown
(
in_channels
,
out_channels
,
stride
=
stride
,
down_sample
=
True
)
self
.
b
=
block
(
out_channels
,
out_channels
,
stride
=
1
)
...
...
@@ -260,7 +259,7 @@ class MakeLayer3(nn.Cell):
class
ResNet
(
nn
.
Cell
):
def
__init__
(
self
,
block
,
layer_num
,
num_classes
=
100
,
batch_size
=
32
):
def
__init__
(
self
,
block
,
num_classes
=
100
,
batch_size
=
32
):
super
(
ResNet
,
self
).
__init__
()
self
.
batch_size
=
batch_size
self
.
num_classes
=
num_classes
...
...
@@ -271,10 +270,10 @@ class ResNet(nn.Cell):
self
.
relu
=
P
.
ReLU
()
self
.
maxpool
=
P
.
MaxPoolWithArgmax
(
ksize
=
3
,
strides
=
2
,
padding
=
"SAME"
)
self
.
layer1
=
MakeLayer0
(
block
,
layer_num
[
0
],
in_channels
=
64
,
out_channels
=
256
,
stride
=
1
)
self
.
layer2
=
MakeLayer1
(
block
,
layer_num
[
1
],
in_channels
=
256
,
out_channels
=
512
,
stride
=
2
)
self
.
layer3
=
MakeLayer2
(
block
,
layer_num
[
2
],
in_channels
=
512
,
out_channels
=
1024
,
stride
=
2
)
self
.
layer4
=
MakeLayer3
(
block
,
layer_num
[
3
],
in_channels
=
1024
,
out_channels
=
2048
,
stride
=
2
)
self
.
layer1
=
MakeLayer0
(
block
,
in_channels
=
64
,
out_channels
=
256
,
stride
=
1
)
self
.
layer2
=
MakeLayer1
(
block
,
in_channels
=
256
,
out_channels
=
512
,
stride
=
2
)
self
.
layer3
=
MakeLayer2
(
block
,
in_channels
=
512
,
out_channels
=
1024
,
stride
=
2
)
self
.
layer4
=
MakeLayer3
(
block
,
in_channels
=
1024
,
out_channels
=
2048
,
stride
=
2
)
self
.
pool
=
P
.
ReduceMean
(
keep_dims
=
True
)
self
.
squeeze
=
P
.
Squeeze
(
axis
=
(
2
,
3
))
...
...
@@ -298,4 +297,4 @@ class ResNet(nn.Cell):
def
resnet50
(
batch_size
,
num_classes
):
return
ResNet
(
ResidualBlock
,
[
3
,
4
,
6
,
3
],
num_classes
,
batch_size
)
return
ResNet
(
ResidualBlock
,
num_classes
,
batch_size
)
tests/st/tbe_networks/resnet_cifar.py
浏览文件 @
929ef67b
...
...
@@ -116,9 +116,9 @@ class CrossEntropyLoss(nn.Cell):
def
construct
(
self
,
logits
,
label
):
label
=
self
.
one_hot
(
label
,
F
.
shape
(
logits
)[
1
],
self
.
one
,
self
.
zero
)
loss
=
self
.
cross_entropy
(
logits
,
label
)[
0
]
loss
=
self
.
mean
(
loss
,
(
-
1
,))
return
loss
loss
_func
=
self
.
cross_entropy
(
logits
,
label
)[
0
]
loss
_func
=
self
.
mean
(
loss_func
,
(
-
1
,))
return
loss
_func
if
__name__
==
'__main__'
:
...
...
tests/st/tbe_networks/test_resnet_cifar_1p.py
浏览文件 @
929ef67b
...
...
@@ -15,7 +15,7 @@
import
os
import
random
import
time
import
pytest
import
numpy
as
np
from
resnet
import
resnet50
...
...
@@ -30,9 +30,8 @@ from mindspore import Tensor
from
mindspore
import
context
from
mindspore.nn.optim.momentum
import
Momentum
from
mindspore.ops
import
operations
as
P
from
mindspore.train.callback
import
ModelCheckpoint
,
CheckpointConfig
,
Callback
from
mindspore.train.callback
import
Callback
from
mindspore.train.model
import
Model
from
mindspore.train.serialization
import
load_checkpoint
,
load_param_into_net
random
.
seed
(
1
)
np
.
random
.
seed
(
1
)
...
...
tests/st/tbe_networks/test_resnet_cifar_8p.py
浏览文件 @
929ef67b
...
...
@@ -15,11 +15,10 @@
import
os
import
random
from
multiprocessing
import
Process
,
Queue
import
numpy
as
np
import
pytest
from
multiprocessing
import
Process
,
Queue
from
resnet
import
resnet50
import
mindspore.common.dtype
as
mstype
import
mindspore.dataset
as
ds
import
mindspore.dataset.transforms.c_transforms
as
C
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录