3

我正在尝试将一个 .proto ( ndarray.proto) 文件中定义的消息导入另一个 ( image.proto)。我的文件夹结构是:

proto/
|
|-- image.proto
|
|-- numproto/
|      |
|      |-- protobuf
|              |
|              |-- ndarray_pb2.py
|              |-- ndarray.proto

在里面image.proto我有:

syntax = "proto3";
package Image;
import "numproto/protobuf/ndarray.proto";

message image {
    int32 width = 1;
    int32 height = 2;
    numproto.protobuf.NDArray image_data = 3;
}

我希望我现在可以将 NDArray 分配给 image_data,但是当我在 Python 脚本中尝试以下操作时:

import image_pb2
from numproto import ndarray_to_proto, proto_to_ndarray

image = image_pb2.image()
a = np.hstack((np.ones(10), np.zeros(10)))
data = ndarray_to_proto(a)
image.image_data = data

我收到一个错误:

TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "image.proto":
  numproto/protobuf/ndarray.proto: Import "numproto/protobuf/ndarray.proto" has not been loaded.
  Image.image.image_data: "numproto.protobuf.NDArray" seems to be defined in "ndarray.proto", which is not imported by "image.proto".  To use it here, please add the necessary import.

我是否错误地将ndarray.proto文件导入到image.proto?

4

0 回答 0