
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
!https://raw.githubusercontent.com/dusty-nv/jetson-containers/docs/docs/images/diffusion_astronaut.jpg
本Docker镜像基于Stable Diffusion实现,支持通过文本生成图像(txt2img)或通过图像生成图像(img2img)。集成了CompVis的stable-diffusion代码(/opt/stable-diffusion)和basujindal的内存优化版本(/opt/stable-diffusion/optimizedSD),已在stable-diffusion-1.4模型上测试通过。适用于Jetson设备,提供命令行方式的图像生成功能。
如需带Web界面的更快实现,可参考https://github.com/dusty-nv/jetson-containers/tree/master/packages/diffusion/stable-diffusion-webui%E5%AE%B9%E5%99%A8%E3%80%82
stable-diffusion-1.4模型(可从Hugging Face获取)L4T >=34.1.0,即JetPack 5.1+)适用于在Jetson嵌入式设备上进行AI图像生成的场景,包括:
1. 下载模型
首先下载stable-diffusion-1.4模型文件(sd-v1-4.ckpt):
bashwget https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt -O /data/models/stable-diffusion/sd-v1-4.ckpt
2. 基础生成命令
默认生成6张512x512图像,使用50步优化:
bashcd /opt/stable-diffusion && python3 scripts/txt2img.py --plms \ --ckpt /data/models/stable-diffusion/sd-v1-4.ckpt \ --outdir /data/images/stable-diffusion \ --prompt "a photograph of an astronaut riding a horse"
3. 自定义参数生成
生成1张512x512图像,使用25步优化:
bashcd /opt/stable-diffusion && python3 scripts/txt2img.py --plms \ --n_samples 1 --n_iter 1 --ddim_steps 25 \ --ckpt /data/models/stable-diffusion/sd-v1-4.ckpt \ --outdir /data/images/stable-diffusion \ --prompt "two robots walking in the woods"
主要参数说明:
--W/--H:图像宽度/高度(默认512x512)--seed:随机种子(默认42,不同种子生成不同结果)--n_samples:每轮生成图像数量--n_iter:生成轮数--ddim_steps:优化步数(影响质量和速度)4. 低内存设备优化(Jetson Orin Nano)
使用内存优化版本脚本:
bashcd /opt/stable-diffusion && python3 optimizedSD/optimized_txt2img.py \ --sampler plms --seed 42 \ --n_samples 1 --n_iter 1 --ddim_steps 25 \ --ckpt /data/models/stable-diffusion/sd-v1-4.ckpt \ --outdir /data/images/stable-diffusion \ --prompt "a photograph of an astronaut riding a horse"
5. 脚本化运行
完整流程可通过脚本执行:https://github.com/dusty-nv/jetson-containers/tree/master/packages/diffusion/stable-diffusion/test.sh
stable-diffusion | |
|---|---|
| 构建状态 | |
| 系统要求 | L4T ['>=34.1.0'](JetPack 5.1+) |
| 依赖项 | https://github.com/dusty-nv/jetson-containers/tree/master/packages/build/build-essential%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/cuda/cuda%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/cuda/cudnn%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/build/python%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/numpy%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/build/cmake/cmake_pip%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/onnx%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/pytorch%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/pytorch/torchvision%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/llm/huggingface_hub%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/build/rust%E3%80%81https://github.com/dusty-nv/jetson-containers/tree/master/packages/llm/transformers |
| 依赖容器 | https://github.com/dusty-nv/jetson-containers/tree/master/packages/l4t/l4t-diffusion |
| Dockerfile | https://github.com/dusty-nv/jetson-containers/tree/master/packages/diffusion/stable-diffusion/Dockerfile |
| 镜像标签 | https://hub.docker.com/r/dustynv/stable-diffusion/tags (2023-12-14, 6.1GB)https://hub.docker.com/r/dustynv/stable-diffusion/tags (2023-12-12, 6.1GB)https://hub.docker.com/r/dustynv/stable-diffusion/tags (2023-12-15, 6.1GB) |
| 注意事项 | JetPack 4上不支持 |
| 仓库/标签 | 日期 | 架构 | 大小 |
|---|---|---|---|
| https://hub.docker.com/r/dustynv/stable-diffusion/tags | 2023-12-14 | arm64 | 6.1GB |
| https://hub.docker.com/r/dustynv/stable-diffusion/tags | 2023-12-12 | arm64 | 6.1GB |
| https://hub.docker.com/r/dustynv/stable-diffusion/tags | 2023-12-15 | arm64 | 6.1GB |
容器镜像与其他次要版本的JetPack/L4T兼容:
• L4T R32.7容器可在其他L4T R32.7版本(JetPack 4.6+)上运行
• L4T R35.x容器可在其他L4T R35.x版本(JetPack 5.1+)上运行
可使用https://github.com/dusty-nv/jetson-containers/tree/master/docs/run.md%E5%92%8Chttps://github.com/dusty-nv/jetson-containers/tree/master/docs/run.md#autotag%E5%90%AF%E5%8A%A8%E5%AE%B9%E5%99%A8%EF%BC%8C%E6%88%96%E6%89%8B%E5%8A%A8%E6%9E%84%E9%80%A0%60docker run`命令:
bash# 自动拉取或构建兼容的容器镜像 jetson-containers run $(autotag stable-diffusion) # 或显式指定上述镜像之一 jetson-containers run dustynv/stable-diffusion:r35.4.1 # 或使用'docker run'(指定镜像和挂载等) sudo docker run --runtime nvidia -it --rm --network=host dustynv/stable-diffusion:r35.4.1
https://github.com/dusty-nv/jetson-containers/tree/master/docs/run.md 将参数转发给
docker run,并添加一些默认值(如--runtime nvidia、挂载/data缓存、检测设备)
https://github.com/dusty-nv/jetson-containers/tree/master/docs/run.md#autotag 查找与JetPack/L4T版本兼容的容器镜像——本地镜像、从仓库拉取或构建镜像。
使用-v或--volume标志将本地目录挂载到容器中:
bashjetson-containers run -v /本地路径:/容器内路径 $(autotag stable-diffusion)
bashjetson-containers run $(autotag stable-diffusion) my_app --abc xyz
可传递任何docker run支持的选项,执行前会打印完整命令。
如果使用上述https://github.com/dusty-nv/jetson-containers/tree/master/docs/run.md#autotag%EF%BC%8C%E9%9C%80%E8%A6%81%E6%97%B6%E4%BC%9A%E8%87%AA%E5%8A%A8%E6%9E%84%E5%BB%BA%E5%AE%B9%E5%99%A8%E3%80%82%E8%A6%81%E6%89%8B%E5%8A%A8%E6%9E%84%E5%BB%BA%EF%BC%8C%E5%85%88%E5%AE%8C%E6%88%90https://github.com/dusty-nv/jetson-containers/tree/master/docs/setup.md%EF%BC%8C%E7%84%B6%E5%90%8E%E8%BF%90%E8%A1%8C%EF%BC%9A
bashjetson-containers build stable-diffusion
构建过程中会集成上述依赖项并进行测试。使用https://github.com/dusty-nv/jetson-containers/tree/master/jetson_containers/build.py%E6%9F%A5%E7%9C%8B%E6%9E%84%E5%BB%BA%E9%80%89%E9%A1%B9%E3%80%82
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务