Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
e014950e
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e014950e
编写于
3月 29, 2019
作者:
W
wopeizl
提交者:
GitHub
3月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add slice support for dim < 0 (#16494)
* add slice support for dim < 0 test=develop
上级
8f7b5883
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
38 deletion
+39
-38
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+17
-6
python/paddle/fluid/tests/unittests/test_variable.py
python/paddle/fluid/tests/unittests/test_variable.py
+22
-32
未找到文件。
python/paddle/fluid/framework.py
浏览文件 @
e014950e
...
...
@@ -789,13 +789,24 @@ class Variable(object):
if
isinstance
(
item
,
tuple
):
if
len
(
item
)
>
len
(
self
.
shape
):
raise
IndexError
(
"Too many indexes"
)
fixedSize
=
True
for
i
in
range
(
len
(
self
.
shape
)):
if
self
.
shape
[
i
]
==
-
1
:
fixedSize
=
False
break
newitem
=
self
.
_reconstructSliceinfo
(
item
)
or
item
check
,
info
=
self
.
_detectContinuesSlice
(
newitem
)
if
check
:
starts
=
info
[
0
]
ends
=
info
[
1
]
axes
=
[
i
for
i
in
range
(
len
(
starts
))]
return
self
.
_sliceVar
(
axes
,
starts
,
ends
)
if
fixedSize
:
check
,
info
=
self
.
_detectContinuesSlice
(
newitem
)
if
check
and
fixedSize
:
starts
=
info
[
0
]
ends
=
info
[
1
]
axes
=
[
i
for
i
in
range
(
len
(
starts
))]
return
self
.
_sliceVar
(
axes
,
starts
,
ends
)
else
:
new_var
=
self
for
index
,
o
in
enumerate
(
newitem
):
new_var
=
new_var
.
_sliceAndConcatVar
(
o
,
index
)
else
:
new_var
=
self
for
index
,
o
in
enumerate
(
newitem
):
...
...
python/paddle/fluid/tests/unittests/test_variable.py
浏览文件 @
e014950e
...
...
@@ -61,7 +61,7 @@ class TestVariable(unittest.TestCase):
name
=
'step_scopes'
,
type
=
core
.
VarDesc
.
VarType
.
STEP_SCOPES
)
self
.
assertEqual
(
core
.
VarDesc
.
VarType
.
STEP_SCOPES
,
var
.
type
)
def
_test_slice
(
self
):
def
_test_slice
(
self
,
place
):
b
=
default_main_program
().
current_block
()
w
=
b
.
create_var
(
dtype
=
"float64"
,
shape
=
[
784
,
100
,
100
],
lod_level
=
0
)
...
...
@@ -83,7 +83,6 @@ class TestVariable(unittest.TestCase):
self
.
assertEqual
(
0
,
nw
.
lod_level
)
place
=
fluid
.
CPUPlace
()
main
=
fluid
.
Program
()
with
fluid
.
program_guard
(
main
):
exe
=
fluid
.
Executor
(
place
)
...
...
@@ -100,10 +99,23 @@ class TestVariable(unittest.TestCase):
var6
=
var
[
1
,
1
:,
1
:]
var7
=
var
[
1
,
...,
1
:]
var8
=
var
[
1
,
...]
var_reshape
=
fluid
.
layers
.
reshape
(
var
,
[
3
,
-
1
,
3
])
var9
=
var_reshape
[
1
,
...,
2
]
var10
=
var_reshape
[:,
:,
-
1
]
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
13
],
dtype
=
'float32'
)
y
=
fluid
.
layers
.
fc
(
input
=
x
,
size
=
1
,
act
=
None
)
var11
=
y
[:,
0
]
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
[
x
])
data
=
[]
data
.
append
((
np
.
random
.
randint
(
10
,
size
=
[
13
]).
astype
(
'float32'
)))
exe
.
run
(
fluid
.
default_startup_program
())
local_out
=
exe
.
run
(
main
,
feed
=
feeder
.
feed
([
data
]),
fetch_list
=
[
var
,
var1
,
var2
,
var3
,
var4
,
var5
,
var6
,
var7
,
var8
var7
,
var8
,
var9
,
var10
,
var11
])
self
.
assertTrue
((
np
.
array
(
local_out
[
1
])
==
np
.
array
(
tensor_array
[
...
...
@@ -122,38 +134,16 @@ class TestVariable(unittest.TestCase):
1
,
...,
1
:])).
all
())
self
.
assertTrue
((
np
.
array
(
local_out
[
8
])
==
np
.
array
(
tensor_array
[
1
,
...])).
all
())
self
.
assertEqual
(
local_out
[
9
].
shape
,
(
1
,
3
,
1
))
self
.
assertEqual
(
local_out
[
10
].
shape
,
(
3
,
3
,
1
))
self
.
assertEqual
(
local_out
[
11
].
shape
,
(
1
,
1
))
def
test_slice
(
self
):
self
.
_test_slice
()
class
TestVariableImperative
(
unittest
.
TestCase
):
def
_test_slice
(
self
):
b
=
default_main_program
().
current_block
()
w
=
b
.
create_var
(
dtype
=
"float64"
,
shape
=
[
784
,
100
,
100
],
lod_level
=
0
)
for
i
in
range
(
3
):
nw
=
w
[
i
]
self
.
assertEqual
([
1
,
100
,
100
],
nw
.
shape
)
nw
=
w
[:]
self
.
assertEqual
([
784
,
100
,
100
],
nw
.
shape
)
nw
=
w
[:,
:,
:]
self
.
assertEqual
([
784
,
100
,
100
],
nw
.
shape
)
nw
=
w
[::
2
,
::
2
,
:]
self
.
assertEqual
([
392
,
50
,
100
],
nw
.
shape
)
nw
=
w
[::
-
2
,
::
-
2
,
:]
self
.
assertEqual
([
392
,
50
,
100
],
nw
.
shape
)
nw
=
w
[
0
::
-
2
,
0
::
-
2
,
:]
self
.
assertEqual
([
1
,
1
,
100
],
nw
.
shape
)
place
=
fluid
.
CPUPlace
()
self
.
_test_slice
(
place
)
def
test_slice
(
self
):
with
fluid
.
dygraph
.
guard
():
self
.
_test_slice
()
if
core
.
is_compiled_with_cuda
():
self
.
_test_slice
(
core
.
CUDAPlace
(
0
))
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录