简体   繁体   中英

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?

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!

You can use string to represent torch::Tensor in the ProtoBuf schema.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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