에이전트형 비전

에이전트형 비전

Gemini Robotics ER 모델은 응답하기 전에 Python 코드를 작성·실행하여 이미지를 조작하고 로직을 적용할 수 있어요. 이 페이지는 코드 실행 예시를 다룬다: 확대/크롭을 이용한 객체 감지, 계측기 판독, 유체 측정, 회로 기판 판독, 이미지 주석.

이 예시를 자신의 사용 사례에 맞추려면 프롬프트 텍스트와 업로드된 이미지 파일을 자신의 것으로 바꾸세요. 애플리케이션이 필요로 하는 출력 구조에 맞게 프롬프트의 요청 JSON 스키마를 조정하거나, 출력 형식과 정밀도를 강제하기 위해 system_instruction을 추가할 수도 있어요.

완전한 실행 가능한 코드는 Robotics cookbook을 참조하세요.

출처: 원문

본문

Thinking 수준

모델의 thinking 수준을 제어해 지연 시간과 정확도를 맞바꿀 수 있어요. 객체 감지 같은 공간 작업은 낮은 thinking 수준으로 잘 수행돼요. 개수 세기나 무게 추정 같은 복잡한 작업은 더 높은 thinking 수준이 유리해요.

다음 예시는 복잡한 개수 세기 작업에 대해 thinking 수준을 high로 설정해요.

from google import genai

client = genai.Client()

uploaded_file = client.files.upload(file="scene.jpeg")

interaction = client.interactions.create(
    model="gemini-robotics-er-2-preview",
    input=[
        {
            "type": "image",
            "uri": uploaded_file.uri,
            "mime_type": uploaded_file.mime_type
        },
        {"type": "text", "text": "Identify and count all objects on the table."}
    ],
    generation_config={
        "thinking_level": "high"  # Use "minimal" or "low" for faster spatial tasks
    }
)

print(interaction.output_text)

Thinking 문서를 참조하세요.

객체 감지(확대 및 크롭)

다음 예시는 객체를 감지하고 경계 상자를 반환할 때 더 선명한 뷰를 위해 코드 실행으로 이미지를 확대하고 크롭해요.

from google import genai

client = genai.Client()

uploaded_file = client.files.upload(file="sorting.jpeg")

prompt = """
Return JSON in the format {label: val, y: val, x: val, y2: val, x2: val} for
the compostable objects in this scene. Please Zoom and crop the image for a
clearer view. Return an annotated image of the final result with the bounding
boxes drawn on it to the API caller as a part of your process.
"""

interaction = client.interactions.create(
    model="gemini-robotics-er-2-preview",
    input=[
        {
            "type": "image",
            "uri": uploaded_file.uri,
            "mime_type": uploaded_file.mime_type
        },
        {"type": "text", "text": prompt}
    ],
    tools=[{"type": "code_execution"}]
)

print(interaction.output_text)

모델 출력은 다음 JSON 응답과 유사해요.

[
  {"label": "compostable", "y": 256, "x": 482, "y2": 295, "x2": 546},
  {"label": "compostable", "y": 317, "x": 478, "y2": 350, "x2": 542},
  {"label": "compostable", "y": 586, "x": 556, "y2": 668, "x2": 595},
  {"label": "compostable", "y": 463, "x": 669, "y2": 511, "x2": 718},
  {"label": "compostable", "y": 178, "x": 565, "y2": 250, "x2": 609}
]

다음 이미지는 모델이 반환한 상자를 보여줘요.

발견된 객체에 대한 경계 상자를 보여주는 예시

아날로그 게이지 판독 및 로직 적용

다음 예시는 모델로 아날로그 게이지를 판독하고 시간 계산을 수행하는 방법을 보여줘요. JSON 출력을 강제하기 위해 시스템 지침을 사용해요.

from google import genai

client = genai.Client()

uploaded_file = client.files.upload(file="gauge.jpeg")

interaction = client.interactions.create(
    model="gemini-robotics-er-2-preview",
    system_instruction="Be precise. When JSON is requested, reply with ONLY that JSON (no preface, no code block).",
    input=[
        {
            "type": "image",
            "uri": uploaded_file.uri,
            "mime_type": uploaded_file.mime_type
        },
        {"type": "text", "text": """Read the current value from this gauge. Then, calculate how long
        it will take at the current rate for the value to reach maximum.
        Reply in JSON: {"current_value": val, "max_value": val,
        "time_to_max_minutes": val}"""}
    ],
    tools=[{"type": "code_execution"}]
)

print(interaction.output_text)

용기의 유체 측정

다음 예시는 코드 실행을 사용해 용기의 유체 수위를 측정하는 방법을 보여줘요.

from google import genai

client = genai.Client()

uploaded_file = client.files.upload(file="fluid.jpeg")

interaction = client.interactions.create(
    model="gemini-robotics-er-2-preview",
    system_instruction="Be precise. When JSON is requested, reply with ONLY that JSON (no preface, no code block).",
    input=[
        {
            "type": "image",
            "uri": uploaded_file.uri,
            "mime_type": uploaded_file.mime_type
        },
        {"type": "text", "text": """Measure the amount of fluid in the container. Reply in JSON:
        {"fluid_level_ml": val, "container_capacity_ml": val,
        "percentage_full": val}"""}
    ],
    tools=[{"type": "code_execution"}]
)

print(interaction.output_text)

회로 기판 표시 판독

다음 예시는 코드 실행을 사용해 회로 기판의 표시를 판독하는 방법을 보여줘요.

from google import genai

client = genai.Client()

uploaded_file = client.files.upload(file="circuit_board.jpeg")

interaction = client.interactions.create(
    model="gemini-robotics-er-2-preview",
    system_instruction="Be precise. When JSON is requested, reply with ONLY that JSON (no preface, no code block).",
    input=[
        {
            "type": "image",
            "uri": uploaded_file.uri,
            "mime_type": uploaded_file.mime_type
        },
        {"type": "text", "text": """Read all visible component labels and markings on this circuit
        board. Reply in JSON: {"components": [{"label": val,
        "location": [y, x]}]}"""}
    ],
    tools=[{"type": "code_execution"}]
)

print(interaction.output_text)

회로 기판의 표시를 보여주는 예시

이미지 주석

다음 예시는 코드 실행을 사용해 이미지에 주석을 달고(예: 폐기 지침용 화살표 그리기) 수정된 이미지를 반환하는 방법을 보여줘요.

from google import genai

client = genai.Client()

# Load your image
uploaded_file = client.files.upload(file="sorting.jpeg")

prompt = """
Look at this image and return it as an annotated version using arrows of
different colors to represent which items should go in which bins for
disposal. You must return the final image to the API caller.
"""

interaction = client.interactions.create(
    model="gemini-robotics-er-2-preview",
    input=[
        {
            "type": "image",
            "uri": uploaded_file.uri,
            "mime_type": uploaded_file.mime_type
        },
        {"type": "text", "text": prompt}
    ],
    tools=[{"type": "code_execution"}]
)

print(interaction.output_text)

다음은 예시 이미지 입력이에요.

판독할 시계를 보여주는 예시

모델 출력은 다음과 유사해요.

  • 주석이 달린 이미지는 테이블 위 물건들의 제안된 폐기 위치를 보여줘요:
    • 녹색 통(퇴비/유기): 홍고추, 홍고추, 포도, 체리.
    • 파란 통(재활용): 노란색 찌그러진 캔과 플라스틱 용기.
    • 검은 통(쓰레기): 초콜릿 바 포장지, Welch's 포장, 하얀 티슈.

다음 단계

더 알아보기 (Learn more)