Multimodal Models
Collection
25 items
•
Updated
•
1
基于 StableDiffusion 1.5 LCM 项目,展示该项目 文生图、图生图 在基于 AX650N 的产品上部署的流程.
支持芯片:
支持硬件
原始模型请参考
| Models | Raspberry Pi5 Only CPU | Intel i7-13700 | Raspberry Pi5 + M.2 Card |
|---|---|---|---|
| UNet(1 step) | 14 s | 1.7 s | 0.43 s |
| VAE Encoder | 25 s | 1.7 s | 0.46 s |
| VAE Decoder | 58 s | 3.8 s | 0.91 s |
| Total txt2img, 4 steps | 120 s | 10.6 s | 2.68 s |
| Total img2img, 2 steps | 113 s | 8.9 s | 2.25 s |
unet.axmodel, vae_encoder.axmodel, vae_decoder 模型拷贝到 ./models 路径下Dreamshaper 7 仓库中的 text_encoder 文件夹拷贝到 ./models 路径下./models 存放了 DEMO 展示的必要模型minicondapip install -r requirements.txt
本次更新, AX650N 支持生成 1024x768 分辨率的图像.
复现命令:
python3 launcher.py --model_dir models_1024x768/ --isize 1024x768 --prompt "(masterpiece, best quality, ultra detailed, 8k, CG unity wallpaper),1 young beautiful girl, full body, official art, extremely detailed, highly detailed, 1 girl, aqua eyes, light smile, grey hair, hair flower,bracelet, choker, ribbon, JK, looking at viewer, on the beach, in summer," --seed 299
python3 launcher.py --model_dir models_1024x768/ --isize 1024x768 --prompt "(masterpiece, best quality, ultra-detailed), photorealistic, 8k resolution,
adult 1girl, front view, (laughing happily), bright sparkling eyes, sweet innocent expression,
head tilted playfully, wind-blown hair flowing wildly, dynamic motion,
detailed skin texture, natural skin pores, sharp focus on eyes" --seed 332
生图总耗时约 30s 左右.
本次更新提供一个统一的模型执行脚本 launcher.py,支持在 AX620E 和 AX650N 芯片上进行文生图 (txt2img) 和图生图 (img2img) 推理任务.
请确保模型文件已放置在正确的目录中:
./modelsax620e_models/文生图任务(256x256 分辨率):
生图总耗时(4 steps): text_encoder 48.7ms + unet 1483.9ms + decoder 739.4ms 约为 2.2s.
python3 launcher.py --isize 256 --model_dir ax620e_models/ -o "ax620e_txt2img_axe.png" --prompt "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"
图生图任务:
生图总耗时(2 steps): text_encoder 48.8ms + vae_encoder 359.1ms + unet 744.8ms + decoder 739.1ms 约为 1.9s.
python3 launcher.py --init_image ax620e_models/img2img-init.png --isize 256 --model_dir ax620e_models/ --seed 1 --prompt "Astronauts in a jungle, cold color palette, muted colors, detailed, 8k" -o "ax620e_img2img_axe.png"
文生图任务(默认 512x512 分辨率):
python3 launcher.py -o "ax650n_txt2img_axe.png" --prompt "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"
图生图任务:
python3 launcher.py --init_image models/img2img-init.png --prompt "Astronauts in a jungle, cold color palette, muted colors, detailed, 8k" -o "ax650n_img2img_axe.png"
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
--backend |
choice | "axe" |
推理后端(axe 或 onnx), 默认 axe |
--prompt |
str | 默认提示词 | 输入文本提示词 |
--model_dir |
str | "./models" |
包含分词器、文本编码器、UNet、VAE 等模型的目录 |
--time_input |
str | None |
可选的时间输入 numpy 文件覆盖 |
--init_image |
str | None |
提供初始图像以启用图生图模式 |
--isize |
int | 512 |
输出图像尺寸, 512 or 256, 默认 512 |
-o, --save_dir |
str | "./output.png" |
生成图像的保存路径 |
--seed |
int | None |
随机种子(图生图模式未指定时默认为 0) |
--init_image 参数启用图生图模式,系统将基于提供的初始图像进行生成.run_txt2img_axe_infer.pyInput Prompt
Self-portrait oil painting, a beautiful cyborg with golden hair, 8k
Output
(sd1_5) axera@raspberrypi:~/samples/sd1.5-lcm.axera $ python run_txt2img_axe_infer.py
[INFO] Available providers: ['AXCLRTExecutionProvider']
prompt: Self-portrait oil painting, a beautiful cyborg with golden hair, 8k
text_tokenizer: ./models/tokenizer
text_encoder: ./models/text_encoder
unet_model: ./models/unet.axmodel
vae_decoder_model: ./models/vae_decoder.axmodel
time_input: ./models/time_input_txt2img.npy
save_dir: ./txt2img_output_axe.png
text encoder take 2891.1ms
[INFO] Using provider: AXCLRTExecutionProvider
[INFO] SOC Name: AX650N
[INFO] VNPU type: VNPUType.DISABLED
[INFO] Compiler version: 3.3 972f38ca
[INFO] Using provider: AXCLRTExecutionProvider
[INFO] SOC Name: AX650N
[INFO] VNPU type: VNPUType.DISABLED
[INFO] Compiler version: 3.3 972f38ca
load models take 26628.9ms
unet once take 437.5ms
unet once take 433.4ms
unet once take 433.6ms
unet once take 433.6ms
unet loop take 1741.2ms
vae inference take 914.8ms
save image take 210.5ms
(sd1_5) axera@raspberrypi:~/samples/sd1.5-lcm.axera $
Output Image
run_txt2img_axe_infer.pyInput Prompt
Astronauts in a jungle, cold color palette, muted colors, detailed, 8k
Input Image
Output
(sd1_5) axera@raspberrypi:~/samples/sd1.5-lcm.axera $ python run_img2img_axe_infer.py
[INFO] Available providers: ['AXCLRTExecutionProvider']
prompt: Astronauts in a jungle, cold color palette, muted colors, detailed, 8k
text_tokenizer: ./models/tokenizer
text_encoder: ./models/text_encoder
unet_model: ./models/unet.axmodel
vae_encoder_model: ./models/vae_encoder.axmodel
vae_decoder_model: ./models/vae_decoder.axmodel
init image: ./models/img2img-init.png
time_input: ./models/time_input_img2img.npy
save_dir: ./img2img_output_axe.png
text encoder take 4494.8ms
[INFO] Using provider: AXCLRTExecutionProvider
[INFO] SOC Name: AX650N
[INFO] VNPU type: VNPUType.DISABLED
[INFO] Compiler version: 3.3-dirty 2ecead35-dirty
[INFO] Using provider: AXCLRTExecutionProvider
[INFO] SOC Name: AX650N
[INFO] VNPU type: VNPUType.DISABLED
[INFO] Compiler version: 3.3 972f38ca
[INFO] Using provider: AXCLRTExecutionProvider
[INFO] SOC Name: AX650N
[INFO] VNPU type: VNPUType.DISABLED
[INFO] Compiler version: 3.3 972f38ca
load models take 27331.3ms
vae encoder inference take 460.4ms
unet once take 433.7ms
unet once take 433.5ms
unet loop take 871.7ms
vae decoder inference take 914.5ms
grid image saved in ./lcm_lora_sdv1-5_imgGrid_output.png
save image take 427.5ms
(sd1_5) axera@raspberrypi:~/samples/sd1.5-lcm.axera $
Output Image
NPU 工具链 Pulsar2 在线文档
Github issues QQ 群: 139953715
Base model
Lykon/dreamshaper-7