הבנת תמונות
מודלים של Gemini מבוססים על מולטי-מודאליות מההתחלה, ולכן הם יכולים לבצע מגוון רחב של משימות עיבוד תמונות וראייה ממוחשבת, כולל תיוג תמונות, סיווג תמונות ומענה לשאלות על תמונות, בלי צורך לאמן מודלים מיוחדים של למידת מכונה.
בנוסף ליכולות הכלליות של מודלים מרובי-מוֹדָלִים, מודלים של Gemini מציעים דיוק משופר בתרחישי שימוש ספציפיים כמו זיהוי אובייקטים ופילוח, באמצעות אימון נוסף.
העברת תמונות ל-Gemini
יש כמה דרכים לספק תמונות כקלט ל-Gemini:
- העברת תמונה באמצעות כתובת URL: מתאים לתמונות שזמינות לכולם.
- העברת נתוני תמונה בתוך השורה: נתוני תמונה בקידוד base64.
- העלאת תמונות באמצעות File API: מומלץ לקבצים גדולים יותר או לשימוש חוזר בתמונות בכמה בקשות.
העברת תמונה באמצעות כתובת URL
אפשר להעלות תמונה באמצעות Files API ולהעביר אותה בבקשה:
Python
from google import genai
client = genai.Client()
uploaded_file = client.files.upload(file="path/to/organ.jpg")
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"uri": uploaded_file.uri,
"mime_type": uploaded_file.mime_type
}
]
)
print(interaction.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const uploadedFile = await client.files.upload({
file: "path/to/organ.jpg",
config: { mimeType: "image/jpeg" }
});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{type: "text", text: "Caption this image."},
{
type: "image",
uri: uploadedFile.uri,
mimeType: uploadedFile.mimeType
}
]
});
console.log(interaction.steps.at(-1).content[0].text);
REST
# First upload the file using the Files API, then use the URI:
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": [
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"uri": "YOUR_FILE_URI",
"mime_type": "image/jpeg"
}
]
}'
העברת נתונים של תמונות מוטבעות
אפשר לספק נתוני תמונה כמחרוזות בקידוד Base64:
Python
from google import genai
with open('path/to/small-sample.jpg', 'rb') as f:
image_bytes = f.read()
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"data": base64.b64encode(image_bytes).decode('utf-8'),
"mime_type": "image/jpeg"
}
]
)
print(interaction.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
const client = new GoogleGenAI({});
const base64ImageFile = fs.readFileSync("path/to/small-sample.jpg", {
encoding: "base64",
});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{type: "text", text: "Caption this image."},
{
type: "image",
data: base64ImageFile,
mime_type: "image/jpeg"
}
]
});
console.log(interaction.steps.at(-1).content[0].text);
REST
IMG_PATH="/path/to/your/image1.jpg"
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
B64FLAGS="--input"
else
B64FLAGS="-w0"
fi
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": [
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"data": "'"$(base64 $B64FLAGS $IMG_PATH)"'",
"mime_type": "image/jpeg"
}
]
}'
העלאת תמונות באמצעות File API
כדי להשתמש בקובץ תמונה גדול או כדי להשתמש שוב ושוב באותו קובץ תמונה, צריך להשתמש ב-Files API. מידע נוסף מופיע במדריך לשימוש ב-Files API.
Python
from google import genai
client = genai.Client()
my_file = client.files.upload(file="path/to/sample.jpg")
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"uri": my_file.uri,
"mime_type": my_file.mime_type
}
]
)
print(interaction.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const myfile = await client.files.upload({
file: "path/to/sample.jpg",
config: { mimeType: "image/jpeg" },
});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{type: "text", text: "Caption this image."},
{
type: "image",
uri: myfile.uri,
mime_type: myfile.mimeType
}
]
});
console.log(interaction.steps.at(-1).content[0].text);
REST
# First upload the file (see Files API guide for details)
# Then use the file URI in the request:
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": [
{"type": "text", "text": "Caption this image."},
{
"type": "image",
"uri": "YOUR_FILE_URI",
"mime_type": "image/jpeg"
}
]
}'
יצירת הנחיות עם כמה תמונות
אפשר לספק כמה תמונות בהנחיה אחת על ידי הכללת כמה אובייקטים של תמונות במערך input:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": "What is different between these two images?"},
{
"type": "image",
"uri": "https://example.com/image1.jpg",
"mime_type": "image/jpeg"
},
{
"type": "image",
"uri": "https://example.com/image2.jpg",
"mime_type": "image/jpeg"
}
]
)
print(interaction.steps[-1].content[0].text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: [
{type: "text", text: "What is different between these two images?"},
{
type: "image",
uri: "https://example.com/image1.jpg",
mime_type: "image/jpeg"
},
{
type: "image",
uri: "https://example.com/image2.jpg",
mime_type: "image/jpeg"
}
]
});
console.log(interaction.steps.at(-1).content[0].text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": [
{"type": "text", "text": "What is different between these two images?"},
{
"type": "image",
"uri": "https://example.com/image1.jpg",
"mime_type": "image/jpeg"
},
{
"type": "image",
"uri": "https://example.com/image2.jpg",
"mime_type": "image/jpeg"
}
]
}'
זיהוי אובייקטים
המודלים מאומנים לזהות אובייקטים בתמונה ולקבל את הקואורדינטות של התיבה התוחמת שלהם. הקואורדינטות, ביחס לממדי התמונה, מותאמות לטווח [0, 1000]. צריך לבטל את שינוי קנה המידה של הקואורדינטות האלה על סמך גודל התמונה המקורי.
Python
from google import genai
from PIL import Image
import json
client = genai.Client()
prompt = "Detect the all of the prominent items in the image. The box_2d should be [ymin, xmin, ymax, xmax] normalized to 0-1000."
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": prompt},
{
"type": "image",
"uri": "https://example.com/image.png",
"mime_type": "image/png"
}
],
response_format={
"type": "text",
"mime_type": "application/json"
}
)
bounding_boxes = json.loads(interaction.steps[-1].content[0].text)
print("Bounding boxes:", bounding_boxes)
דוגמאות נוספות זמינות בתיקיות Notebook הבאות בספר המתכונים של Gemini:
פילוח
החל מ-Gemini 2.5, המודלים לא רק מזהים פריטים אלא גם מבצעים פילוח שלהם ומספקים את מסכות המתאר שלהם.
המודל חוזה רשימת JSON, שבה כל פריט מייצג מסכת פילוח.
לכל פריט יש תיבת תוחמת (bounding box) ("box_2d") בפורמט [y0, x0, y1, x1] עם קואורדינטות מנורמלות בין 0 ל-1,000, תווית ("label") שמזהה את האובייקט, ולבסוף מסכת הפילוח בתוך התיבה התוחמת, כקובץ PNG עם קידוד base64 שהוא מפת הסתברות עם ערכים בין 0 ל-255.
Python
from google import genai
from PIL import Image
import json
client = genai.Client()
prompt = """
Give the segmentation masks for the wooden and glass items.
Output a JSON list of segmentation masks where each entry contains the 2D
bounding box in the key "box_2d", the segmentation mask in key "mask", and
the text label in the key "label". Use descriptive labels.
"""
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=[
{"type": "text", "text": prompt},
{
"type": "image",
"uri": "https://example.com/image.png",
"mime_type": "image/png"
}
],
config={
"thinking_level": "minimal" # Minimize thinking for better detection results
}
)
items = json.loads(interaction.steps[-1].content[0].text)
print("Segmentation results:", items)
אילו פורמטים של תמונות נתמכים?
Gemini תומך בסוגי ה-MIME הבאים של פורמטים של תמונות:
- PNG –
image/png - JPEG –
image/jpeg - WEBP –
image/webp - HEIC –
image/heic - HEIF -
image/heif
מידע על שיטות אחרות להזנת קבצים זמין במדריך בנושא שיטות להזנת קבצים.
יכולות
כל הגרסאות של מודל Gemini הן מולטי-מודאליות, ואפשר להשתמש בהן במגוון רחב של משימות עיבוד תמונות וראייה ממוחשבת, כולל, בין היתר, כיתוב תמונות, מענה על שאלות שקשורות לאובייקטים חזותיים, סיווג תמונות, זיהוי אובייקטים ופילוח.
יכול להיות ש-Gemini יצמצם את הצורך בשימוש במודלים מיוחדים של ML, בהתאם לדרישות האיכות והביצועים שלכם.
הגרסאות העדכניות של המודלים אומנו במיוחד כדי לשפר את הדיוק של משימות ייעודיות, בנוסף ליכולות כלליות כמו זיהוי אובייקטים ופילוח משופרים.
מגבלות ומידע טכני חשוב
מכסת קבצים
מודלים של Gemini תומכים בעד 3,600 קבצים של תמונות לכל בקשה.
חישוב טוקנים
- 258 טוקנים אם שני המימדים הם 384 פיקסלים או פחות. תמונות גדולות יותר מחולקות למקטעים בגודל 768x768 פיקסלים, וכל מקטע עולה 258 טוקנים.
נוסחה משוערת לחישוב מספר המשבצות:
- חישוב גודל יחידת החיתוך, שהוא בערך:
floor(min(width, height)/ 1.5). - מחלקים כל מאפיין בגודל יחידת החיתוך ומכפילים את התוצאה כדי לקבל את מספר האריחים.
לדוגמה, אם התמונה היא בגודל 960x540, גודל יחידת החיתוך יהיה 360. מחלקים כל מאפיין ב-360 ומקבלים 3 * 2 = 6 משבצות.
רזולוציית המדיה
Gemini 3 מציג שליטה מפורטת בעיבוד של ראייה מולטי-מודאלית באמצעות הפרמטר media_resolution. הפרמטר media_resolution קובע את המספר המקסימלי של טוקנים שמוקצים לכל תמונה או פריים של סרטון קלט.
רזולוציות גבוהות יותר משפרות את היכולת של המודל לקרוא טקסט קטן או לזהות פרטים קטנים, אבל הן מגדילות את השימוש בטוקנים ואת זמן האחזור.
טיפים ושיטות מומלצות
- מוודאים שהתמונות מסובבות בצורה נכונה.
- השתמשו בתמונות ברורות ולא מטושטשות.
- כשמשתמשים בתמונה אחת עם טקסט, צריך למקם את הנחיית הטקסט לפני התמונה במערך
input.
המאמרים הבאים
במדריך הזה מוסבר איך להעלות קובצי תמונות וליצור פלט טקסט מקלט תמונה. מידע נוסף זמין במקורות המידע הבאים:
- Files API: מידע נוסף על העלאה וניהול של קבצים לשימוש עם Gemini
- הוראות למערכת: הוראות למערכת מאפשרות לכם לכוון את התנהגות המודל בהתאם לצרכים הספציפיים ולתרחישי השימוש שלכם.
- אסטרטגיות לכתיבת הנחיות עם קבצים: Gemini API תומך בכתיבת הנחיות עם נתוני טקסט, תמונה, אודיו ווידאו, שנקראות גם כתיבת הנחיות מולטי-מודאליות.
- הנחיות בנושא בטיחות: לפעמים מודלים של AI גנרטיבי יוצרים תוצאות לא צפויות, כמו תוצאות לא מדויקות, מוטות או פוגעניות. עיבוד תמונה (Post Processing) והערכה אנושית חיוניים כדי לצמצם את הסיכון לנזק שעלול להיגרם מתוצאות כאלה.