@@ -156,13 +156,13 @@ def input_fn(is_training, data_dir, batch_size, *args, **kwargs):
156
156
return input_fn
157
157
158
158
159
- def image_bytes_serving_input_fn (image_shape ):
159
+ def image_bytes_serving_input_fn (image_shape , dtype = tf . float32 ):
160
160
"""Serving input fn for raw jpeg images."""
161
161
162
162
def _preprocess_image (image_bytes ):
163
163
"""Preprocess a single raw image."""
164
164
# Bounding box around the whole image.
165
- bbox = tf .constant ([0.0 , 0.0 , 1.0 , 1.0 ], dtype = tf . float32 , shape = [1 , 1 , 4 ])
165
+ bbox = tf .constant ([0.0 , 0.0 , 1.0 , 1.0 ], dtype = dtype , shape = [1 , 1 , 4 ])
166
166
height , width , num_channels = image_shape
167
167
image = imagenet_preprocessing .preprocess_image (
168
168
image_bytes , bbox , height , width , num_channels , is_training = False )
@@ -171,7 +171,7 @@ def _preprocess_image(image_bytes):
171
171
image_bytes_list = tf .placeholder (
172
172
shape = [None ], dtype = tf .string , name = 'input_tensor' )
173
173
images = tf .map_fn (
174
- _preprocess_image , image_bytes_list , back_prop = False , dtype = tf . float32 )
174
+ _preprocess_image , image_bytes_list , back_prop = False , dtype = dtype )
175
175
return tf .estimator .export .TensorServingInputReceiver (
176
176
images , {'image_bytes' : image_bytes_list })
177
177
@@ -530,12 +530,15 @@ def input_fn_eval():
530
530
531
531
if flags_obj .export_dir is not None :
532
532
# Exports a saved model for the given classifier.
533
+ export_dtype = flags_core .get_tf_dtype (flags_obj )
533
534
if flags_obj .image_bytes_as_serving_input :
534
- input_receiver_fn = functools .partial (image_bytes_serving_input_fn , shape )
535
+ input_receiver_fn = functools .partial (
536
+ image_bytes_serving_input_fn , shape , dtype = export_dtype )
535
537
else :
536
538
input_receiver_fn = export .build_tensor_serving_input_receiver_fn (
537
- shape , batch_size = flags_obj .batch_size )
538
- classifier .export_savedmodel (flags_obj .export_dir , input_receiver_fn )
539
+ shape , batch_size = flags_obj .batch_size , dtype = export_dtype )
540
+ classifier .export_savedmodel (flags_obj .export_dir , input_receiver_fn ,
541
+ strip_default_attrs = True )
539
542
540
543
541
544
def define_resnet_flags (resnet_size_choices = None ):
@@ -565,7 +568,7 @@ def define_resnet_flags(resnet_size_choices=None):
565
568
help = flags_core .help_wrap ('Skip training and only perform evaluation on '
566
569
'the latest checkpoint.' ))
567
570
flags .DEFINE_boolean (
568
- name = "image_bytes_as_serving_input" , default = True ,
571
+ name = "image_bytes_as_serving_input" , default = False ,
569
572
help = flags_core .help_wrap (
570
573
'If True exports savedmodel with serving signature that accepts '
571
574
'JPEG image bytes instead of a fixed size [HxWxC] tensor that '
0 commit comments