พรอมต์เชิงลบและสิ่งที่ต้องยกเว้น
สิ่งที่ต้องยกเว้น: ภาพเบลอ ลายน้ำ ภาพน่าเกลียด ภาพผิดรูป — การเขียนพรอมต์เชิงลบอย่างมีประสิทธิภาพ
พรอมต์เชิงลบและสิ่งที่ต้องยกเว้น เป็นบทเรียน AI Prompt Engineering ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Prompt Engineering และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน
พรอมต์เชิงลบคืออะไร
พรอมต์เชิงลบจะบอกโมเดลสร้างภาพว่าไม่ควรใส่อะไรลงในภาพที่ generate พรอมต์เหล่านี้แยกจากพรอมต์เชิงบวก และช่วยชี้นำการ generate ให้ห่างจากสิ่งแปลกปลอม สไตล์ และองค์ประกอบที่ไม่ต้องการ เดิมทีแนวคิดนี้เป็นคุณสมบัติของ Stable Diffusion แต่ภายหลังได้แพร่หลายไปยังโมเดลสร้างภาพต่าง ๆ
ไวยากรณ์พรอมต์เชิงลบของ Stable Diffusion
ใน Stable Diffusion พรอมต์เชิงลบจะถูกส่งผ่านพารามิเตอร์แยกต่างหาก โมเดลจะปฏิบัติต่อพรอมต์เหล่านี้เป็นการชี้นำเชิงต้าน: แนวคิดที่อยู่ในพรอมต์เชิงลบจะถูกผลักออกอย่างต่อเนื่องระหว่างการ generate
import requests
SD_API_URL = 'http://localhost:7860/sdapi/v1/txt2img'
def generate_sd_image(positive_prompt, negative_prompt, steps=30, cfg_scale=7):
payload = {
'prompt': positive_prompt,
'negative_prompt': negative_prompt,
'steps': steps,
'cfg_scale': cfg_scale, # 7-12 recommended
'width': 512,
'height': 512,
'sampler_name': 'DPM++ 2M Karras'
}
response = requests.post(SD_API_URL, json=payload)
return response.json()
# Example call with negative prompt
positive = (
'portrait of a young woman, soft natural light, '
'professional photography, sharp focus, elegant'
)
negative = (
'blurry, watermark, text, logo, ugly, distorted, '
'deformed, extra fingers, extra limbs, bad anatomy, '
'low quality, low resolution, grainy, noisy, '
'oversaturated, harsh shadows'
)
result = generate_sd_image(positive, negative)
print('Generated:', len(result.get('images', [])), 'images')พรอมต์เชิงลบด้านคุณภาพแบบสากล
ชุดคำศัพท์พรอมต์เชิงลบมาตรฐานช่วยปรับปรุงคุณภาพผลลัพธ์สำหรับหัวข้อเกือบทุกประเภท โปรดจดจำหรือบันทึกชุดนี้ไว้เป็นจุดเริ่มต้นเริ่มต้นของคุณ
# Universal quality negative prompt
QUALITY_NEGATIVES = [
# Technical quality issues
'blurry', 'out of focus', 'low quality', 'low resolution',
'pixelated', 'grainy', 'noisy', 'compressed artifacts', 'jpeg artifacts',
# Anatomical distortions (common AI failure mode)
'extra fingers', 'extra limbs', 'extra arms', 'deformed hands',
'bad anatomy', 'malformed', 'mutated', 'disfigured',
# Unwanted elements
'watermark', 'text', 'logo', 'signature', 'caption',
'border', 'frame', 'username',
# Stylistic failures
'ugly', 'poorly drawn', 'amateur', 'sketch',
'unfinished', 'rough draft',
# Color problems
'oversaturated', 'washed out', 'overexposed', 'underexposed'
]
UNIVERSAL_NEGATIVE = ', '.join(QUALITY_NEGATIVES)
print('Universal negative prompt:')
print(UNIVERSAL_NEGATIVE[:200], '...')พรอมต์เชิงลบด้านกายวิภาคและร่างกาย
เป็นที่รู้กันดีว่าโมเดลสร้างภาพด้วย AI มักมีปัญหากับมือและนิ้ว พรอมต์เชิงลบด้านกายวิภาคที่ระบุอย่างเจาะจงช่วยลดสิ่งแปลกปลอมเหล่านี้ได้อย่างมากเมื่อ generate รูปร่างมนุษย์
ANATOMY_NEGATIVES = [
# Hand and finger issues
'extra fingers', 'missing fingers', 'deformed fingers',
'fused fingers', 'too many fingers', 'six fingers',
'wrong number of fingers', 'extra hands', 'floating hand',
# Face issues
'distorted face', 'asymmetrical face', 'multiple faces',
'merged faces', 'duplicate head', 'two heads',
'extra eyes', 'missing eyes', 'heterochromia (if not desired)',
# Body proportions
'extra legs', 'extra arms', 'floating limbs',
'bad proportions', 'unrealistic body proportions',
'torso too long', 'missing torso',
# Skin
'skin blemishes', 'skin texture issues'
]
BODY_NEGATIVE = ', '.join(ANATOMY_NEGATIVES)
# Full portrait negative prompt combining quality + anatomy
PORTRAIT_NEGATIVE = UNIVERSAL_NEGATIVE + ', ' + BODY_NEGATIVE
print('Portrait negative length:', len(PORTRAIT_NEGATIVE.split(',')), 'terms')การตัดสไตล์ออกด้วยพรอมต์เชิงลบ
พรอมต์เชิงลบสามารถตัดสไตล์ที่ไม่ต้องการออกได้ ซึ่งมีประโยชน์เมื่อคำศัพท์ด้านสไตล์ในพรอมต์เชิงบวกดึงดูดสไตล์ใกล้เคียงที่คุณต้องการหลีกเลี่ยง ตัวอย่างการตัดสไตล์ที่พบบ่อย:
style_exclusion_examples = [
{
'goal': 'Oil painting portrait without cartoonish look',
'positive': 'oil painting portrait, classical technique, highly detailed',
'negative': 'cartoon, anime, illustration, flat colors, cel-shaded, vector'
},
{
'goal': 'Photorealistic image without HDR over-processing',
'positive': 'photorealistic landscape, natural light, DSLR quality',
'negative': 'HDR, hyper-saturated, over-processed, Instagram filter, tone-mapped'
},
{
'goal': 'Dark fantasy without gore',
'positive': 'dark fantasy warrior, dramatic lighting, detailed armor',
'negative': 'gore, blood, violence, disturbing content, horror'
},
{
'goal': 'Vintage look without actual age degradation',
'positive': 'vintage 1960s photograph, film grain, warm tones',
'negative': 'deteriorated, damaged, torn, stains, yellowed, faded'
}
]
for ex in style_exclusion_examples[:2]:
print(f'Goal: {ex["goal"]}')
print(f'Negative: {ex["negative"][:60]}...')
print()ไวยากรณ์การหลีกเลี่ยงของ DALL-E
DALL-E 3 ไม่มีช่องพรอมต์เชิงลบแยกต่างหาก แต่ให้เขียนสิ่งที่ต้องการตัดออกตามธรรมชาติในพรอมต์เชิงบวก โดยใช้ถ้อยคำอย่าง 'avoid', 'without', 'no' หรือ 'do not include'
import openai
client = openai.OpenAI(api_key='YOUR_API_KEY')
# DALL-E 3: exclusions in the positive prompt
dalle_prompt_with_exclusions = (
'A professional portrait photograph of a businesswoman in a modern office. '
'Natural window light, shallow depth of field, warm tones. '
'Do not include: any text, watermarks, logos, or captions. '
'Avoid: cartoon or illustrated style, anime, artificial-looking skin. '
'The image should have no distracting background elements. '
'Realistic and natural — not over-processed or filtered.'
)
response = client.images.generate(
model='dall-e-3',
prompt=dalle_prompt_with_exclusions,
size='1024x1024',
quality='hd',
n=1
)
image_url = response.data[0].url
print('Generated image URL:', image_url[:60], '...')ความแรงของพรอมต์เชิงลบและมาตราส่วน CFG
ใน Stable Diffusion มาตราส่วน CFG (การชี้นำโดยไม่มีตัวจำแนก) จะควบคุมว่าพรอมต์ทั้งเชิงบวกและเชิงลบมีอิทธิพลต่อการ generate มากเพียงใด ค่า CFG ที่สูงขึ้นหมายถึงการทำตามพรอมต์ที่แรงขึ้น แต่อาจทำให้เกิดสิ่งแปลกปลอมได้
# CFG scale guide for Stable Diffusion
cfg_guide = {
3: 'Very loose adherence, creative/random, may ignore negative prompts',
5: 'Balanced: creative but follows prompts generally',
7: 'Standard: good balance of quality and adherence (recommended default)',
10: 'Strong adherence: follows both positive and negative prompts closely',
12: 'Very strong: highly literal, may oversaturate colors or cause artifacts',
15: 'Extreme: usually causes artifacts, rarely useful'
}
# Parenthetical weighting in Stable Diffusion
# Surround a term with () to increase its weight
# surround with [] to decrease its weight
weighted_negative = (
'(blurry:1.3), (extra fingers:1.5), watermark, '
'[slight noise:0.5], text'
# extra fingers gets 1.5x negative weight (most important to avoid)
# blurry gets 1.3x negative weight
# slight noise gets reduced 0.5x weight (tolerate a little)
)
print('CFG=7 (recommended default) balances quality and prompt adherence')
print('Weighted negative example:', weighted_negative[:80], '...')การสร้างคลังพรอมต์เชิงลบ
กรณีการใช้งานที่แตกต่างกันต้องใช้ชุดพรอมต์เชิงลบที่แตกต่างกัน โปรดสร้างคลังพรอมต์เชิงลบเฉพาะด้านที่สามารถนำมาประกอบรวมกันได้สำหรับงาน generate ทุกประเภท
NEGATIVE_PROMPT_LIBRARY = {
'quality_base': (
'blurry, low quality, low resolution, pixelated, '
'watermark, text, logo, signature'
),
'anatomy': (
'extra fingers, deformed hands, bad anatomy, '
'extra limbs, distorted face'
),
'portrait_specific': (
'double chin exaggerated, skin blemishes, '
'red eye, harsh shadows on face'
),
'landscape_specific': (
'overcast flat light, washed out colors, '
'lens flare, chromatic aberration'
),
'product_photo': (
'shadow on product, uneven background, '
'reflection glare, dust spots'
),
'no_style_bleed': (
'anime, cartoon, illustration, painting, '
'sketch (when photorealism is desired)'
)
}
def compose_negative(*keys):
return ', '.join(NEGATIVE_PROMPT_LIBRARY[k] for k in keys)
# Portrait generation
portrait_neg = compose_negative('quality_base', 'anatomy', 'portrait_specific')
print('Portrait negative:', portrait_neg[:100], '...')
# Product photo generation
product_neg = compose_negative('quality_base', 'product_photo', 'no_style_bleed')
print('Product negative:', product_neg[:100], '...')เมื่อพรอมต์เชิงลบใช้ไม่ได้ผล
พรอมต์เชิงลบไม่ใช่หลักประกัน เพราะช่วยลดความน่าจะเป็นขององค์ประกอบที่ไม่ต้องการ แต่ไม่สามารถกำจัดองค์ประกอบเหล่านั้นได้ทั้งหมด การทำความเข้าใจว่าเมื่อใดพรอมต์เหล่านี้ใช้ไม่ได้ผลจะช่วยให้คุณตั้งความคาดหวังได้อย่างสมจริง
negative_prompt_limitations = {
'Failure: Concept too abstract': {
'problem': '"bad" is too vague for the model to act on',
'fix': 'Use specific concrete terms: "blurry", "deformed", "watermark"'
},
'Failure: Contradiction with positive prompt': {
'problem': 'Positive: "detailed painting" | Negative: "painting"',
'fix': 'Narrow negative to the specific aspect: negative: "amateur painting, rough sketch"'
},
'Failure: Too many negative terms dilute effect': {
'problem': '200-word negative prompt where each term gets minimal weight',
'fix': 'Limit to 15-20 terms. Use weighting for most critical: "(extra fingers:1.5)"'
},
'Failure: Watermarks still appear': {
'problem': 'Some model checkpoints are strongly trained on watermarked data',
'fix': 'Use a different model checkpoint or use an inpainting pass to remove'
}
}
for failure, info in negative_prompt_limitations.items():
print(f'{failure}')
print(f' Problem: {info["problem"]}')
print(f' Fix: {info["fix"]}')
print()การทดสอบประสิทธิผลของพรอมต์เชิงลบ
ทดสอบอย่างเป็นระบบว่าพรอมต์เชิงลบใดช่วยปรับปรุงผลลัพธ์สำหรับกรณีการใช้งานเฉพาะของคุณได้จริง generate โดยมีและไม่มีพรอมต์เชิงลบ แล้วเปรียบเทียบผลลัพธ์โดยใช้ค่าเริ่มต้นแบบเดียวกัน
import requests
SD_API_URL = 'http://localhost:7860/sdapi/v1/txt2img'
def test_negative_prompts(positive, negative_variants, seed=42, steps=30):
results = []
for label, negative in negative_variants.items():
payload = {
'prompt': positive,
'negative_prompt': negative,
'seed': seed, # fixed seed for fair comparison
'steps': steps,
'cfg_scale': 7
}
response = requests.post(SD_API_URL, json=payload)
results.append({
'label': label,
'negative': negative[:60] + '...',
'image_count': len(response.json().get('images', []))
})
return results
# Test different negative prompt levels
variants = {
'no_negative': '',
'quality_only': 'blurry, low quality, watermark',
'anatomy_added': 'blurry, low quality, watermark, extra fingers, bad anatomy',
'full_library': compose_negative('quality_base', 'anatomy', 'portrait_specific')
}
print('Testing negative prompt variants with fixed seed...')
print('Compare output images to identify which negative terms have the most impact.')พารามิเตอร์ไม่ใช้ของ Midjourney
Midjourney ใช้พารามิเตอร์ --no เป็นสิ่งเทียบเท่ากับพรอมต์เชิงลบ ไวยากรณ์แตกต่างกัน แต่แนวคิดเหมือนกันทุกประการ: ให้ต่อท้ายพรอมต์ด้วย --no [term1] [term2]
# Midjourney negative prompt syntax using --no parameter
midjourney_prompts = [
# Basic exclusion
'professional headshot portrait, soft studio lighting, --no text watermark logo background',
# Style exclusion
'oil painting of a medieval castle, dramatic lighting --no modern cars people telephone wires',
# Anatomy
'full body character art, hero pose --no extra fingers deformed limbs bad anatomy',
# Content exclusion
'children\'s book illustration of a forest --no violence scary dark horror'
]
# Midjourney also supports emphasis with :: weighting
weighted_midjourney = (
'A serene Japanese garden::2, cherry blossoms::1.5, '
'koi pond, stone lantern --no people tourists modern buildings::3'
# ::2 = 2x weight on the garden
# ::3 on the no-people exclusion = very strong exclusion
)
for prompt in midjourney_prompts[:3]:
print('Midjourney:', prompt[:70], '...')ตรวจสอบความเข้าใจ
เทคนิคใดของ Stable Diffusion ที่เพิ่มอิทธิพลของคำศัพท์เชิงลบคำหนึ่งให้มากกว่าคำอื่น ๆ
สรุปพรอมต์เชิงลบ
พรอมต์เชิงลบเป็นเครื่องมือทรงพลังสำหรับชี้นำการสร้างภาพให้ห่างจากคุณลักษณะที่ไม่ต้องการ:
- Stable Diffusion: ใช้พารามิเตอร์
negative_promptแยกต่างหาก และรองรับการกำหนดน้ำหนักด้วยวงเล็บ - DALL-E 3: ใช้ 'avoid', 'without' และ 'do not include' ในพรอมต์เชิงบวก
- Midjourney: ต่อท้ายพรอมต์ด้วย
--no [terms] - คำเชิงลบสากล: เบลอ คุณภาพต่ำ ลายน้ำ ข้อความ นิ้วเกิน
- มาตราส่วน CFG: ควบคุมว่าพรอมต์เชิงบวกและเชิงลบจะชี้นำการ generate อย่างเข้มข้นเพียงใด
- ข้อจำกัด: ลดความน่าจะเป็นได้ แต่ไม่รับประกันการตัดออก และควรใช้ไม่เกิน 15–20 คำ
เรียนรู้ AI Prompt Engineering ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 53
- บทเรียน
- 199
คำถามที่พบบ่อย
บทเรียน “พรอมต์เชิงลบและสิ่งที่ต้องยกเว้น” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “พรอมต์เชิงลบและสิ่งที่ต้องยกเว้น” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Prompt Engineering ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “พรอมต์เชิงลบและสิ่งที่ต้องยกเว้น”
สิ่งที่ต้องยกเว้น: ภาพเบลอ ลายน้ำ ภาพน่าเกลียด ภาพผิดรูป — การเขียนพรอมต์เชิงลบอย่างมีประสิทธิภาพ คุณปฏิบัติ AI Prompt Engineering ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Prompt Engineering หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Prompt Engineering บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “พรอมต์เชิงลบและสิ่งที่ต้องยกเว้น” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน AI Prompt Engineering นี้ได้ไหม
ได้ บทเรียน AI Prompt Engineering ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- องค์ประกอบของพรอมต์สร้างภาพ
- การระบุรูปแบบและสื่อศิลป์
- พรอมต์เชิงลบและสิ่งที่ต้องยกเว้น
- การปรับปรุงพรอมต์สร้างภาพแบบวนซ้ำ