Skip to content

Commit f9f13ed

Browse files
committed
* [maixcam2] optimize projects
1 parent f31def8 commit f9f13ed

File tree

22 files changed

+460
-1900
lines changed

22 files changed

+460
-1900
lines changed
13.9 KB
Loading
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
title: Running the LCM-LoRA-SDv1-5 Model on MaixPy MaixCAM
3+
update:
4+
- date: 2025-12-03
5+
author: lxowalle
6+
version: 1.0.0
7+
content: Added LCM-LoRA-SDv1-5 code and documentation
8+
---
9+
10+
## Supported Devices
11+
12+
| Device | Supported |
13+
| -------- | ------- |
14+
| MaixCAM2 ||
15+
| MaixCAM ||
16+
17+
18+
## Introduction to the LCM-LoRA-SDv1-5 Model
19+
20+
LCM-LoRA-SDv1-5 is a model that supports text-to-image and image-to-image generation, based on the StableDiffusion 1.5 LCM project. With this model, you can generate conceptual images for artistic creation—simply provide a text description, and the model will generate an image based on it.
21+
22+
## Running the LCM-LoRA-SDv1-5 Model on MaixPy MaixCAM
23+
24+
### Model and Download Link
25+
26+
If the `LCM-LoRA-SDv1-5` model is not present in the system directory `/root/models` by default, you need to download it manually.
27+
28+
* Memory requirement: CMM memory 1 GiB. For details, refer to the [Memory Usage Documentation](../pro/memory.md)
29+
30+
* Download link: https://huggingface.co/sipeed/lcm-lora-sdv1-5-maixcam2
31+
32+
For the download method, refer to the instructions in the [Qwen documentation](../pro/memory.md)
33+
34+
### Running the Model with MaixPy
35+
36+
> Note: MaixPy version `4.12.3` or above is required for support.
37+
38+
This example demonstrates how to use MaixPy to run the LCM-LoRA-SDv1-5 model for both text-to-image and image-to-image generation.
39+
40+
```python
41+
from maix import sdv1_5
42+
43+
model = sdv1_5.SDV1_5("/root/models/lcm-lora-sdv1-5-maixcam2/ax620e_models")
44+
model.init(img2img=True)
45+
model.refer(prompt="A white dog.", save_path="/root/text2img.jpg")
46+
model.refer(prompt="Replace the dog with a cat.", init_image_path="/root/text2img.jpg", seed=1, save_path="/root/img2img.jpg")
47+
48+
model.deinit()
49+
```
50+
Output:
51+
![](../../assets/ldm_sdv1.5_img2img.jpg)
52+
53+
Explanation:
54+
1. When performing text-to-image generation, you need to define a `prompt` describing the image you want. The prompt must be written in English, and the generated image will be saved to the path specified by `save_path`.
55+
2. When performing image-to-image generation, you need to define a prompt describing the content you want to generate`init_image_path` specifies the initial image,`seed` controls randomness in image generation
56+
The output image will be saved to the path specified by save_path.
57+
3. Since `sdv1_5` depends on several large Python packages, importing it may take some time. If you want the application to enter the UI quickly during development, you can use `importlib` and `threading` to load the module in the background. Example:
58+
```python
59+
from maix import time
60+
import importlib, threading
61+
62+
class ModuleLoader():
63+
def __load_module(self):
64+
self.module = importlib.import_module(self.module_name)
65+
self.load_ok = True
66+
pass
67+
def __init__(self, module_name: str):
68+
self.module_name = module_name
69+
self.module = None
70+
self.load_ok = False
71+
self.t = threading.Thread(target=self.__load_module)
72+
self.t.start()
73+
def try_get_module(self, block = True):
74+
if self.load_ok:
75+
return self.module
76+
if block:
77+
while not self.load_ok:
78+
time.sleep_ms(100)
79+
return self.module
80+
else:
81+
return None
82+
83+
sdv1_5_loader = ModuleLoader("maix.sdv1_5")
84+
while True:
85+
sdv1_5 = sdv1_5_loader.try_get_module(block=False)
86+
if sdv1_5 is not None:
87+
break
88+
time.sleep_ms(1000)
89+
print(sdv1_5)
90+
```
91+
92+
### Running the Model with Command Line
93+
94+
Refer to `launcher.py` in the model directory to run the model.
95+
96+
#### Text-to-Image
97+
```shell
98+
cd lcm-lora-sdv1-5-maixcam2
99+
python3 launcher.py --isize 256 --model_dir ax620e_models/ -o "ax620e_txt2img_axe.png" --prompt "a white dog"
100+
```
101+
102+
Parameter description:
103+
- `--isize`: Input image size, recommended value is 256
104+
- `--model_dir`: Model directory
105+
- `-o`: Output image filename
106+
- `--prompt`: Description text; the model generates an image based on this description
107+
108+
#### Image-to-Image
109+
```shell
110+
cd lcm-lora-sdv1-5-maixcam2
111+
python3 launcher.py --init_image ax620e_models/img2img-init.png --isize 256 --model_dir ax620e_models/ --seed 1 --prompt "Change to black clothes" -o "ax620e_img2img_axe.png"
112+
```
113+
114+
Parameter description:
115+
- `--init_image`: Initial image; the model generates a new image based on this
116+
- `--isize`: Input image size, recommended value is 256
117+
- `--model_dir`: Model directory
118+
- `--seed`: Random seed, controls randomness during image generation
119+
- `-o`: Output image filename
120+
- `--prompt`: Description text; the model generates an image based on this description
121+
122+

