如何写出“魔法Spec”:Ming-Image-0.1-Design-Layer图层分解规格编写技巧清单(海报/招牌/UI实例)
如何写出“魔法Spec”:Ming-Image-0.1-Design-Layer图层分解规格编写技巧清单(海报/招牌/UI实例)
Ming-Image-0.1-Design-Layer 是一个跑在 Apple Silicon 上的图层分解模型,能把一张扁平设计稿(海报、招牌、卡片、UI)自动拆成可编辑的 RGBA 图层。而决定拆分质量的关键,就是你调用时传入的 Spec(图层规格)。本文整理了一份面向新手的 Spec 编写技巧清单,附带海报、招牌、UI 三类实例,帮你写出“魔法级”的图层分解指令。
图层分解是什么:一张设计稿拆成可编辑 RGBA 图层
先花一分钟看懂这个模型能做什么:
- 输入一张扁平设计图,输出 N 个独立 RGBA 图层,文字、Logo、角色、物体各自独立成层;
- 图层顺序是从最上层往下(front-most first),返回结果中
layers[0]就是最顶层; - 背景层会自动填补被遮挡的区域,不会留下破洞;
- 模型还会额外输出一张重新合成的画面,方便直接校验拆分是否正确。
💡 想了解仓库全貌,先读 README.md;各组件目录(
mllm/、connector/、mlp/、transformer/、vae/)里都有对应的 config.json 说明。
魔法 Spec 基础格式:一行模板就能跑通
模型读取的是一份“逐层规格”,标准格式如下(直接来自 README.md):
Decompose this image into 4 layers with the following specifications:
Number of layers: 4
Layer 1: Centered dark-navy bold sans-serif headline text in the upper middle.
Layer 2: Bright blue cloud-shaped logo badge at the top center.
Layer 3: Cartoon squirrel character standing in the lower left.
Layer 4: Light sky-blue background with clouds, green hills and flowers.
不写 Spec 时,一句 Decompose this image into N layers. 也能跑通;但精确的 Spec 能显著更好地分离文字与物体——这就是“魔法”的来源。
Spec 编写技巧清单:7 条从及格到魔法的写法
技巧 1:先数清层数,且层数 ≤ 12
开头的 Number of layers: N 是整份规格的“总纲”。建议按肉眼可区分的元素估算,不要贪多;在 MLXEngine 下请求上限就是 12 层,超过会被直接拒绝。
技巧 2:每层写足“位置 + 外观 + 内容”三要素
拆解上面的示例,每条 Layer 描述都包含:
| 要素 | 示例 |
|---|---|
| 位置 | in the upper middle / at the top center / in the lower left |
| 外观 | dark-navy bold sans-serif / bright blue cloud-shaped |
| 内容 | headline text / logo badge / cartoon squirrel character |
三要素齐了,模型才知道“切哪里、切出什么”。
技巧 3:按“从最上到最下”的顺序编号
图层顺序 = 视觉上的遮挡顺序:被遮挡的先写,遮挡别人的后写。顺序写反,文字和背景可能会“抢层”。
技巧 4:背景层永远放最后
最后一层写背景(天空、底纹、渐变),模型会把被前景盖住的区域自动补全。背景描述尽量点出主色调和主要元素,例如 Light sky-blue background with clouds, green hills and flowers.
技巧 5:文本层写清“字体气质”
bold sans-serif、headline text 这类描述能帮模型把文字从装饰元素里剥离出来。不确定细节时,至少写清文字的大致位置和用途(标题 / 副标题 / 按钮文案)。
技巧 6:颜色、形状描述要具体
Bright blue cloud-shaped logo badge 比一句 a logo 有效得多。颜色给主色,形状给轮廓(云朵、盾牌、圆角矩形……),物体给姿态(standing / flying)。
技巧 7:拿不准就“降级”,但别裸奔
实在描述不清,退一步只给层数:Decompose this image into 4 layers.——能出图,但文字与物体的分离度会打折扣。建议先用降级 Spec 跑一遍看结果,再针对性补描述迭代精修。
实例示范:海报 / 招牌 / UI 三类 Spec 怎么写
海报实例(官方示例)
一张“小松鼠海报”,四个视觉元素正好对应四层:
Decompose this image into 4 layers with the following specifications:
Number of layers: 4
Layer 1: Centered dark-navy bold sans-serif headline text in the upper middle.
Layer 2: Bright blue cloud-shaped logo badge at the top center.
Layer 3: Cartoon squirrel character standing in the lower left.
Layer 4: Light sky-blue background with clouds, green hills and flowers.
拆分结果:标题文字、Logo 徽章、松鼠角色各自独立成层,背景的云与草坡完整补全。
招牌实例
街边门店招牌通常是“品牌名 + 图形 + 底色”的三层结构:
Decompose this image into 3 layers with the following specifications:
Number of layers: 3
Layer 1: White bold store name text in the center.
Layer 2: Red circular brand icon to the left of the text.
Layer 3: Dark wood-grain background panel filling the whole frame.
📌 招牌图多为横向构图,模型输出会保持输入的宽高比(按 512 / 1024 档位缩放),横图不用手动裁切。
UI 实例
App 卡片或界面截图元素细碎,建议按“文案 → 控件 → 主体 → 卡片 → 底版”逐层点名:
Decompose this image into 5 layers with the following specifications:
Number of layers: 5
Layer 1: Small grey caption text at the bottom of the card.
Layer 2: Rounded green 'Buy' button on the lower right.
Layer 3: Product photo with soft shadow in the upper half.
Layer 4: White card panel with rounded corners.
Layer 5: Light-grey gradient background behind the card.
Spec 传给模型:Swift 调用速览
Spec 本质就是一个字符串,在 Swift / MLX 移植版中通过 LayerDecomposeRequest 传入:
let response = try await package.run(LayerDecomposeRequest(
image: Image(format: .png, data: try Data(contentsOf: designURL)),
spec: spec, // 上面写好的规格字符串;或只传 layerCount
resolution: 1024)) as! LayerDecomposeResponse
// response.layers[0] 是最上层;response.composite 是模型重新合成的画面
🔧 工程细节:多帧输出(每层一帧 + 合成帧)由 transformer/config.json 中的 multi_frame_output: true 驱动;RGBA 编码由 vae/config.json 的 RGBA VAE 完成(input_channels: 4)。
硬件与速度参考:你的 Mac 跑图层分解够不够?
| 项目 | 数据 |
|---|---|
| 加载后常驻内存 | 13.2 GB |
| 峰值内存(1024 档,4–12 层) | 50.1–50.4 GB |
| bf16 版(MLXEngine)建议配置 | 96 GB Mac |
| 48 GB Mac | 换 8-bit 量化版(约 28.3 GB) |
| 36 GB Mac | 换 4-bit 量化版(约 20.5 GB) |
| 速度(M5 Max 实测) | 4 层 @ 512 档约 131 秒;1024 档约 11 分钟 |
📊 量化版与 bf16 的视觉差距极小(8-bit 在 0.1 dB 内、4-bit 在 0.2 dB 内),内存紧张时放心降级。
提交前自检:Spec 质量检查清单
- [ ] 开头声明了
Number of layers: N,且 N ≤ 12 - [ ] 每层都写足了“位置 + 外观 + 内容”三要素
- [ ] 顺序从最上层(被遮挡的)写到最下层
- [ ] 背景层放在最后,并点出主色调与主要元素
- [ ] 文字层写清了位置与字体气质
- [ ] 颜色、形状描述具体,没有“一个标志”式空话
- [ ] 先用降级 Spec 跑一遍,再迭代精修
Spec 写得像给同事交接设计稿一样清楚,图层分解的干净程度就会超出预期。把上面的清单贴在工位旁,下次写 Spec 时逐条对照——你会发现“魔法”其实是结构化的描述习惯。