我正在转换tensorflow.keras公司估计量的模型及其应用
estimator.export_saved_mode(serving_input_receiver_fn=serving_input_receiver_fn)
让我的模型准备好为TensorFlow服务。这是我的
serving_input_receiver_fn
看起来像:
def image_preprocessing(image):
image = tf.expand_dims(image, 0)
image = tf.image.resize_bilinear(image, [HEIGHT, WIDTH], align_corners=False)
image = tf.squeeze(image, axis=[0])
image = tf.cast(image, dtype=tf.uint8)
return image
def serving_input_receiver_fn():
def prepare_image(image_str_tensor):
image = tf.image.decode_jpeg(image_str_tensor, channels=CHANNELS)
return image_preprocessing(image)
input_ph = tf.placeholder(tf.string, shape=[None], name='image_binary')
images_tensor = tf.map_fn(prepare_image, input_ph, back_prop=False, dtype=tf.uint8)
images_tensor = tf.image.convert_image_dtype(images_tensor, dtype=tf.float32)
return tf.estimator.export.ServingInputReceiver(
{model.input_names[0]: images_tensor},
{'image_bytes': input_ph})
是否有方法继续将uint8作为输入,但将其转换为float32,然后应用tensorflow.keras公司预处理功能,如
tensorflow.keras.applications.xception.preprocess_input
?
我不知道如何根据平均值/标准差tensorflow.keras.应用模型。在添加上述内容之前,我的模型接受了numpy数组的json序列化列表,并且我会在客户端对它们进行规范化。既然它接受uint8 base64编码字节字符串,我不知道如何将keras规范化移到这个函数。