简体   繁体   English

如何使用 protobuf 序列化 tuple(std::string, torch::Tensor) 的 libtorch 向量?

[英]How to serialize a libtorch vector of tuple(std::string, torch::Tensor) using protobuf?

How should I define the ProtoBuf schema so that I can serialize this vector of shape?我应该如何定义 ProtoBuf 模式以便我可以序列化这个形状向量?

std::vector<std::tuple(std::string, torch::Tensor)>

All I could find were simple trivial examples.我所能找到的只是简单的琐碎示例。 I have no idea how I should be defining the torch::Tensor or the tuple in the ProtoBuf schema!我不知道我应该如何定义torch::Tensor或 ProtoBuf 模式中的tuple

You can use string to represent torch::Tensor in the ProtoBuf schema.您可以使用string来表示 ProtoBuf 架构中的torch::Tensor

Example:例子:

syntax = "proto3";

package tensor;

message Lookup {
    message Tuple {
        string key = 1;
        string tensor = 2;
    }

    repeated Tuple tuples = 1;
}

Use torch::save() and torch::load() APIs to convert to/from std::string via std::stringstream as mentioned here .如此所述,使用torch::save()torch::load() API 通过std::stringstreamstd::string相互转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM