Skip to content

Commit 4d42404

Browse files
authored
cnn2deepstream
1 parent c91e931 commit 4d42404

10 files changed

+15921
-0
lines changed

CNN-to-DeepStream/UTKFace_test.zip

14.6 MB
Binary file not shown.

CNN-to-DeepStream/convert_2_onnx.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## pip install -U tensorflow tf2onnx
2+
3+
import numpy as np
4+
import tensorflow as tf
5+
from tensorflow import keras
6+
import tf2onnx
7+
8+
# It can be used to reconstruct the model identically.
9+
model = keras.models.load_model('gender/content/gender_model.h5')
10+
11+
# model.add(keras.layers.Reshape((1, 224, 224,3)))
12+
13+
print(model.input_shape)
14+
print(model.output_shape)
15+
print(model.summary())
16+
17+
18+
# arr = [1,3,224,224]
19+
arr = [1,224,224,3]
20+
21+
model_proto, external_tensor_storage = tf2onnx.convert.from_keras(model,
22+
input_signature=None, opset=None, custom_ops=None,
23+
custom_op_handlers=None, custom_rewriter=None,
24+
inputs_as_nchw=arr, outputs_as_nchw=None, extra_opset=None,
25+
shape_override=None, target=None, large_model=False, output_path=None)
26+
27+
28+
with open("./gender.onnx", "wb") as f:
29+
f.write(model_proto.SerializeToString())
30+
31+
print('\n\n[INFO] model to onnx was successful..')
32+
33+
#python3 -m tf2onnx.convert --saved-model tmp_model --output "model.onnx"

0 commit comments

Comments
 (0)