Get value from c10::Dict<c10::IValue, c10::IValue>

Hi, I’m using a TorchScript Model on Pytorch C++ Frontend.

The model in Python return an output dict as Dict[str, List[torch.Tensor]].

When I use it in C++, it return a c10::Dict<c10::IValue, c10::IValue>. But what is the equivalents of this Python code:

value_a = output['key_a']
value_b = output['key_b']

in C++ to get value from c10::Dict

I have tried this but it does not work.

torch::IValue key_a("key_a");
torch::IValue key_b("key_b");
c10::IValue value_a = output[key_a];
c10::IValue value_b = output[key_b];
std::cout << value_a << std::endl;
std::cout << value_b << std::endl;

Output:

error: type 'c10::Dict<c10::IValue, c10::IValue>' does not provide a subscript operator

Anyone can give me a little help here. Thanks

Also asked in here https://stackoverflow.com/questions/63917001/get-value-from-c10dictc10ivalue-c10ivalue-in-pytorch-c

As answer by https://stackoverflow.com/users/10886420/szymon-maszke on the StackOverFlow question. The correct way to do this is:

auto a = output.at("key_a")