关键词:多模态图像生成 / 电商主图批量生成 / Prompt 工程 / 图像质检 / 自动化流水线 / PIL 尺寸校验 / VLM 判分 / 图像编辑一致性
摘要
本文给出一套把"人工改图"改造成"模板化 + 批量 + 双闸质检"的工程方案,覆盖 Prompt 结构化、尺寸/场景矩阵生成、规则与模型双重质检、限流重试四个环节。适用于 SKU 多、场景矩阵固定的电商团队。文中给出可直接运行的核心代码与实测口径。
一、背景:为什么要流水线化
电商主图生产的两个老问题:
- 改图返工重:单张主图平均改 3 版以上,主要卡在换背景、改比例、替换产品。
- 一致性差:同 SKU 的不同尺寸/场景图风格漂移。
2026-09 新版多模态图像模型在多轮编辑一致性 与生成延迟上提升明显(官方口径延迟最多降 50%),使批量流水线第一次在工程上划算。
二、技术方案
2.1 Prompt 结构化
自然语言描述方差大,无法批量。改成字段模板:
python
PROMPT_TEMPLATE = (
"subject: {subject}; background: {background}; lighting: {lighting}; "
"mood: {mood}; aspect_ratio: {ratio}; "
"style: e-commerce product photo, clean, no text, no watermark"
)
def build_prompt(subject, background, lighting, mood, ratio):
return PROMPT_TEMPLATE.format(
subject=subject, background=background,
lighting=lighting, mood=mood, ratio=ratio)
2.2 尺寸/场景矩阵
python
from itertools import product
RATIOS = ["1:1", "4:5", "9:16"]
SCENES = [
("white studio", "softbox", "clean"),
("marble desk", "window light", "premium"),
("outdoor lawn", "natural", "fresh"),
("kitchen counter", "warm lamp", "cozy"),
]
def gen_matrix(subject):
return [build_prompt(subject, bg, light, mood, ratio)
for (bg, light, mood), ratio in product(SCENES, RATIOS)]
2.3 双闸质检
python
from PIL import Image
def quality_gate(img_path, expect_ratio, min_width=800):
with Image.open(img_path) as im:
w, h = im.size
# 闸1:硬规则
if abs(w / h - expect_ratio) > 0.02:
return False, "ratio_mismatch"
if w < min_width:
return False, "resolution_too_low"
# 闸2:VLM 判分(主体完整度 + 文字/水印残留)
score = vlm_score(img_path)
if score < 0.8:
return False, "content_score_low"
return True, "ok"
2.4 限流与重试
python
import time
from concurrent.futures import ThreadPoolExecutor
def run_batch(tasks, max_workers=4, max_retry=2):
results = {}
def worker(p):
for i in range(max_retry + 1):
try:
results[p] = generate_image(p)
return
except Exception:
time.sleep(1.5 * (i + 1))
results[p] = None
with ThreadPoolExecutor(max_workers=max_workers) as ex:
list(ex.map(worker, tasks))
return results
三、实测数据
在 200 张主图任务上的对比(单项目口径,样本有限):
| 指标 | 人工流程 | 流水线 |
|---|---|---|
| 单图平均耗时 | ~8 min | ~1 min |
| 一次通过率 | --- | ~72% |
| 返工轮次 | 3+ | 1 |
| 尺寸矩阵覆盖 | 部分 | 100% |
四、踩坑记录
aspect_ratio必须写进 prompt,靠后处理裁剪会丢构图。- 多轮编辑固定同一 seed / 参考图,否则"改背景"会连主体一起改。
- 质检闸2 的 VLM 判分需留人工复核,主观项易误杀。
- 并发过高接口抖动,限流 + 退避重试是刚需。
五、适用边界
- 适合:SKU 多、场景矩阵固定、要求风格一致的团队。
- 不适合:单次出图量少、审美高度依赖资深设计师的场景。
六、总结
这一轮模型升级的工程价值是"可批量 + 可连续编辑"。把 Prompt 结构化、矩阵生成、双闸质检、限流重试四件事接起来,人工改图的返工就被压下去了。难点不在代码,在把质检标准写清楚。