Views
No views yet
1import torch
2from diffusers import FluxPipeline
3
4# 1. 设置模型路径和 LoRA 路径
5base_model_id = "black-forest-labs/FLUX.1-dev"
6# 修改为您实际的 LoRA 文件路径
7lora_path = "output/oxford_tree_style_v1/oxford_tree_style_v1_000001750.safetensors"
8# 触发词
9trigger_word = "oxford style"
10
11# 2. 加载基础模型
12print("正在加载基础模型...")
13pipe = FluxPipeline.from_pretrained(
14 base_model_id,
15 torch_dtype=torch.bfloat16
16)
17# 如果您的显存只有 24G,这一步会自动把模型分配到 CPU 和 GPU,可能有点慢
18pipe.enable_model_cpu_offload()
19
20# 3. 加载您训练好的 LoRA
21print(f"正在加载 LoRA: {lora_path}")
22pipe.load_lora_weights(lora_path)
23
24# 4. 生成图片
25prompt = f"{trigger_word}, a cute rabbit reading a book under a big tree, watercolor texture"
26print(f"正在生成: {prompt}")
27
28image = pipe(
29 prompt,
30 height=1024,
31 width=1024,
32 guidance_scale=3.5,
33 num_inference_steps=20,
34 generator=torch.Generator("cuda").manual_seed(42)
35).images[0]
36
37# 5. 保存图片
38output_file = "test_oxford_1750.png"
39image.save(output_file)
40print(f"图片已保存为: {output_file}")
41oxford style to trigger the image generation.