Gemini Robotics ER 2는 Python 코드를 작성하고 실행하여 이미지를 조작하고 로직을 적용한 후 답변할 수 있습니다. 이 페이지에서는 확대/축소 및 자르기를 사용한 객체 감지, 계측기 판독, 유체 측정, 회로 기판 판독, 이미지 주석과 같은 코드 실행 예시를 다룹니다.
실행 가능한 전체 코드는 로보틱스 설명서를 참고하세요.
사고 수준
사고 수준을 제어하여 지연 시간과 정확성을 절충할 수 있습니다. 객체 감지와 같은 공간 작업은 낮은 사고 수준으로도 잘 수행됩니다. 계산이나 무게 추정과 같은 복잡한 작업에는 더 높은 값이 유용합니다.
다음 예에서는 복잡한 계산 작업에 대해 사고 수준을 높음으로 설정합니다.
Python
from google import genai
from google.genai import types
client = genai.Client(
enterprise=True,
project="your-project-id",
location="global",
)
# Load your image
with open('scene.jpeg', 'rb') as f:
image_bytes = f.read()
response = client.models.generate_content(
model="gemini-robotics-er-2-preview",
contents=[
types.Part.from_bytes(
data=image_bytes,
mime_type='image/jpeg',
),
"Identify and count all objects on the table."
],
config = types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(
# Use MINIMAL or LOW for faster spatial tasks.
thinking_level=types.ThinkingLevel.HIGH
),
)
)
print(response.text)
자세한 내용은 사고를 참고하세요.
객체 감지 (확대/축소 및 자르기)
다음 예시에서는 코드 실행을 사용하여 객체를 감지하고 경계 상자를 반환할 때 더 선명하게 보기 위해 이미지를 확대하고 자르는 방법을 보여줍니다.
Python
from google import genai
from google.genai import types
client = genai.Client(
enterprise=True,
project="your-project-id",
location="global",
)
# Load your image
with open('sorting.jpeg', 'rb') as f:
image_bytes = f.read()
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.
"""
response = client.models.generate_content(
model="gemini-robotics-er-2-preview",
contents=[
types.Part.from_bytes(
data=image_bytes,
mime_type='image/jpeg',
),
prompt
],
config = types.GenerateContentConfig(
tools=[types.Tool(code_execution=types.ToolCodeExecution)],
)
)
print(response.text)
모델 출력은 다음과 비슷합니다.
[
{"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 출력을 적용합니다.
Python
from google import genai
from google.genai import types
client = genai.Client(
enterprise=True,
project="your-project-id",
location="global",
)
with open('gauge.jpeg', 'rb') as f:
image_bytes = f.read()
system_instruction = "Be precise. When JSON is requested, reply with ONLY that JSON (no preface, no code block)."
response = client.models.generate_content(
model="gemini-robotics-er-2-preview",
contents=[
types.Part.from_bytes(
data=image_bytes,
mime_type='image/jpeg',
),
"""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}"""
],
config = types.GenerateContentConfig(
system_instruction=system_instruction,
tools=[types.Tool(code_execution=types.ToolCodeExecution)],
)
)
print(response.text)
용기에 담긴 액체 측정하기
다음 예시에서는 코드 실행을 사용하여 컨테이너의 액체 수준을 측정하는 방법을 보여줍니다.
Python
from google import genai
from google.genai import types
client = genai.Client(
enterprise=True,
project="your-project-id",
location="global",
)
with open('fluid.jpeg', 'rb') as f:
image_bytes = f.read()
system_instruction = "Be precise. When JSON is requested, reply with ONLY that JSON (no preface, no code block)."
response = client.models.generate_content(
model="gemini-robotics-er-2-preview",
contents=[
types.Part.from_bytes(
data=image_bytes,
mime_type='image/jpeg',
),
"""Measure the amount of fluid in the container. Reply in JSON:
{"fluid_level_ml": val, "container_capacity_ml": val,
"percentage_full": val}"""
],
config = types.GenerateContentConfig(
system_instruction=system_instruction,
tools=[types.Tool(code_execution=types.ToolCodeExecution)],
)
)
print(response.text)
회로 기판의 표시 읽기
다음 예시에서는 코드 실행을 사용하여 회로 기판의 표시를 읽는 방법을 보여줍니다.
Python
from google import genai
from google.genai import types
client = genai.Client(
enterprise=True,
project="your-project-id",
location="global",
)
with open('circuit_board.jpeg', 'rb') as f:
image_bytes = f.read()
system_instruction = "Be precise. When JSON is requested, reply with ONLY that JSON (no preface, no code block)."
response = client.models.generate_content(
model="gemini-robotics-er-2-preview",
contents=[
types.Part.from_bytes(
data=image_bytes,
mime_type='image/jpeg',
),
"""Read all visible component labels and markings on this circuit
board. Reply in JSON: {"components": [{"label": val,
"location": [y, x]}]}"""
],
config = types.GenerateContentConfig(
system_instruction=system_instruction,
tools=[types.Tool(code_execution=types.ToolCodeExecution)],
)
)
print(response.text)
이미지 주석
다음 예시에서는 코드 실행을 사용하여 이미지에 주석을 달고 (예: 폐기 안내를 위한 화살표 그리기) 수정된 이미지를 반환하는 방법을 보여줍니다.
Python
from google import genai
from google.genai import types
client = genai.Client(
enterprise=True,
project="your-project-id",
location="global",
)
# Load your image
with open('sorting.jpeg', 'rb') as f:
image_bytes = f.read()
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.
"""
response = client.models.generate_content(
model="gemini-robotics-er-2-preview",
contents=[
types.Part.from_bytes(
data=image_bytes,
mime_type='image/jpeg',
),
prompt
],
config = types.GenerateContentConfig(
tools=[types.Tool(code_execution=types.ToolCodeExecution)],
)
)
print(response.text)
다음은 이미지 입력의 예시입니다.
모델 출력은 다음과 비슷합니다.
The annotated image shows the suggested disposal locations for the items on the table:
- **Green bin (Compost/Organic)**: Green chili, red chili, grapes, and cherries.
- **Blue bin (Recycling)**: Yellow crushed can and plastic container.
- **Black bin (Trash)**: Chocolate bar wrapper, Welch's packet, and white tissue.
다음 단계
Gemini Robotics ER 2에 대해 자세히 알아보려면 다음 리소스를 참고하세요.
- 작업 조정: 커스텀 로봇 API를 사용하는 장기 작업
- 공간 추론: 포인팅, 추적, 경계 상자, 궤적
- 동영상 이해: 순간 찾기 및 진행 상황 분류
- Gemini Robotics ER 2 개요: 기능 및 빠른 시작
- Gemini Robotics ER 2 모델 정보: 기술 사양, 토큰 한도, 지원되는 기능