TFRecords / TensorFlow Serving:将 TFRecords 转换为(GRPC 或 RESTFul)TensorFlow Serving 请求?

TFRecords / TensorFlow Serving: Converting TFRecords into (GRPC or RESTFul) TensorFlow Serving requests?

我有一堆用来训练模型的 TFRecords。我也想将它们与 TensorFlow Serving 一起使用。到目前为止,我一直在使用 RESTful TensorFlow 服务端点并将 TFRecords 转换为 JSON 请求主体。

是否有一些特殊的方法可以直接对 TFRecords 进行推理,而无需手动将单个 TFRecords 修改为 TF 服务请求?

TFRecords 是二进制格式,很难通过 RESTFul API 直接传递。 另一种方法是使用 tf 服务的 GRPC 端点。但这可能不会为您节省太多。

GRPC 请求需要 tensor_proto 作为输入,see here for an example call in Python. In this case, your tensor proto could be a one dimensional data containing a serialized tf.Example object that comes from TFRecord. When you save your model during the training phase, you can define custom serving input processing function, that can accept a serialized tf.Example data as input for serving. Refer to the tf.estimator.Estimator.export_saved_model 关于如何定义自定义函数 serving_input_receiver_fn 以在服务时处理输入。