docs/doc/en/mllm/lm_lora_sdv1_5.md

Lines changed: 0 additions & 64 deletions
This file was deleted.

docs/doc/en/sidebar.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ items:
124124
label: InternVL Vision-Language Model
125125
- file: mllm/vlm_qwen3.md
126126
label: Qwen3-VL Vision-Language Model
127-
- file: mllm/lm_lora_sdv1_5.md
128-
label: LCM-LoRA-SDv1-5 Model
127+
- file: mllm/dlm_lora_sdv1_5.md
128+
label: LCM-LoRA-SDv1-5 Image-Generation Model
129129
- file: mllm/vlm_smolvlm.md
130130
label: SmolVLM Vision-Language Model
131131

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
title: MaixPy MaixCAM 运行 LCM-LoRA-SDv1-5 模型
3+
update:
4+
- date: 2025-12-03
5+
author: lxowalle
6+
version: 1.0.0
7+
content: 新增 LCM-LoRA-SDv1-5 代码和文档
8+
---
9+
10+
## 支持的设备
11+
12+
| 设备 | 是否支持 |
13+
| -------- | ------- |
14+
| MaixCAM2 ||
15+
| MaixCAM ||
16+
17+
18+
## LCM-LoRA-SDv1-5 模型简介
19+
20+
LCM-LoRA-SDv1-5 是一个支持文生图, 图生图的模型, 基于 StableDiffusion 1.5 LCM 项目. 我们可以通过这个模型来生成艺术创作的概念图, 只需要输入一段图片的描述文字, 模型便可以基于描述生成一张图片.
21+
22+
## 在 MaixPy MaixCAM 运行 LCM-LoRA-SDv1-5 模型
23+
24+
### 模型和下载地址
25+
26+
默认系统`/root/models`目录下如果没有`LCM-LoRA-SDv1-5`模型,需要自行下载。
27+
28+
* 内存需求:CMM 内存 1GiB,内存解释请看[内存使用文档](../pro/memory.md)
29+
* 下载地址:https://huggingface.co/sipeed/lcm-lora-sdv1-5-maixcam2
30+
31+
下载方法参考[Qwen 文档](./llm_qwen.md) 里面的下载方法。
32+
33+
### MaixPy 运行模型
34+
35+
> 注意:必须要`MaixPy 4.12.3`以上版本才支持
36+
37+
这里的示例展示了如何使用 MaixPy 运行 LCM-LoRA-SDv1-5 模型来实现文生文和图生图的功能
38+
39+
```python
40+
from maix import sdv1_5
41+
42+
model = sdv1_5.SDV1_5("/root/models/lcm-lora-sdv1-5-maixcam2/ax620e_models")
43+
model.init(img2img=True)
44+
model.refer(prompt="A white dog.", save_path="/root/text2img.jpg")
45+
model.refer(prompt="Replace the dog with a cat.", init_image_path="/root/text2img.jpg", seed=1, save_path="/root/img2img.jpg")
46+
47+
model.deinit()
48+
```
49+
输出:
50+
![](../../assets/ldm_sdv1.5_img2img.jpg)
51+
52+
说明:
53+
1. 执行文生文功能时, 需要定义一个`prompt`, 描述你的图片内容, 必须是英文输入, 生成的图片会保存在`save_path`指定的路径
54+
2. 执行图生图功能时, 需要定义一个`prompt`, 描述你要生成图片的内容, `init_image_path`指定初始图片, `seed`指定图片生成时的随机性, 生成的图片会保存在`save_path`指定的路径
55+
3. 由于`sdv1_5`依赖了一些比较大的python包, 因此在导入时会比较慢, 需要耐心等待. 开发时如果希望快速进入界面, 可以尝试使用`importlib``threading`库将加载模块的过程放到后台执行, 参考代码:
56+
```python
57+
from maix import time
58+
import importlib, threading
59+
60+
class ModuleLoader():
61+
def __load_module(self):
62+
self.module = importlib.import_module(self.module_name)
63+
self.load_ok = True
64+
pass
65+
def __init__(self, module_name: str):
66+
self.module_name = module_name
67+
self.module = None
68+
self.load_ok = False
69+
self.t = threading.Thread(target=self.__load_module)
70+
self.t.start()
71+
def try_get_module(self, block = True):
72+
if self.load_ok:
73+
return self.module
74+
if block:
75+
while not self.load_ok:
76+
time.sleep_ms(100)
77+
return self.module
78+
else:
79+
return None
80+
81+
sdv1_5_loader = ModuleLoader("maix.sdv1_5")
82+
while True:
83+
sdv1_5 = sdv1_5_loader.try_get_module(block=False)
84+
if sdv1_5 is not None:
85+
break
86+
time.sleep_ms(1000)
87+
print(sdv1_5)
88+
```
89+
90+
### 命令行运行模型
91+
92+
请参考模型文件中的`launcher.py`来运行模型.
93+
94+
#### 文生图
95+
```shell
96+
cd lcm-lora-sdv1-5-maixcam2
97+
python3 launcher.py --isize 256 --model_dir ax620e_models/ -o "ax620e_txt2img_axe.png" --prompt "a white dog"
98+
```
99+
100+
参数说明:
101+
- `--isize`: 输入图片的尺寸, 推荐填写256
102+
- `--model_dir`: 模型目录
103+
- `-o`: 输出图片名称
104+
- `--prompt`: 描述文字, 模型基于这里的描述生成图片
105+
106+
#### 图生图
107+
```shell
108+
cd lcm-lora-sdv1-5-maixcam2
109+
python3 launcher.py --init_image ax620e_models/img2img-init.png --isize 256 --model_dir ax620e_models/ --seed 1 --prompt "Change to black clothes" -o "ax620e_img2img_axe.png"
110+
```
111+
112+
参数说明:
113+
- `--init_image`: 初始图片, 模型基于这个图片生成图片
114+
- `--isize`: 输入图片的尺寸, 推荐填写256
115+
- `--model_dir`: 模型目录
116+
- `--seed`: 随机种子, 代表图片生成时的随机性
117+
- `-o`: 输出图片名称
118+
- `--prompt`: 描述文字, 模型基于这里的描述生成图片
119+
120+

docs/doc/zh/mllm/lm_lora_sdv1_5.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

docs/doc/zh/sidebar.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ items:
125125
label: InternVL 视觉语言模型
126126
- file: mllm/vlm_qwen3.md
127127
label: Qwen3-VL 视觉语言模型
128-
- file: mllm/lm_lora_sdv1_5.md
129-
label: LCM-LoRA-SDv1-5 模型
128+
- file: mllm/dlm_lora_sdv1_5.md
129+
label: LCM-LoRA-SDv1-5 图像生成模型
130130
- file: mllm/vlm_smolvlm.md
131131
label: SmolVLM 视觉语言模型
132132

0 commit comments

Comments
 (0)