【问题标题】:How does one properly regenerate python .pb2.py files from .proto files using protocol buffer compiler for tensorflow?如何使用 tensorflow 的协议缓冲区编译器从 .proto 文件正确地重新生成 python .pb2.py 文件?
【发布时间】:2016-12-22 06:18:55
【问题描述】:

以 incepetion_inference.proto 为例,我尝试使用以下命令重新生成 inception_inference.pb2.py 文件:

protoc inception_inference.proto --python_out=./

将新生成的文件 inception_inference.pb2.py 与最初从编译生成的文件进行比较,除了许可证通知之外,它是相同的,并且底部包含:

import abc
import six
from grpc.beta import implementations as beta_implementations
from grpc.framework.common import cardinality
from grpc.framework.interfaces.face import utilities as face_utilities

class BetaInceptionServiceServicer(six.with_metaclass(abc.ABCMeta, object)):
  """<fill me in later!>"""
  @abc.abstractmethod
  def Classify(self, request, context):
    raise NotImplementedError()

class BetaInceptionServiceStub(six.with_metaclass(abc.ABCMeta, object)):
  """The interface to which stubs will conform."""
  @abc.abstractmethod
  def Classify(self, request, timeout):

等等等等……

我猜 Bazel 构建系统的某些部分将其注入到 .pb2.py 文件中,但我找不到这是在哪里完成的。

有人知道如何正确地重新生成这个文件吗?显然,理解这是生成我自己的 .proto 文件的必要步骤。

谢谢!

【问题讨论】:

  • 对于每个 proto 文件都有一个 proto_library BUILD 目标,正确的方法是 bazel 构建该目标
  • 是的,在这种情况下: serving_proto_library( name = "inception_inference_proto", srcs = ["inception_inference.proto"], has_services = 1, cc_api_version = 2, cc_grpc_version = 1, ) 如上所述,重新生成不能开箱即用。
  • 你试过bazel build ...:inception_inference_proto吗?

标签: tensorflow protocol-buffers bazel tensorflow-serving


【解决方案1】:

试试

protoc -I ./ --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ./your.proto

确保您已经安装了 protoc 3.0(C++ 和 python 插件),并且如果您还没有在 grpcio 上运行 pip 安装。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2014-05-02
    • 1970-01-01
    相关资源
    最近更新 更多