Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
oneflow
提交
993b6d37
O
oneflow
项目概览
Oneflow-Inc
/
oneflow
上一次同步 2 年多
通知
13
Star
2733
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oneflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
993b6d37
编写于
7月 22, 2020
作者:
qq_22305325
提交者:
GitHub
7月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove deprecated call (#3246)
Co-authored-by:
N
Li Xinqi
<
lixinqi2010@gmail.com
>
上级
3f2ed3f2
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
85 addition
and
85 deletion
+85
-85
oneflow/python/benchmarks/bert_benchmark/bert.py
oneflow/python/benchmarks/bert_benchmark/bert.py
+9
-9
oneflow/python/benchmarks/bert_benchmark/pretrain.py
oneflow/python/benchmarks/bert_benchmark/pretrain.py
+7
-7
oneflow/python/benchmarks/cnn_benchmark/inceptionv3_model.py
oneflow/python/benchmarks/cnn_benchmark/inceptionv3_model.py
+24
-24
oneflow/python/benchmarks/cnn_benchmark/resnet_model.py
oneflow/python/benchmarks/cnn_benchmark/resnet_model.py
+1
-1
oneflow/python/test/deprecated/variable_scope.py
oneflow/python/test/deprecated/variable_scope.py
+3
-3
oneflow/python/test/models/bert.py
oneflow/python/test/models/bert.py
+9
-9
oneflow/python/test/models/inceptionv3.py
oneflow/python/test/models/inceptionv3.py
+24
-24
oneflow/python/test/models/pretrain.py
oneflow/python/test/models/pretrain.py
+7
-7
oneflow/python/test/models/resnet50.py
oneflow/python/test/models/resnet50.py
+1
-1
未找到文件。
oneflow/python/benchmarks/bert_benchmark/bert.py
浏览文件 @
993b6d37
...
...
@@ -25,8 +25,8 @@ class BertBackbone(object):
initializer_range
=
0.02
,
):
with
flow
.
deprecated
.
variable_scop
e
(
"bert"
):
with
flow
.
deprecated
.
variable_scop
e
(
"embeddings"
):
with
flow
.
scope
.
namespac
e
(
"bert"
):
with
flow
.
scope
.
namespac
e
(
"embeddings"
):
(
self
.
embedding_output_
,
self
.
embedding_table_
)
=
_EmbeddingLookup
(
input_ids_blob
=
input_ids_blob
,
vocab_size
=
vocab_size
,
...
...
@@ -48,7 +48,7 @@ class BertBackbone(object):
max_position_embeddings
=
max_position_embeddings
,
dropout_prob
=
hidden_dropout_prob
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"encoder"
):
with
flow
.
scope
.
namespac
e
(
"encoder"
):
attention_mask_blob
=
_CreateAttentionMaskFromInputMask
(
input_mask_blob
,
from_seq_length
=
seq_length
,
...
...
@@ -112,10 +112,10 @@ def _TransformerModel(
prev_output_blob
=
flow
.
reshape
(
input_blob
,
(
-
1
,
input_width
))
all_layer_output_blobs
=
[]
for
layer_idx
in
range
(
num_hidden_layers
):
with
flow
.
deprecated
.
variable_scop
e
(
"layer_%d"
%
layer_idx
):
with
flow
.
scope
.
namespac
e
(
"layer_%d"
%
layer_idx
):
layer_input_blob
=
prev_output_blob
with
flow
.
deprecated
.
variable_scop
e
(
"attention"
):
with
flow
.
deprecated
.
variable_scop
e
(
"self"
):
with
flow
.
scope
.
namespac
e
(
"attention"
):
with
flow
.
scope
.
namespac
e
(
"self"
):
attention_output_blob
=
_AttentionLayer
(
from_blob
=
layer_input_blob
,
to_blob
=
layer_input_blob
,
...
...
@@ -128,7 +128,7 @@ def _TransformerModel(
from_seq_length
=
seq_length
,
to_seq_length
=
seq_length
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"output"
):
with
flow
.
scope
.
namespac
e
(
"output"
):
attention_output_blob
=
_FullyConnected
(
attention_output_blob
,
input_size
=
num_attention_heads
*
attention_head_size
,
...
...
@@ -143,7 +143,7 @@ def _TransformerModel(
attention_output_blob
=
_LayerNorm
(
attention_output_blob
,
hidden_size
)
with
flow
.
deprecated
.
variable_scop
e
(
"intermediate"
):
with
flow
.
scope
.
namespac
e
(
"intermediate"
):
if
callable
(
intermediate_act_fn
):
act_fn
=
op_conf_util
.
kNone
else
:
...
...
@@ -160,7 +160,7 @@ def _TransformerModel(
intermediate_output_blob
=
intermediate_act_fn
(
intermediate_output_blob
)
with
flow
.
deprecated
.
variable_scop
e
(
"output"
):
with
flow
.
scope
.
namespac
e
(
"output"
):
layer_output_blob
=
_FullyConnected
(
intermediate_output_blob
,
input_size
=
intermediate_size
,
...
...
oneflow/python/benchmarks/bert_benchmark/pretrain.py
浏览文件 @
993b6d37
...
...
@@ -65,13 +65,13 @@ def PreTrain(
hidden_size
=
hidden_size
,
initializer_range
=
initializer_range
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"cls-loss"
):
with
flow
.
scope
.
namespac
e
(
"cls-loss"
):
total_loss
=
lm_loss
+
ns_loss
return
total_loss
,
lm_loss
,
ns_loss
def
PooledOutput
(
sequence_output
,
hidden_size
,
initializer_range
):
with
flow
.
deprecated
.
variable_scop
e
(
"bert-pooler"
):
with
flow
.
scope
.
namespac
e
(
"bert-pooler"
):
first_token_tensor
=
flow
.
slice
(
sequence_output
,
[
None
,
0
,
0
],
[
None
,
1
,
-
1
])
first_token_tensor
=
flow
.
reshape
(
first_token_tensor
,
[
-
1
,
hidden_size
])
pooled_output
=
bert_util
.
_FullyConnected
(
...
...
@@ -98,15 +98,15 @@ def _AddMaskedLanguageModelLoss(
hidden_act
,
initializer_range
,
):
with
flow
.
deprecated
.
variable_scop
e
(
"other"
):
with
flow
.
scope
.
namespac
e
(
"other"
):
sum_label_weight_blob
=
flow
.
math
.
reduce_sum
(
label_weight_blob
,
axis
=
[
-
1
])
ones
=
sum_label_weight_blob
*
0.0
+
1.0
sum_label_weight_blob
=
flow
.
math
.
reduce_sum
(
sum_label_weight_blob
)
batch_size
=
flow
.
math
.
reduce_sum
(
ones
)
sum_label_weight_blob
=
sum_label_weight_blob
/
batch_size
with
flow
.
deprecated
.
variable_scop
e
(
"cls-predictions"
):
with
flow
.
scope
.
namespac
e
(
"cls-predictions"
):
input_blob
=
_GatherIndexes
(
input_blob
,
positions_blob
,
seq_length
,
hidden_size
)
with
flow
.
deprecated
.
variable_scop
e
(
"transform"
):
with
flow
.
scope
.
namespac
e
(
"transform"
):
if
callable
(
hidden_act
):
act_fn
=
op_conf_util
.
kNone
else
:
...
...
@@ -136,7 +136,7 @@ def _AddMaskedLanguageModelLoss(
)
pre_example_loss
=
flow
.
reshape
(
pre_example_loss
,
[
-
1
,
max_predictions_per_seq
])
numerator
=
pre_example_loss
*
label_weight_blob
with
flow
.
deprecated
.
variable_scop
e
(
"loss"
):
with
flow
.
scope
.
namespac
e
(
"loss"
):
numerator
=
flow
.
math
.
reduce_sum
(
numerator
,
axis
=
[
-
1
])
denominator
=
sum_label_weight_blob
+
1e-5
loss
=
numerator
/
denominator
...
...
@@ -152,7 +152,7 @@ def _GatherIndexes(sequence_blob, positions_blob, seq_length, hidden_size):
def
_AddNextSentenceOutput
(
input_blob
,
label_blob
,
hidden_size
,
initializer_range
):
with
flow
.
deprecated
.
variable_scop
e
(
"cls-seq_relationship"
):
with
flow
.
scope
.
namespac
e
(
"cls-seq_relationship"
):
output_weight_blob
=
flow
.
get_variable
(
name
=
"output_weights"
,
shape
=
[
2
,
hidden_size
],
...
...
oneflow/python/benchmarks/cnn_benchmark/inceptionv3_model.py
浏览文件 @
993b6d37
...
...
@@ -54,12 +54,12 @@ def _conv2d_layer(
def
InceptionA
(
in_blob
,
index
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch1x1"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch1x1"
):
branch1x1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
64
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch5x5"
):
with
flow
.
scope
.
namespac
e
(
"branch5x5"
):
branch5x5_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
48
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -71,7 +71,7 @@ def InceptionA(in_blob, index):
strides
=
1
,
padding
=
"SAME"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3dbl"
):
with
flow
.
scope
.
namespac
e
(
"branch3x3dbl"
):
branch3x3dbl_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
64
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -91,7 +91,7 @@ def InceptionA(in_blob, index):
strides
=
1
,
padding
=
"SAME"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool_1
=
flow
.
nn
.
avg_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -121,12 +121,12 @@ def InceptionA(in_blob, index):
def
InceptionB
(
in_blob
,
index
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch3x3"
):
branch3x3
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
384
,
kernel_size
=
3
,
strides
=
2
,
padding
=
"VALID"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3dbl"
):
with
flow
.
scope
.
namespac
e
(
"branch3x3dbl"
):
branch3x3dbl_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
64
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -146,7 +146,7 @@ def InceptionB(in_blob, index):
strides
=
2
,
padding
=
"VALID"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool
=
flow
.
nn
.
max_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -166,12 +166,12 @@ def InceptionB(in_blob, index):
def
InceptionC
(
in_blob
,
index
,
filters
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch1x1"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch1x1"
):
branch1x1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
192
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch7x7"
):
with
flow
.
scope
.
namespac
e
(
"branch7x7"
):
branch7x7_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
...
...
@@ -196,7 +196,7 @@ def InceptionC(in_blob, index, filters):
strides
=
[
1
,
1
],
padding
=
"SAME"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch7x7dbl"
):
with
flow
.
scope
.
namespac
e
(
"branch7x7dbl"
):
branch7x7dbl_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
...
...
@@ -237,7 +237,7 @@ def InceptionC(in_blob, index, filters):
strides
=
1
,
padding
=
"SAME"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool_1
=
flow
.
nn
.
avg_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -266,8 +266,8 @@ def InceptionC(in_blob, index, filters):
def
InceptionD
(
in_blob
,
index
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch3x3"
):
branch3x3_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
192
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -279,7 +279,7 @@ def InceptionD(in_blob, index):
strides
=
2
,
padding
=
"VALID"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch7x7x3"
):
with
flow
.
scope
.
namespac
e
(
"branch7x7x3"
):
branch7x7x3_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
192
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -307,7 +307,7 @@ def InceptionD(in_blob, index):
strides
=
2
,
padding
=
"VALID"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool
=
flow
.
nn
.
max_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -328,12 +328,12 @@ def InceptionD(in_blob, index):
def
InceptionE
(
in_blob
,
index
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch1x1"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch1x1"
):
branch1x1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
320
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3"
):
with
flow
.
scope
.
namespac
e
(
"branch3x3"
):
branch3x3_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
384
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -359,7 +359,7 @@ def InceptionE(in_blob, index):
concat_branch3x3
=
flow
.
concat
(
values
=
inceptionE_1_bn
,
axis
=
1
,
name
=
"concat"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3dbl"
):
with
flow
.
scope
.
namespac
e
(
"branch3x3dbl"
):
branch3x3dbl_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
448
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -393,7 +393,7 @@ def InceptionE(in_blob, index):
concat_branch3x3dbl
=
flow
.
concat
(
values
=
inceptionE_2_bn
,
axis
=
1
,
name
=
"concat"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool_1
=
flow
.
nn
.
avg_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -473,7 +473,7 @@ def inceptionv3(images, labels, trainable=True):
mixed_10
,
ksize
=
8
,
strides
=
1
,
padding
=
"VALID"
,
data_format
=
"NCHW"
,
name
=
"pool3"
)
with
flow
.
deprecated
.
variable_scop
e
(
"logits"
):
with
flow
.
scope
.
namespac
e
(
"logits"
):
pool3
=
flow
.
reshape
(
pool3
,
[
pool3
.
shape
[
0
],
-
1
])
# TODO: Need to transpose weight when converting model from TF to OF if
# you want to use layers.dense interface.
...
...
oneflow/python/benchmarks/cnn_benchmark/resnet_model.py
浏览文件 @
993b6d37
...
...
@@ -122,7 +122,7 @@ def resnet50(images, trainable=True):
images
=
flow
.
transpose
(
images
,
name
=
"transpose"
,
perm
=
[
0
,
3
,
1
,
2
])
with
flow
.
deprecated
.
variable_scop
e
(
"Resnet"
):
with
flow
.
scope
.
namespac
e
(
"Resnet"
):
stem
=
resnet_stem
(
images
)
body
=
resnet_conv_x_body
(
stem
,
lambda
x
:
x
)
pool5
=
flow
.
nn
.
avg_pool2d
(
...
...
oneflow/python/test/deprecated/variable_scope.py
浏览文件 @
993b6d37
...
...
@@ -4,7 +4,7 @@ import oneflow as of
@
flow
.
global_function
def
variable_scope_test_job_1
(
a
=
of
.
FixedTensorDef
((
1
,
3
,
6
,
6
))):
with
of
.
deprecated
.
variable_scop
e
(
"job1_scope1"
):
with
of
.
scope
.
namespac
e
(
"job1_scope1"
):
convw
=
of
.
get_variable
(
"conv_weight"
,
shape
=
(
5
,
3
,
3
,
3
),
...
...
@@ -14,7 +14,7 @@ def variable_scope_test_job_1(a=of.FixedTensorDef((1, 3, 6, 6))):
)
conv
=
of
.
nn
.
conv2d
(
a
,
convw
,
1
,
"SAME"
,
"NCHW"
,
name
=
"conv"
)
with
of
.
deprecated
.
variable_scop
e
(
"job1_scope2"
):
with
of
.
scope
.
namespac
e
(
"job1_scope2"
):
fcw
=
of
.
get_variable
(
"fc_weight"
,
shape
=
(
180
,
10
),
...
...
@@ -54,7 +54,7 @@ def variable_scope_test_job_1(a=of.FixedTensorDef((1, 3, 6, 6))):
@
flow
.
global_function
def
variable_scope_test_job_2
(
a
=
of
.
FixedTensorDef
((
2
,
5
))):
with
of
.
deprecated
.
variable_scop
e
(
"job2_scope1"
):
with
of
.
scope
.
namespac
e
(
"job2_scope1"
):
indices
=
of
.
get_variable
(
"gather_inds"
,
shape
=
(
2
,),
...
...
oneflow/python/test/models/bert.py
浏览文件 @
993b6d37
...
...
@@ -25,8 +25,8 @@ class BertBackbone(object):
initializer_range
=
0.02
,
):
with
flow
.
deprecated
.
variable_scop
e
(
"bert"
):
with
flow
.
deprecated
.
variable_scop
e
(
"embeddings"
):
with
flow
.
scope
.
namespac
e
(
"bert"
):
with
flow
.
scope
.
namespac
e
(
"embeddings"
):
(
self
.
embedding_output_
,
self
.
embedding_table_
)
=
_EmbeddingLookup
(
input_ids_blob
=
input_ids_blob
,
vocab_size
=
vocab_size
,
...
...
@@ -48,7 +48,7 @@ class BertBackbone(object):
max_position_embeddings
=
max_position_embeddings
,
dropout_prob
=
hidden_dropout_prob
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"encoder"
):
with
flow
.
scope
.
namespac
e
(
"encoder"
):
addr_blob
=
_CreateAttentionMaskFromInputMask
(
input_mask_blob
,
from_seq_length
=
seq_length
,
...
...
@@ -112,10 +112,10 @@ def _TransformerModel(
prev_output_blob
=
flow
.
reshape
(
input_blob
,
(
-
1
,
input_width
))
all_layer_output_blobs
=
[]
for
layer_idx
in
range
(
num_hidden_layers
):
with
flow
.
deprecated
.
variable_scop
e
(
"layer_%d"
%
layer_idx
):
with
flow
.
scope
.
namespac
e
(
"layer_%d"
%
layer_idx
):
layer_input_blob
=
prev_output_blob
with
flow
.
deprecated
.
variable_scop
e
(
"attention"
):
with
flow
.
deprecated
.
variable_scop
e
(
"self"
):
with
flow
.
scope
.
namespac
e
(
"attention"
):
with
flow
.
scope
.
namespac
e
(
"self"
):
attention_output_blob
=
_AttentionLayer
(
from_blob
=
layer_input_blob
,
to_blob
=
layer_input_blob
,
...
...
@@ -128,7 +128,7 @@ def _TransformerModel(
from_seq_length
=
seq_length
,
to_seq_length
=
seq_length
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"output"
):
with
flow
.
scope
.
namespac
e
(
"output"
):
attention_output_blob
=
_FullyConnected
(
attention_output_blob
,
input_size
=
num_attention_heads
*
attention_head_size
,
...
...
@@ -143,7 +143,7 @@ def _TransformerModel(
attention_output_blob
=
_LayerNorm
(
attention_output_blob
,
hidden_size
)
with
flow
.
deprecated
.
variable_scop
e
(
"intermediate"
):
with
flow
.
scope
.
namespac
e
(
"intermediate"
):
if
callable
(
intermediate_act_fn
):
act_fn
=
op_conf_util
.
kNone
else
:
...
...
@@ -160,7 +160,7 @@ def _TransformerModel(
intermediate_output_blob
=
intermediate_act_fn
(
intermediate_output_blob
)
with
flow
.
deprecated
.
variable_scop
e
(
"output"
):
with
flow
.
scope
.
namespac
e
(
"output"
):
layer_output_blob
=
_FullyConnected
(
intermediate_output_blob
,
input_size
=
intermediate_size
,
...
...
oneflow/python/test/models/inceptionv3.py
浏览文件 @
993b6d37
...
...
@@ -133,12 +133,12 @@ def _data_load_layer(args, data_dir):
def
InceptionA
(
in_blob
,
index
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch1x1"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch1x1"
):
branch1x1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
64
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch5x5"
):
with
flow
.
scope
.
namespac
e
(
"branch5x5"
):
branch5x5_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
48
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -150,7 +150,7 @@ def InceptionA(in_blob, index):
strides
=
1
,
padding
=
"SAME"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3dbl"
):
with
flow
.
scope
.
namespac
e
(
"branch3x3dbl"
):
branch3x3dbl_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
64
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -170,7 +170,7 @@ def InceptionA(in_blob, index):
strides
=
1
,
padding
=
"SAME"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool_1
=
flow
.
nn
.
avg_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -200,12 +200,12 @@ def InceptionA(in_blob, index):
def
InceptionB
(
in_blob
,
index
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch3x3"
):
branch3x3
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
384
,
kernel_size
=
3
,
strides
=
2
,
padding
=
"VALID"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3dbl"
):
with
flow
.
scope
.
namespac
e
(
"branch3x3dbl"
):
branch3x3dbl_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
64
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -225,7 +225,7 @@ def InceptionB(in_blob, index):
strides
=
2
,
padding
=
"VALID"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool
=
flow
.
nn
.
max_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -245,12 +245,12 @@ def InceptionB(in_blob, index):
def
InceptionC
(
in_blob
,
index
,
filters
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch1x1"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch1x1"
):
branch1x1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
192
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch7x7"
):
with
flow
.
scope
.
namespac
e
(
"branch7x7"
):
branch7x7_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
...
...
@@ -275,7 +275,7 @@ def InceptionC(in_blob, index, filters):
strides
=
[
1
,
1
],
padding
=
"SAME"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch7x7dbl"
):
with
flow
.
scope
.
namespac
e
(
"branch7x7dbl"
):
branch7x7dbl_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
...
...
@@ -316,7 +316,7 @@ def InceptionC(in_blob, index, filters):
strides
=
1
,
padding
=
"SAME"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool_1
=
flow
.
nn
.
avg_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -345,8 +345,8 @@ def InceptionC(in_blob, index, filters):
def
InceptionD
(
in_blob
,
index
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch3x3"
):
branch3x3_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
192
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -358,7 +358,7 @@ def InceptionD(in_blob, index):
strides
=
2
,
padding
=
"VALID"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch7x7x3"
):
with
flow
.
scope
.
namespac
e
(
"branch7x7x3"
):
branch7x7x3_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
192
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -386,7 +386,7 @@ def InceptionD(in_blob, index):
strides
=
2
,
padding
=
"VALID"
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool
=
flow
.
nn
.
max_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -407,12 +407,12 @@ def InceptionD(in_blob, index):
def
InceptionE
(
in_blob
,
index
):
with
flow
.
deprecated
.
variable_scop
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
deprecated
.
variable_scop
e
(
"branch1x1"
):
with
flow
.
scope
.
namespac
e
(
"mixed_{}"
.
format
(
index
)):
with
flow
.
scope
.
namespac
e
(
"branch1x1"
):
branch1x1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
320
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3"
):
with
flow
.
scope
.
namespac
e
(
"branch3x3"
):
branch3x3_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
384
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -438,7 +438,7 @@ def InceptionE(in_blob, index):
concat_branch3x3
=
flow
.
concat
(
values
=
inceptionE_1_bn
,
axis
=
1
,
name
=
"concat"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch3x3dbl"
):
with
flow
.
scope
.
namespac
e
(
"branch3x3dbl"
):
branch3x3dbl_1
=
_conv2d_layer
(
"conv0"
,
in_blob
,
filters
=
448
,
kernel_size
=
1
,
strides
=
1
,
padding
=
"SAME"
)
...
...
@@ -472,7 +472,7 @@ def InceptionE(in_blob, index):
concat_branch3x3dbl
=
flow
.
concat
(
values
=
inceptionE_2_bn
,
axis
=
1
,
name
=
"concat"
)
with
flow
.
deprecated
.
variable_scop
e
(
"branch_pool"
):
with
flow
.
scope
.
namespac
e
(
"branch_pool"
):
branch_pool_1
=
flow
.
nn
.
avg_pool2d
(
in_blob
,
ksize
=
3
,
...
...
@@ -552,7 +552,7 @@ def InceptionV3(images, labels, trainable=True):
mixed_10
,
ksize
=
8
,
strides
=
1
,
padding
=
"VALID"
,
data_format
=
"NCHW"
,
name
=
"pool3"
)
with
flow
.
deprecated
.
variable_scop
e
(
"logits"
):
with
flow
.
scope
.
namespac
e
(
"logits"
):
pool3
=
flow
.
reshape
(
pool3
,
[
pool3
.
shape
[
0
],
-
1
])
# TODO: Need to transpose weight when converting model from TF to OF if
# you want to use layers.dense interface.
...
...
oneflow/python/test/models/pretrain.py
浏览文件 @
993b6d37
...
...
@@ -65,13 +65,13 @@ def PreTrain(
hidden_size
=
hidden_size
,
initializer_range
=
initializer_range
,
)
with
flow
.
deprecated
.
variable_scop
e
(
"cls-loss"
):
with
flow
.
scope
.
namespac
e
(
"cls-loss"
):
total_loss
=
lm_loss
+
ns_loss
return
total_loss
def
PooledOutput
(
sequence_output
,
hidden_size
,
initializer_range
):
with
flow
.
deprecated
.
variable_scop
e
(
"bert-pooler"
):
with
flow
.
scope
.
namespac
e
(
"bert-pooler"
):
first_token_tensor
=
flow
.
slice
(
sequence_output
,
[
None
,
0
,
0
],
[
None
,
1
,
-
1
])
first_token_tensor
=
flow
.
reshape
(
first_token_tensor
,
[
-
1
,
hidden_size
])
pooled_output
=
bert_util
.
_FullyConnected
(
...
...
@@ -99,15 +99,15 @@ def _AddMaskedLanguageModelLoss(
initializer_range
,
):
with
flow
.
deprecated
.
variable_scop
e
(
"other"
):
with
flow
.
scope
.
namespac
e
(
"other"
):
sum_label_weight_blob
=
flow
.
math
.
reduce_sum
(
label_weight_blob
,
axis
=
[
-
1
])
ones
=
sum_label_weight_blob
*
0.0
+
1.0
sum_label_weight_blob
=
flow
.
math
.
reduce_sum
(
sum_label_weight_blob
)
batch_size
=
flow
.
math
.
reduce_sum
(
ones
)
sum_label_weight_blob
=
sum_label_weight_blob
/
batch_size
with
flow
.
deprecated
.
variable_scop
e
(
"cls-predictions"
):
with
flow
.
scope
.
namespac
e
(
"cls-predictions"
):
input_blob
=
_GatherIndexes
(
input_blob
,
positions_blob
,
seq_length
,
hidden_size
)
with
flow
.
deprecated
.
variable_scop
e
(
"transform"
):
with
flow
.
scope
.
namespac
e
(
"transform"
):
if
callable
(
hidden_act
):
act_fn
=
op_conf_util
.
kNone
else
:
...
...
@@ -137,7 +137,7 @@ def _AddMaskedLanguageModelLoss(
)
pre_example_loss
=
flow
.
reshape
(
pre_example_loss
,
[
-
1
,
max_predictions_per_seq
])
numerator
=
pre_example_loss
*
label_weight_blob
with
flow
.
deprecated
.
variable_scop
e
(
"loss"
):
with
flow
.
scope
.
namespac
e
(
"loss"
):
numerator
=
flow
.
math
.
reduce_sum
(
numerator
,
axis
=
[
-
1
])
denominator
=
sum_label_weight_blob
+
1e-5
loss
=
numerator
/
denominator
...
...
@@ -153,7 +153,7 @@ def _GatherIndexes(sequence_blob, positions_blob, seq_length, hidden_size):
def
_AddNextSentenceOutput
(
input_blob
,
label_blob
,
hidden_size
,
initializer_range
):
with
flow
.
deprecated
.
variable_scop
e
(
"cls-seq_relationship"
):
with
flow
.
scope
.
namespac
e
(
"cls-seq_relationship"
):
output_weight_blob
=
flow
.
get_variable
(
name
=
"output_weights"
,
shape
=
[
2
,
hidden_size
],
...
...
oneflow/python/test/models/resnet50.py
浏览文件 @
993b6d37
...
...
@@ -231,7 +231,7 @@ def resnet50(args, data_dir):
g_output_key
.
append
(
"input_img"
)
g_output
.
append
(
images
)
with
flow
.
deprecated
.
variable_scop
e
(
"Resnet"
):
with
flow
.
scope
.
namespac
e
(
"Resnet"
):
stem
=
resnet_stem
(
images
)
body
=
resnet_conv_x_body
(
stem
,
lambda
x
:
x
)
pool5
=
flow
.
nn
.
avg_pool2d
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录