Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
b255b211
Commit
b255b211
authored
Jul 30, 2019
by
Ewa21
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Py] Added depth_to_space operator to Python API.
parent
5ece6de2
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
113 additions
and
5 deletions
+113
-5
ngraph.ops.rst
doc/sphinx/source/python_api/_autosummary/ngraph.ops.rst
+1
-0
__init__.py
python/ngraph/__init__.py
+1
-0
__init__.py
python/ngraph/impl/op/__init__.py
+1
-0
ops.py
python/ngraph/ops.py
+26
-5
depth_to_space.cpp
python/pyngraph/ops/fused/depth_to_space.cpp
+31
-0
depth_to_space.hpp
python/pyngraph/ops/fused/depth_to_space.hpp
+23
-0
regmodule_pyngraph_op.cpp
python/pyngraph/ops/regmodule_pyngraph_op.cpp
+1
-0
regmodule_pyngraph_op.hpp
python/pyngraph/ops/regmodule_pyngraph_op.hpp
+1
-0
setup.py
python/setup.py
+1
-0
test_ops_fused.py
python/test/ngraph/test_ops_fused.py
+27
-0
No files found.
doc/sphinx/source/python_api/_autosummary/ngraph.ops.rst
View file @
b255b211
...
...
@@ -30,6 +30,7 @@ ngraph.ops
convolution_backprop_data
cos
cosh
depth_to_space
divide
dot
elu
...
...
python/ngraph/__init__.py
View file @
b255b211
...
...
@@ -43,6 +43,7 @@ from ngraph.ops import convolution
from
ngraph.ops
import
convolution_backprop_data
from
ngraph.ops
import
cos
from
ngraph.ops
import
cosh
from
ngraph.ops
import
depth_to_space
from
ngraph.ops
import
divide
from
ngraph.ops
import
dot
from
ngraph.ops
import
elu
...
...
python/ngraph/impl/op/__init__.py
View file @
b255b211
...
...
@@ -67,6 +67,7 @@ from _pyngraph.op import ConvolutionBackpropData
from
_pyngraph.op
import
ConvolutionBackpropFilters
from
_pyngraph.op
import
Cos
from
_pyngraph.op
import
Cosh
from
_pyngraph.op
import
DepthToSpace
from
_pyngraph.op
import
Divide
from
_pyngraph.op
import
Dot
from
_pyngraph.op
import
Elu
...
...
python/ngraph/ops.py
View file @
b255b211
...
...
@@ -22,11 +22,11 @@ from ngraph.impl import AxisSet, AxisVector, Coordinate, CoordinateDiff, Functio
from
ngraph.impl.op
import
Abs
,
Acos
,
Add
,
And
,
Asin
,
ArgMax
,
ArgMin
,
Atan
,
AvgPool
,
\
BatchNormTraining
,
BatchNormInference
,
Broadcast
,
Ceiling
,
Concat
,
Constant
,
Convert
,
\
Convolution
,
ConvolutionBackpropData
,
Cos
,
Cosh
,
D
ivide
,
Dot
,
Elu
,
Equal
,
Exp
,
Floor
,
\
GetOutputElement
,
Greater
,
GreaterEq
,
Less
,
LessEq
,
Log
,
LRN
,
Max
,
Maximum
,
MaxPool
,
\
M
in
,
Minimum
,
Multiply
,
Negative
,
Not
,
NotEqual
,
OneHot
,
Or
,
Pad
,
Parameter
,
Product
,
\
P
ower
,
Relu
,
ReplaceSlice
,
Reshape
,
Reverse
,
Select
,
Sign
,
Sin
,
Sinh
,
Slice
,
Softmax
,
\
Sqrt
,
Subtract
,
Sum
,
Tan
,
Tanh
,
TopK
Convolution
,
ConvolutionBackpropData
,
Cos
,
Cosh
,
D
epthToSpace
,
Divide
,
Dot
,
Elu
,
Equal
,
\
Exp
,
Floor
,
GetOutputElement
,
Greater
,
GreaterEq
,
Less
,
LessEq
,
Log
,
LRN
,
Max
,
Maximum
,
\
M
axPool
,
Min
,
Minimum
,
Multiply
,
Negative
,
Not
,
NotEqual
,
OneHot
,
Or
,
Pad
,
Parameter
,
\
P
roduct
,
Power
,
Relu
,
ReplaceSlice
,
Reshape
,
Reverse
,
Select
,
Sign
,
Sin
,
Sinh
,
Slice
,
\
S
oftmax
,
S
qrt
,
Subtract
,
Sum
,
Tan
,
Tanh
,
TopK
from
typing
import
Callable
,
Iterable
,
List
,
Union
...
...
@@ -527,6 +527,27 @@ def convert(node, new_type, name=None): # type: (Node, NumericType, str) -> Nod
return
Convert
(
node
,
new_element_type
)
@nameable_op
def
depth_to_space
(
node
,
block_size
,
name
=
None
):
# type: (Node, int, str) -> Node
"""Rearranges input tensor from depth into blocks of spatial data.
Values from the height and width dimensions are moved to the depth dimension.
Input tensor has shape [N,C,H,W], where N is the batch axis, C is the channel or depth,
H is the height and W is the width.
Output node produces a tensor with shape:
[N, C * :code:`block_size` * :code:`block_size`, H / :code:`block_size`, W / :code:`block_size`]
:param node: The node with input tensor data.
:param block_size: The size of the block of value to be moved.
:param name: Optional output node name.
:return: The new node performing an DepthToSpace operation on its input tensor.
"""
return
DepthToSpace
(
node
,
block_size
)
@nameable_op
def
select
(
selection_node
,
input_node1
,
input_node2
,
name
=
None
):
# type: (Node, Node, Node, str) -> Node
...
...
python/pyngraph/ops/fused/depth_to_space.cpp
0 → 100644
View file @
b255b211
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "ngraph/op/fused/depth_to_space.hpp"
#include "pyngraph/ops/fused/depth_to_space.hpp"
namespace
py
=
pybind11
;
void
regclass_pyngraph_op_DepthToSpace
(
py
::
module
m
)
{
py
::
class_
<
ngraph
::
op
::
DepthToSpace
,
std
::
shared_ptr
<
ngraph
::
op
::
DepthToSpace
>
,
ngraph
::
op
::
Op
>
depthtospace
(
m
,
"DepthToSpace"
);
depthtospace
.
doc
()
=
"ngraph.impl.op.DepthToSpace wraps ngraph::op::DepthToSpace"
;
depthtospace
.
def
(
py
::
init
<
const
std
::
shared_ptr
<
ngraph
::
Node
>&
,
std
::
size_t
&>
());
}
python/pyngraph/ops/fused/depth_to_space.hpp
0 → 100644
View file @
b255b211
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#pragma once
#include <pybind11/pybind11.h>
namespace
py
=
pybind11
;
void
regclass_pyngraph_op_DepthToSpace
(
py
::
module
m
);
python/pyngraph/ops/regmodule_pyngraph_op.cpp
View file @
b255b211
...
...
@@ -47,6 +47,7 @@ void regmodule_pyngraph_op(py::module m_op)
regclass_pyngraph_op_ConvolutionBackpropFilters
(
m_op
);
regclass_pyngraph_op_Cos
(
m_op
);
regclass_pyngraph_op_Cosh
(
m_op
);
regclass_pyngraph_op_DepthToSpace
(
m_op
);
regclass_pyngraph_op_Divide
(
m_op
);
regclass_pyngraph_op_Dot
(
m_op
);
regclass_pyngraph_op_Elu
(
m_op
);
...
...
python/pyngraph/ops/regmodule_pyngraph_op.hpp
View file @
b255b211
...
...
@@ -43,6 +43,7 @@
#include "pyngraph/ops/equal.hpp"
#include "pyngraph/ops/exp.hpp"
#include "pyngraph/ops/floor.hpp"
#include "pyngraph/ops/fused/depth_to_space.hpp"
#include "pyngraph/ops/get_output_element.hpp"
#include "pyngraph/ops/greater.hpp"
#include "pyngraph/ops/greater_eq.hpp"
...
...
python/setup.py
View file @
b255b211
...
...
@@ -177,6 +177,7 @@ sources = [
'pyngraph/ops/cos.cpp'
,
'pyngraph/ops/cosh.cpp'
,
'pyngraph/ops/ceiling.cpp'
,
'pyngraph/ops/fused/depth_to_space.cpp'
,
'pyngraph/ops/divide.cpp'
,
'pyngraph/ops/dot.cpp'
,
'pyngraph/ops/elu.cpp'
,
...
...
python/test/ngraph/test_ops_fused.py
View file @
b255b211
...
...
@@ -67,3 +67,30 @@ def test_elu_operator_with_scalar():
result
=
computation
(
data_value
)
expected
=
np
.
array
([[
-
2.9797862
,
1.
],
[
-
2.5939941
,
3.
]],
dtype
=
np
.
float32
)
assert
np
.
allclose
(
result
,
expected
)
def
test_depth_to_space
():
runtime
=
get_runtime
()
data_value
=
np
.
array
([[[[
0
,
1
,
2
],
[
3
,
4
,
5
]],
[[
6
,
7
,
8
],
[
9
,
10
,
11
]],
[[
12
,
13
,
14
],
[
15
,
16
,
17
]],
[[
18
,
19
,
20
],
[
21
,
22
,
23
]]]],
dtype
=
np
.
float32
)
block_size
=
np
.
float32
(
2
)
data_shape
=
[
1
,
4
,
2
,
3
]
parameter_data
=
ng
.
parameter
(
data_shape
,
name
=
'Data'
,
dtype
=
np
.
float32
)
model
=
ng
.
depth_to_space
(
parameter_data
,
block_size
)
computation
=
runtime
.
computation
(
model
,
parameter_data
)
result
=
computation
(
data_value
)
expected
=
np
.
array
([[[[
0
,
6
,
1
,
7
,
2
,
8
],
[
12
,
18
,
13
,
19
,
14
,
20
],
[
3
,
9
,
4
,
10
,
5
,
11
],
[
15
,
21
,
16
,
22
,
17
,
23
]]]],
dtype
=
np
.
float32
)
assert
np
.
allclose
(
result
,
expected
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment