当前版本的tensorflow-serving尝试从asset.extra / tf_serving_warmup_requests文件加载预热请求。
2018-08-16 16:05:28.513085:I tensorflow_serving / servables / tensorflow / saved_model_warmup.cc:83]在/tmp/faster_rcnn_inception_v2_coco_2018_01_28_string_input_version-export/1/assets.extra/tp_up_reserving/ >
我想知道tensorflow是否提供通用API来将请求导出到该位置吗?还是我们应该手动将请求写到该位置?
答案 0 :(得分:4)
目前,尚无用于将预热数据导出到asset.extra的通用API。编写脚本相对简单(类似于以下内容):
import tensorflow as tf
from tensorflow_serving.apis import model_pb2
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_log_pb2
def main():
with tf.python_io.TFRecordWriter("tf_serving_warmup_requests") as writer:
request = predict_pb2.PredictRequest(
model_spec=model_pb2.ModelSpec(name="<add here>"),
inputs={"examples": tf.make_tensor_proto([<add here>])}
)
log = prediction_log_pb2.PredictionLog(
predict_log=prediction_log_pb2.PredictLog(request=request))
writer.write(log.SerializeToString())
if __name__ == "__main__":
main()
答案 1 :(得分:0)
我们提到了official doc
特别是,我们使用分类而不是预测,因此我们将代码更改为
log = prediction_log_pb2.PredictionLog(
classify_log=prediction_log_pb2.ClassifyLog(request=<request>))
答案 2 :(得分:0)
这是使用ResNet model的对象检测系统的完整示例。预测由图像组成。
import tensorflow as tf
import requests
import base64
from tensorflow.python.framework import tensor_util
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_log_pb2
IMAGE_URL = 'https://tensorflow.org/images/blogs/serving/cat.jpg'
NUM_RECORDS = 100
def get_image_bytes():
image_content = requests.get(IMAGE_URL, stream=True)
image_content.raise_for_status()
return image_content.content
def main():
"""Generate TFRecords for warming up."""
with tf.io.TFRecordWriter("tf_serving_warmup_requests") as writer:
image_bytes = get_image_bytes()
predict_request = predict_pb2.PredictRequest()
predict_request.model_spec.name = 'resnet'
predict_request.model_spec.signature_name = 'serving_default'
predict_request.inputs['image_bytes'].CopyFrom(
tensor_util.make_tensor_proto([image_bytes], tf.string))
log = prediction_log_pb2.PredictionLog(
predict_log=prediction_log_pb2.PredictLog(request=predict_request))
for r in range(NUM_RECORDS):
writer.write(log.SerializeToString())
if __name__ == "__main__":
main()
此脚本将创建一个名为“ tf_serving_warmup_requests”的文件
我将此文件移至/your_model_location/resnet/1538687457/assets.extra/
,然后重新启动docker镜像以获取新更改。