Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit f30121b

Browse files
committed
added model conversion script.
1 parent d3fbf20 commit f30121b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
model_js
132+
node_modules

convert_model.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import tensorflow as tf
2+
import model
3+
import tensorflowjs as tfjs
4+
5+
G2 = model.Generator()
6+
G2.trainable = False
7+
G2.load_weights("weights/weights")
8+
9+
# Convert the model
10+
converter = tf.lite.TFLiteConverter.from_keras_model(G2) # path to the SavedModel directory
11+
#converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_LATENCY]
12+
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
13+
tflite_model = converter.convert()
14+
15+
# Save the model.
16+
with open('model.tflite', 'wb') as f:
17+
f.write(tflite_model)
18+
19+
tfjs.converters.save_keras_model(G2, "model_js")

0 commit comments

Comments
 (0)