-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_to_saved_model.py
59 lines (44 loc) · 1.42 KB
/
convert_to_saved_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import tensorflow as tf
from models.model import create_model_fn
from utils.train_utils import create_estimator_fn
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string(
name='model_dir',
default='./ckpts',
help='Directory to save checkpoints.')
tf.app.flags.DEFINE_string(
name='saved_model_dir',
default='./saved_model',
help='Directory to save checkpoints.')
tf.app.flags.DEFINE_integer(
name='image_size',
default=128,
help='Input image size.')
tf.app.flags.DEFINE_string(
name='backbone',
default='xception',
help='Input image size.')
def main(_):
image_size = (FLAGS.image_size, FLAGS.image_size)
model_fn = create_model_fn(
backbone=FLAGS.backbone,
output_stride=16,
img_size=image_size)
estimator_fn = create_estimator_fn(
model_fn=model_fn,
loss_fn=None,
metrics_fn=None)
estimator = tf.estimator.Estimator(
model_fn=estimator_fn,
model_dir=FLAGS.model_dir,
params={})
def serving_input_fn():
images = tf.placeholder(
shape=[None, None, None, 3],
dtype=tf.float32,
name="images")
images = tf.image.resize_bilinear(images, size=image_size)
return tf.estimator.export.TensorServingInputReceiver(images, images)
estimator.export_savedmodel(FLAGS.saved_model_dir, serving_input_fn)
if __name__ == "__main__":
tf.app.run(main=main)