C++ input side packets

343 views
Skip to first unread message

Aleksandr Yeganov

unread,
Dec 16, 2021, 4:10:59 PM12/16/21
to MediaPipe
Hello,

I am working on creating a custom solution using MediaPipe. As part of that solution I need to be able to switch calculators at will, depending on the users input. From my understanding this can be achieved by using SwitchContainer and InputSidePackets. I have created a configuration with SwitchContainer, but I can't find a way to change input side packets values after executing `graph.Start()` method.

1. Is this possible to do?
2. Am I on the right track, or is there a different approach?

Thanks,
Aleks

Aleksandr Yeganov

unread,
Jan 19, 2022, 9:11:29 AM1/19/22
to MediaPipe
For anyone looking here in the future. No need for InputSidePacket, regular input_stream would work. Example:

input_stream: "selected_encoder"

node
{
  calculator: "SwitchContainer"
  name: "Encoder"
  input_stream: "SELECT:selected_encoder"
  input_stream: "INPUT_TENSOR:input_tensor"
  output_stream: "OUTPUT_TENSOR:encoder_tensor"
  node_options:
  {
    [type.googleapis.com/mediapipe.SwitchContainerOptions]
    {
      contained_node:
      {
        calculator: "OnnxModelInference"
        name: "LadonNamedEncoder"
        options: {
          [mediapipe.OnnxSessionFromSavedModelOptions.ext]
          {
            saved_model_path: "/media/data/ml_models/ladon_named_tensors/encoder_model.onnx"
          }
        }
      }
      contained_node:
      {
        calculator: "OnnxModelInference"
        name: "LadonIndexEncoder"
        options: {
          [mediapipe.OnnxSessionFromSavedModelOptions.ext]
          {
            saved_model_path: "/media/data/ml_models/ladon_named_tensors/different_encoder.onnx"
            input_tensor_index: [0]
          }
        }
      }
    }
  }
}

In the code after you have initialized and started the graph object:

  auto encoder =  mediapipe::MakePacket<int32_t>(1);
  auto timestamp_us =
        (double)cv::getTickCount() / (double)cv::getTickFrequency() * 1e6;
  auto status = graph->AddPacketToInputStream("selected_encoder",
                                              encoder.At(mediapipe::Timestamp(timestamp_us)));

Reply all
Reply to author
Forward
0 new messages