Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Pokedex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
michael.divia
Pokedex
Commits
9e0298bc
Commit
9e0298bc
authored
2 months ago
by
michael.divia
Browse files
Options
Downloads
Patches
Plain Diff
Dynamic ONNX converter
parent
cd94e0ed
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Python/convert_onnx.py
+26
-7
26 additions, 7 deletions
Python/convert_onnx.py
with
26 additions
and
7 deletions
Python/convert_onnx.py
+
26
−
7
View file @
9e0298bc
import
tensorflow
as
tf
import
tensorflow
as
tf
import
tf2onnx
import
tf2onnx
import
argparse
# WHAT ?
parser
=
argparse
.
ArgumentParser
(
description
=
"
WHAT ?!
"
)
parser
.
add_argument
(
"
--model
"
,
choices
=
[
"
1
"
,
"
2
"
],
default
=
"
1
"
,
help
=
"
1 = ResNet50, 2 = Xception
"
)
args
=
parser
.
parse_args
()
# Load Sequential model
# Load Sequential model
seq_model
=
tf
.
keras
.
models
.
load_model
(
"
../models/resnet50.h5
"
,
compile
=
False
)
if
args
.
model
==
"
1
"
:
seq_model
=
tf
.
keras
.
models
.
load_model
(
"
../models/ResNet50/pokemon_resnet50.h5
"
,
compile
=
False
)
elif
args
.
model
==
"
2
"
:
seq_model
=
tf
.
keras
.
models
.
load_model
(
"
../models/ResNet50/pokemon_xception.h5
"
,
compile
=
False
)
# Create input layer with same shape
# Create input layer with same shape
inputs
=
tf
.
keras
.
Input
(
shape
=
(
224
,
224
,
3
),
name
=
"
input
"
)
inputs
=
tf
.
keras
.
Input
(
shape
=
(
224
,
224
,
3
),
name
=
"
input
"
)
...
@@ -15,9 +25,18 @@ model = tf.keras.Model(inputs=inputs, outputs=outputs)
...
@@ -15,9 +25,18 @@ model = tf.keras.Model(inputs=inputs, outputs=outputs)
# Convert to ONNX
# Convert to ONNX
spec
=
(
tf
.
TensorSpec
((
1
,
224
,
224
,
3
),
tf
.
float32
,
name
=
"
input
"
),)
spec
=
(
tf
.
TensorSpec
((
1
,
224
,
224
,
3
),
tf
.
float32
,
name
=
"
input
"
),)
onnx_model
,
_
=
tf2onnx
.
convert
.
from_keras
(
model
,
if
args
.
model
==
"
1
"
:
input_signature
=
spec
,
onnx_model
,
_
=
tf2onnx
.
convert
.
from_keras
(
opset
=
13
,
model
,
output_path
=
"
../models/resnet50.onnx
"
input_signature
=
spec
,
)
opset
=
13
,
\ No newline at end of file
output_path
=
"
../models/ResNet50/pokemon_resnet50.onnx
"
)
elif
args
.
model
==
"
2
"
:
onnx_model
,
_
=
tf2onnx
.
convert
.
from_keras
(
model
,
input_signature
=
spec
,
opset
=
13
,
output_path
=
"
../models/ResNet50/pokemon_xception.onnx
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment