尝试编译 protoc 文件时出错:文件未找到或有错误

ERROR when trying to compile protoc files: file not found or had errors

我正在尝试使用此命令编译 protoc 文件:

protoc/bin/protoc models/research/object_detection/protos/*.proto --python_out=.

但我在 cmd

上得到了这个输出
object_detection/protos/flexible_grid_anchor_generator.proto: File not found.
object_detection/protos/grid_anchor_generator.proto: File not found.
object_detection/protos/multiscale_anchor_generator.proto: File not found.
object_detection/protos/ssd_anchor_generator.proto: File not found.
models/research/object_detection/protos/anchor_generator.proto:5:1: Import "object_detection/protos/flexible_grid_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:6:1: Import "object_detection/protos/grid_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:7:1: Import "object_detection/protos/multiscale_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:8:1: Import "object_detection/protos/ssd_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:14:5: "GridAnchorGenerator" is not defined.
models/research/object_detection/protos/anchor_generator.proto:15:5: "SsdAnchorGenerator" is not defined.
models/research/object_detection/protos/anchor_generator.proto:16:5: "MultiscaleAnchorGenerator" is not defined.
models/research/object_detection/protos/anchor_generator.proto:17:5: "FlexibleGridAnchorGenerator" is not defined.

所以可能是什么问题 谢谢

您需要 运行 正确目录中的 protobuf 编译器。在这种情况下,它将是 models/research:

$ cd models/research
$ ../../protoc/bin/protoc object_detection/protos/*.proto --python_out=.

protobuf 文件将被编译为 python。在目录 object_detection/protos/ 中,您应该有 python 个以 protobuf 文件命名的文件(即 <name_protobuf>_pb2.py)。

这些 protobuf 文件中有相对导入,因此 protobuf 编译器 运行 在正确的目录中很重要。您有一个提示,这可能是错误,因为 File not Found 错误消息列出了与您当前目录不同的路径。