시각적 질문 답변
이미지의 내용, 수량 및 속성에 대해 구체적인 질문을 합니다.
시각적 질문 답변은(는) CoddyKit의 무료 AI Prompt Engineering 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 AI Prompt Engineering 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. AI Prompt Engineering 강의에는 총 4개의 강의가 포함되어 있습니다.
시각적 질문 응답(VQA)
시각적 질문 응답(VQA)은 이미지에 관한 자연어 질문에 답하는 작업입니다. 모든 것을 설명하는 이미지 설명과 달리, VQA는 특정 질문에 답하는 데 모델의 초점을 맞춥니다.
VQA 프롬프트는 정확하고 직접적이며, 시각적 콘텐츠를 세거나 식별하거나 비교하거나 추론해야 하는 경우가 많습니다. 프롬프트 품질에 따라 정확하고 유용한 답변을 얻을지, 모호하고 일반적인 응답을 얻을지가 결정됩니다.
기본 VQA 프롬프트 구조
VQA 프롬프트는 이미지와 구체적인 질문을 결합합니다. 핵심은 직접적이고 활용 가능한 답변을 만들 만큼 질문을 정확하게 작성하는 것입니다:
import anthropic, base64
client = anthropic.Anthropic(api_key='YOUR_API_KEY')
def ask_about_image(image_path, question, answer_format='Direct answer. No extra explanation.'):
with open(image_path, 'rb') as f:
img_b64 = base64.standard_b64encode(f.read()).decode('utf-8')
prompt = f'{question}\n\n{answer_format}'
r = client.messages.create(
model='claude-opus-4-5', max_tokens=150,
messages=[{'role': 'user', 'content': [
{'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/jpeg', 'data': img_b64}},
{'type': 'text', 'text': prompt}
]}]
)
return r.content[0].text
# Example VQA calls (replace image.jpg with actual image)
print('VQA function defined. Ready for image questions.')개수 세기 질문
개수 세기는 일반적인 VQA 작업입니다. 정확한 개수 세기 프롬프트를 사용하면 모호한 프롬프트보다 더 정확한 결과를 얻을 수 있습니다:
# Vague (bad):
vague_prompt = 'How many people are there?'
# Precise (good): specifies what counts and what does not
counting_prompt = '''
How many people are visible in this image?
Count only: people whose faces OR bodies are at least 50% visible.
Do NOT count: people who are heavily cropped, cut off at the edge, or only partially visible.
Return a single number.
'''
# Even more precise: handles partial visibility explicitly
precise_count = '''
Count the number of distinct individuals visible in this image.
If a person is partially obscured, count them if more than half their body is visible.
Return JSON: {"count": integer, "partially_visible": integer, "notes": "string or null"}
'''
print('Counting prompts: vague vs precise.')
print('Precise prompts define edge cases explicitly.')브랜드와 로고 식별
이미지에서 브랜드 로고를 식별하는 것은 일반적인 제품 분석 작업입니다. 프롬프트는 무엇을 찾고 어떤 형식으로 반환할지 지정해야 합니다:
logo_prompt = '''
Identify all visible brand logos, company names, and product labels in this image.
For each, note:
- Brand/company name
- Where it appears in the image (top-left, center, on a product, etc.)
- Confidence: high (clearly legible) | medium (partially visible) | low (partially obscured)
Return JSON: {"brands": [{"name": str, "location": str, "confidence": str}]}
If no logos are visible, return: {"brands": []}
'''
import anthropic, base64, json
client = anthropic.Anthropic(api_key='YOUR_API_KEY')
def identify_brands(image_path):
with open(image_path, 'rb') as f:
img_b64 = base64.standard_b64encode(f.read()).decode('utf-8')
r = client.messages.create(
model='claude-opus-4-5', max_tokens=200,
messages=[{'role': 'user', 'content': [
{'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/jpeg', 'data': img_b64}},
{'type': 'text', 'text': logo_prompt}
]}]
)
return json.loads(r.content[0].text)
print('Brand identification function defined.')감정 및 표정 인식
이미지에서 감정 표현을 식별하려면 불확실성을 인정하는 신중한 프롬프트 설계가 필요합니다:
emotion_prompt = '''
Describe the emotional expression of the person in this image.
Assess:
- Primary emotion: (happy, sad, angry, surprised, fearful, disgusted, neutral, or other)
- Intensity: (low, moderate, high)
- Confidence: (high if expression is clear, medium if subtle, low if face is obscured or turned away)
- Evidence: which specific facial features support your assessment
Return JSON:
{
"primary_emotion": str,
"intensity": str,
"confidence": str,
"evidence": str,
"secondary_emotion": str or null
}
If no person or face is clearly visible, return: {"primary_emotion": null, "confidence": "none", "reason": str}
'''
print(emotion_prompt)공간 관계 질문
객체 간 상대적 위치를 묻는 질문에는 프롬프트에 명시적인 공간 어휘가 필요합니다:
spatial_prompt = '''
Answer questions about the spatial relationships of objects in this image.
Use these spatial terms consistently:
- Position in frame: top-left, top-center, top-right, middle-left, center, middle-right, bottom-left, bottom-center, bottom-right
- Relative position: in front of, behind, to the left of, to the right of, above, below, overlapping
- Distance: in the foreground, in the midground, in the background
Question: {question}
Answer in one or two sentences using the spatial vocabulary above.
'''
# Example questions:
questions = [
'Where is the red cup relative to the laptop?',
'Is the plant in the foreground or background?',
'What object is to the left of the person?'
]
for q in questions:
print(spatial_prompt.replace('{question}', q)[:200])
print('---')품질 및 상태 평가
이미지 속 객체의 품질이나 상태를 평가하는 작업은 제품 검사, 부동산 평가, 품질 관리에 유용합니다:
condition_prompt = '''
Assess the condition of the main subject in this image.
Rate on these dimensions (1-5 scale, 5=excellent):
- Physical condition: (1=heavily damaged, 5=like new)
- Cleanliness: (1=very dirty, 5=spotless)
- Completeness: (1=major parts missing, 5=fully intact)
For each rating, provide one-sentence evidence.
Return JSON:
{
"physical_condition": {"score": int, "evidence": str},
"cleanliness": {"score": int, "evidence": str},
"completeness": {"score": int, "evidence": str},
"overall_grade": "excellent|good|fair|poor",
"recommendation": str
}
'''
print('Condition assessment prompt defined.')
print('Useful for: product inspection, real estate, equipment maintenance.')예/아니요 VQA 질문
이진 예/아니요 질문에는 단순한 불리언 값이 필요할 때 모델이 애매한 산문 답변을 하지 않도록 하는 프롬프트가 필요합니다:
def yes_no_question(image_path, question):
with open(image_path, 'rb') as f:
img_b64 = base64.standard_b64encode(f.read()).decode('utf-8')
prompt = f'''
Answer this yes/no question about the image.
Return JSON: {{"answer": "yes|no", "confidence": "high|medium|low", "reason": str}}
Do NOT answer with maybe, possibly, or a hedged statement.
If you genuinely cannot determine the answer, return {{"answer": "unclear", "confidence": "low", "reason": str}}
Question: {question}
'''
r = client.messages.create(
model='claude-opus-4-5', max_tokens=100,
messages=[{'role': 'user', 'content': [
{'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/jpeg', 'data': img_b64}},
{'type': 'text', 'text': prompt}
]}]
)
return json.loads(r.content[0].text)
# Example: 'Is there a safety helmet visible in the image?'
print('Yes/no VQA function defined.')VQA 질문 연결
동일한 이미지에 대한 여러 VQA 질문을 하나의 프롬프트로 연결하면 API 호출 횟수를 줄일 수 있습니다:
multi_question_prompt = '''
Answer all of the following questions about this image.
Return a JSON object where each key is the question ID.
Questions:
1. How many people are visible?
2. What is the approximate age range of the youngest person?
3. Is there any food visible in the image?
4. What is the dominant color in the image?
5. Is the setting indoors or outdoors?
Return JSON:
{
"q1": {"answer": str},
"q2": {"answer": str},
"q3": {"answer": "yes|no", "details": str or null},
"q4": {"answer": str},
"q5": {"answer": "indoors|outdoors|unclear"}
}
'''
print('Multi-question VQA prompt — answers 5 questions in one API call.')VQA 불확실성 처리
VQA 질문은 때때로 확실하게 답할 수 없습니다. 이미지가 흐리거나, 관련 요소가 일부 가려져 있거나, 답변이 실제로 모호할 수 있습니다. 억지로 추측하게 하는 대신 명시적인 불확실성을 요청하세요:
uncertainty_vqa_prompt = '''
Answer this question about the image as precisely as possible.
If the answer is not clearly visible or is ambiguous, say so explicitly.
Question: {question}
Return JSON:
{
"answer": str,
"confidence": "high|medium|low|cannot_determine",
"limitation": str or null
}
For confidence levels:
- high: Answer is clearly visible and unambiguous
- medium: Visible but some uncertainty
- low: Partially visible or requires inference
- cannot_determine: Not enough visual information
Question: What brand is printed on the water bottle?
'''
print(uncertainty_vqa_prompt)도메인별 VQA 프롬프트
도메인마다 필요한 VQA 어휘와 측정 기준이 다릅니다. 도메인별 프롬프트를 사용하면 더 정확하고 실행 가능한 답변을 얻을 수 있습니다:
# Manufacturing quality control VQA
qc_prompt = '''
Inspect this product image for quality defects.
Answer each question:
1. Are there any visible scratches or surface damage? (yes/no + location)
2. Is the product alignment within expected tolerance? (yes/no)
3. Are all required labels/markings present? (yes/no + list missing ones)
4. Overall QC result: PASS or FAIL?
Return JSON:
{"scratches": {"present": bool, "location": str or null},
"alignment_ok": bool,
"labels_complete": bool, "missing_labels": [str],
"qc_result": "PASS|FAIL",
"fail_reasons": [str]}
'''
# Food safety VQA
food_prompt = '''
Inspect this food preparation image.
1. Are gloves being worn? 2. Is hair covered? 3. Any visible contamination risk?
Return JSON: {"gloves": bool, "hair_covered": bool, "contamination_risk": bool, "details": str}
'''
print("Domain-specific QC and food safety VQA prompts defined.")간단 확인
이미지 속 객체의 개수를 셀 때 정확하고 활용 가능한 답변을 가장 잘 이끌어 내는 VQA 프롬프트는 무엇인가요?
VQA 프롬프트 — 핵심 요점
효과적인 시각 질의응답에는 정교하게 설계된 프롬프트가 필요합니다.
- 질문을 구체적이고 직접적으로 작성합니다 — 일부 또는 다양한처럼 모호한 표현은 피합니다.
- 개수 세기 질문에서는 경계 사례를 명시적으로 정의합니다(부분적으로 보이는 것은 어떻게 셀 것인가?).
- 애매하게 얼버무린 서술형 답변을 방지하도록 정확한 출력 형식(JSON, 단일 숫자, 예/아니요)을 지정합니다.
- 불확실한 출력을 표시할 수 있도록 모든 답변에 신뢰도 수준을 포함합니다.
- API 비용을 줄이려면 같은 이미지에 대한 여러 질문을 한 번의 호출로 묶습니다.
- 이진 예/아니요 질문에서는 애매한 응답을 명시적으로 방지하고 불명확이라는 대체 응답을 허용합니다.
- 분야별 VQA(의료, 법률, 제품)에서는 프롬프트에 해당 분야의 어휘를 포함해야 합니다.
자주 묻는 질문
“시각적 질문 답변” 강의는 무료인가요?
네 — “시각적 질문 답변” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 AI Prompt Engineering 강의 전체를 잠금 해제할 수 있습니다. AI Prompt Engineering 강의에는 총 4개의 강의가 포함되어 있습니다.
“시각적 질문 답변”에서 뭘 배우나요?
이미지의 내용, 수량 및 속성에 대해 구체적인 질문을 합니다. 브라우저에서 직접 실행하는 실습 코드로 AI Prompt Engineering을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
AI Prompt Engineering을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 AI Prompt Engineering은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“시각적 질문 답변” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 AI Prompt Engineering 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 AI Prompt Engineering 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.