MinAI - Về trang chủ
Lý thuyết
5/1335 phút
Đang tải...

Advanced Prompting Techniques

Kỹ thuật prompt nâng cao cho image generation - composition, style, quality control

0

🎯 Mục tiêu bài học

TB5 min

Prompt engineering cho images rất khác với text. Bài này dạy các kỹ thuật để tạo hình ảnh chất lượng cao, nhất quán và đúng ý muốn.

Sau bài này, bạn sẽ:

✅ Master prompt anatomy và structure cho image generation ✅ Sử dụng style keywords, composition techniques, camera settings ✅ Áp dụng prompt weighting cho DALL-E và Stable Diffusion ✅ Duy trì consistency khi tạo batch images

1

🔍 Prompt Anatomy

TB5 min
Diagram
Đang vẽ diagram...

Formula cơ bản

Ví dụ
1[Subject] + [Action/Pose] + [Environment] + [Style] + [Lighting] + [Quality modifiers]

Ví dụ

python.py
1prompt = """
2A Vietnamese woman in traditional ao dai,
3standing in a lotus garden at golden hour,
4soft natural lighting, shallow depth of field,
5professional photography, 8K, highly detailed
6"""
7
8negative = """
9low quality, blurry, distorted, deformed,
10bad anatomy, bad hands, watermark, text
11"""

Checkpoint

Bạn đã hiểu cấu trúc prompt gồm Subject, Style, Composition, Lighting và Quality chưa?

2

🎨 Style Keywords

TB5 min

Photography Styles

python.py
1styles = {
2 "portrait": "professional portrait photography, studio lighting, sharp focus",
3 "landscape": "landscape photography, golden hour, wide angle, vivid colors",
4 "product": "product photography, white background, studio lighting, commercial",
5 "street": "street photography, candid, natural light, urban",
6 "macro": "macro photography, extreme close-up, detailed texture, bokeh"
7}

Art Styles

python.py
1art_styles = {
2 "watercolor": "watercolor painting, soft edges, flowing colors, artistic",
3 "oil_painting": "oil painting, impasto technique, rich textures, classical",
4 "digital_art": "digital art, clean lines, vibrant, modern illustration",
5 "anime": "anime style, cel-shaded, detailed, studio quality",
6 "minimalist": "minimalist design, clean, simple, geometric, flat colors"
7}

Checkpoint

Bạn đã thử áp dụng các style keywords khác nhau để thay đổi phong cách ảnh chưa?

3

📐 Composition Techniques

TB5 min

Rule of Thirds

python.py
1composition_prompts = {
2 "rule_of_thirds": "subject positioned at rule of thirds intersection",
3 "centered": "centered composition, symmetrical",
4 "leading_lines": "leading lines drawing eye to subject",
5 "golden_ratio": "golden ratio composition, balanced",
6 "aerial": "bird's eye view, top-down perspective",
7 "low_angle": "low angle shot, dramatic perspective"
8}

Camera Settings

python.py
1camera_prompts = {
2 "wide": "wide angle lens, 24mm, expansive view",
3 "portrait": "85mm lens, shallow depth of field, bokeh",
4 "macro": "macro lens, extreme detail, close-up",
5 "telephoto": "telephoto lens, compressed perspective",
6 "tilt_shift": "tilt-shift photography, miniature effect"
7}

Checkpoint

Bạn đã biết cách sử dụng composition keywords và camera settings trong prompt chưa?

4

⚡ Prompt Weighting

TB5 min

DALL-E 3 (natural language emphasis)

python.py
1# DALL-E uses natural language - emphasize with adjectives
2prompt_dalle = """
3An EXTREMELY detailed and HIGHLY realistic photo of a
4modern Vietnamese skyline at sunset, with VIBRANT golden
5and orange colors, CRYSTAL CLEAR reflections in the river
6"""

Stable Diffusion (syntax weighting)

python.py
1# SD supports (word:weight) syntax
2prompt_sd = """
3(masterpiece:1.3), (best quality:1.2),
4a beautiful (Vietnamese landscape:1.5),
5(golden hour:1.2) lighting,
6(detailed:1.1) rice terraces
7"""
8
9# Higher weight = more emphasis
10# (word:1.5) = 50% more emphasis
11# (word:0.5) = 50% less emphasis

Checkpoint

Bạn đã hiểu sự khác biệt giữa prompt weighting trong DALL-E và Stable Diffusion chưa?

5

📝 Negative Prompting

TB5 min
python.py
1# Standard negative prompt
2standard_negative = """
3low quality, worst quality, blurry,
4distorted, deformed, disfigured,
5bad anatomy, bad hands, extra fingers,
6watermark, text, logo, signature,
7oversaturated, underexposed
8"""
9
10# Style-specific negatives
11photo_negative = standard_negative + ", cartoon, illustration, painting, drawing"
12art_negative = standard_negative + ", photo, realistic, photograph"

Checkpoint

Bạn đã biết cách sử dụng negative prompts để loại bỏ artifacts không mong muốn chưa?

6

🛠️ Prompt Templates và Consistency

TB5 min

Prompt Templates với LangChain

python.py
1from langchain_openai import ChatOpenAI
2from langchain_core.prompts import ChatPromptTemplate
3
4llm = ChatOpenAI(model="gpt-4o-mini")
5
6prompt_generator = (
7 ChatPromptTemplate.from_messages([
8 ("system", """Ban la image prompt engineer.
9 Tao prompt chi tiet cho image generation tu mo ta ngan.
10 Include: subject, style, lighting, composition, quality modifiers.
11 Output chi prompt, khong giai thich."""),
12 ("human", "Tao prompt cho: {description}\nStyle: {style}")
13 ])
14 | llm
15)
16
17result = prompt_generator.invoke({
18 "description": "Quan ca phe Viet Nam hien dai",
19 "style": "professional photography"
20})

Consistency Techniques

python.py
1# Maintain consistent style across batch
2style_prefix = "professional photography, consistent lighting, 4K, "
3
4subjects = [
5 "modern office interior",
6 "team meeting room",
7 "reception area",
8 "executive lounge"
9]
10
11prompts = [style_prefix + subject for subject in subjects]
12# All images will share consistent visual style

Checkpoint

Bạn đã thử dùng LLM để auto-generate image prompts và duy trì style consistency chưa?

7

🎯 Tổng kết

TB5 min

Bài tập thực hành

Hands-on Exercise
  1. Tạo 5 images cùng subject, khác style (photo, watercolor, anime, etc.)
  2. Thử nghiệm prompt weighting cho Stable Diffusion
  3. Build prompt generator với LLM
  4. Tạo bộ ảnh sản phẩm nhất quán

Challenge: Tạo brand visual identity với consistent style

Câu hỏi tự kiểm tra

  1. Prompt weighting hoạt động như thế nào trong Stable Diffusion và tại sao nó hữu ích cho việc kiểm soát output?
  2. Làm sao duy trì style nhất quán (consistency) khi tạo nhiều ảnh trong cùng một bộ sản phẩm?
  3. Các thành phần chính của một image prompt hiệu quả gồm những gì (subject, style, lighting, composition)?
  4. Sử dụng LLM để tự động tạo prompt cho image generation có những lợi ích và hạn chế gì?

🎉 Tuyệt vời! Bạn đã hoàn thành bài học Advanced Prompting Techniques!

Tiếp theo: Chúng ta sẽ học cách chỉnh sửa hình ảnh với AI - inpainting, outpainting và background removal.


🚀 Bài tiếp theo

Image Editing va Inpainting →