我正在尝试将一个.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
中?