Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
f7572dd5
Commit
f7572dd5
authored
Sep 29, 2017
by
Joshua Z. Zhang
Committed by
Tianqi Chen
May 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TUTORIAL] Onnx tutorial (#60)
* update * back to color
parent
f8db4af6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
+12
-7
nnvm/tutorials/from_onnx.py
+12
-7
No files found.
nnvm/tutorials/from_onnx.py
View file @
f7572dd5
...
...
@@ -45,8 +45,10 @@ from PIL import Image
img_url
=
'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true'
with
open
(
'cat.jpg'
,
'w'
)
as
f
:
f
.
write
(
urllib2
.
urlopen
(
img_url
)
.
read
())
img
=
Image
.
open
(
'cat.jpg'
)
.
convert
(
"L"
)
# convert to greyscale
x
=
np
.
array
(
img
.
resize
((
224
,
224
)))[
np
.
newaxis
,
np
.
newaxis
,
:,
:]
img
=
Image
.
open
(
'cat.jpg'
)
.
resize
((
224
,
224
))
img_ycbcr
=
img
.
convert
(
"YCbCr"
)
# convert to YCbCr
img_y
,
img_cb
,
img_cr
=
img_ycbcr
.
split
()
x
=
np
.
array
(
img_y
)[
np
.
newaxis
,
np
.
newaxis
,
:,
:]
######################################################################
# Compile the model on NNVM
...
...
@@ -73,15 +75,18 @@ m.run()
# get outputs
output_shape
=
(
1
,
1
,
672
,
672
)
tvm_output
=
m
.
get_output
(
0
,
tvm
.
nd
.
empty
(
output_shape
,
dtype
))
.
asnumpy
()
out_img
=
tvm_output
.
reshape
((
672
,
672
))
######################################################################
# Display results
# ---------------------------------------------
# We put input and output image neck to neck
from
matplotlib
import
pyplot
as
plt
canvas
=
np
.
full
((
672
,
672
*
2
),
255
)
canvas
[
0
:
224
,
0
:
224
]
=
x
[
0
,
0
,
:,
:]
canvas
[:,
672
:]
=
out_img
plt
.
imshow
(
canvas
,
cmap
=
'gray'
)
out_y
=
Image
.
fromarray
(
np
.
uint8
((
tvm_output
[
0
,
0
])
.
clip
(
0
,
255
)),
mode
=
'L'
)
out_cb
=
img_cb
.
resize
(
out_y
.
size
,
Image
.
BICUBIC
)
out_cr
=
img_cr
.
resize
(
out_y
.
size
,
Image
.
BICUBIC
)
result
=
Image
.
merge
(
'YCbCr'
,
[
out_y
,
out_cb
,
out_cr
])
.
convert
(
'RGB'
)
canvas
=
np
.
full
((
672
,
672
*
2
,
3
),
255
)
canvas
[
0
:
224
,
0
:
224
,
:]
=
np
.
asarray
(
img
)
canvas
[:,
672
:,
:]
=
np
.
asarray
(
result
)
plt
.
imshow
(
canvas
.
astype
(
np
.
uint8
))
plt
.
show
()
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