GraphConfig

 

GraphConfig는 MediaPipe 그래프 토폴로지(통신 네트워크에서 의미하는 맥락의 토폴로지같다. 노드들과 이에 연결된 회선들을 포함한 네트워크 배열이나 구성을 개념적 그림을 표현한 것을 의미한다고 한다.)와 기능을 설명하는 명세서이다. GraphConfig에서 그래프 노드는 특정 calculator의 인스턴스를 나타낸다. 노드의 유형, 입출력과 같은 필요한 모든 구성은 GraphConfig에 설명되어야 한다. 

GraphConfig에는 그래프 실행기 구성, 스레드 수 및 입력 스트림 최대 대기열 크기와 같은 전역 그래프 수준 설정을 구성하기 위한 몇 가지 다른 필드가 있다. 여러 그래프 수준 설정은 다양한 플랫폼(ex : 데스크탑이랑 모바일)에서 그래프 성능을 조정하는 데 유용하다. 예를 들어, 모바일에서 무거운 모델 추론 계산기를 별도 실행기에 연결하면 스레드 지역성이 가능해 실시간 어플 성능을 향상시킬 수 있다.

 

ex)

# This graph named main_pass_throughcals_nosubgraph.pbtxt contains 4
# passthrough calculators.
# 4개의 통과 계산기가 포함되어 있다.
input_stream: "in"
node {
    calculator: "PassThroughCalculator"
    input_stream: "in"
    output_stream: "out1"
}
node {
    calculator: "PassThroughCalculator"
    input_stream: "out1"
    output_stream: "out2"
}
node {
    calculator: "PassThroughCalculator"
    input_stream: "out2"
    output_stream: "out3"
}
node {
    calculator: "PassThroughCalculator"
    input_stream: "out3"
    output_stream: "out4"
}

Subgraph

 

CalculatorGraphConfig를 하위 모듈로 모듈화하고 perception solution 재사용을 지원하기 위해 MediaPipe 그래프를 하위 그래프로 정의할 수 있다. subgraph의 공개 인터페이스는 Calculator 공개 인터페이스와 유사한 일련의 입출력 스트림으로 구성된다. 그러면 subgraph가 Calculator인 것처럼 CalculatorGraphConfig에 포함될 수 있다. CalculatorGraphConfig에서 MediaPipe 그래프가 로드되면 각 subgraph 노드가 해당 Calculator 그래프로 대체된다. 결과적으로 subgraph 의미 및 성능은 해당 Calculator 그래프와 동일하다.

 

그래프 안의 그래프가 가능하다는 것 같다. 그래프든 Calculator든 모듈처럼 붙였다 뗐다가 가능한 것 같다.

 

ex)

 

1. subgraph

# This subgraph is defined in two_pass_through_subgraph.pbtxt
# and is registered as "TwoPassThroughSubgraph"

type: "TwoPassThroughSubgraph"
input_stream: "out1"
output_stream: "out3"

node {
    calculator: "PassThroughCalculator"
    input_stream: "out1"
    output_stream: "out2"
}
node {
    calculator: "PassThroughCalculator"
    input_stream: "out2"
    output_stream: "out3"
}

subgraph 공개 인터페이스는 다음과 같이 구성되어 있다.

  • Graph input streams
  • Graph output streams
  • Graph input side packets
  • Graph output side packets

2. BUILD 규칙 mediapipe_simple_subgraph를 사용해 subgraph를 등록한다. 매개변수 register_as는 새 subgraph의 구성 요소 이름을 정의한다.

# Small section of BUILD file for registering the "TwoPassThroughSubgraph"
# subgraph for use by main graph main_pass_throughcals.pbtxt

mediapipe_simple_subgraph(
    name = "twopassthrough_subgraph",
    graph = "twopassthrough_subgraph.pbtxt",
    register_as = "TwoPassThroughSubgraph",
    deps = [
            "//mediapipe/calculators/core:pass_through_calculator",
            "//mediapipe/framework:calculator_graph",
    ],
)
Use the subgraph in the main graph.

# This main graph is defined in main_pass_throughcals.pbtxt
# using subgraph called "TwoPassThroughSubgraph"

input_stream: "in"
node {
    calculator: "PassThroughCalculator"
    input_stream: "in"
    output_stream: "out1"
}
node {
    calculator: "TwoPassThroughSubgraph"
    input_stream: "out1"
    output_stream: "out3"
}
node {
    calculator: "PassThroughCalculator"
    input_stream: "out3"
    output_stream: "out4"
}

 

이걸 보니까 mediapipe 전부가 엄청 많은 subgraph 들로 이뤄져 있고 그걸 다 적당한 기능에 맞춰서 연결하는 거구나.. 싶다.

 

'그 외 공부 > 하루하루 깨달은 바' 카테고리의 다른 글

Mediapipe Packets  (0) 2021.11.05
Mediapipe Calculators  (0) 2021.11.05

+ Recent posts