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
57fdd798
Commit
57fdd798
authored
Mar 28, 2018
by
tsocha
Committed by
Scott Cyphers
Mar 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Py] Update serialization (#750)
* [Py] Update serialization * Update docstring * Add UT for serialize model
parent
211b70f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
3 deletions
+28
-3
runtime.py
python/ngraph/runtime.py
+8
-3
test_basic.py
python/test/ngraph/test_basic.py
+20
-0
No files found.
python/ngraph/runtime.py
View file @
57fdd798
...
...
@@ -93,9 +93,14 @@ class Computation:
result_arr
=
result_arr
.
reshape
(
result_shape
)
return
result_arr
def
serialize
(
self
):
# type: () -> str
"""Serialize function (compute graph) to a JSON string."""
return
serialize
(
self
.
function
)
def
serialize
(
self
,
indent
=
0
,
bin_const_data
=
False
):
# type: (int, bool) -> str
"""Serialize function (compute graph) to a JSON string.
:param indent: set indent of serialized output
:param bin_const_data: constant data should be binary or not
:return: serialized model
"""
return
serialize
(
self
.
function
,
indent
,
bin_const_data
)
@staticmethod
def
_get_buffer_size
(
element_type
,
element_count
):
# type: (TensorViewType, int) -> int
...
...
python/test/ngraph/test_basic.py
View file @
57fdd798
...
...
@@ -16,6 +16,7 @@
import
numpy
as
np
import
pytest
import
json
import
ngraph
as
ng
...
...
@@ -39,3 +40,21 @@ def test_simple_computation_on_ndarrays(dtype):
value_c
=
np
.
array
([[
9
,
10
],
[
11
,
12
]],
dtype
=
dtype
)
result
=
computation
(
value_a
,
value_b
,
value_c
)
assert
np
.
allclose
(
result
,
np
.
array
([[
54
,
80
],
[
110
,
144
]],
dtype
=
dtype
))
def
test_serialization
():
dtype
=
np
.
float32
manager_name
=
pytest
.
config
.
getoption
(
'backend'
,
default
=
'CPU'
)
shape
=
[
2
,
2
]
parameter_a
=
ng
.
parameter
(
shape
,
dtype
=
dtype
,
name
=
'A'
)
parameter_b
=
ng
.
parameter
(
shape
,
dtype
=
dtype
,
name
=
'B'
)
parameter_c
=
ng
.
parameter
(
shape
,
dtype
=
dtype
,
name
=
'C'
)
model
=
(
parameter_a
+
parameter_b
)
*
parameter_c
runtime
=
ng
.
runtime
(
manager_name
=
manager_name
)
computation
=
runtime
.
computation
(
model
,
parameter_a
,
parameter_b
,
parameter_c
)
serialized
=
computation
.
serialize
(
2
)
serial_json
=
json
.
loads
(
serialized
)
assert
serial_json
[
0
][
"name"
]
!=
''
assert
10
==
len
(
serial_json
[
0
][
"ops"
])
\ No newline at end of file
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