Views
No views yet
models/finetuned_paddle/ 和 models/sd2.1_base_paddle/,这些是转换为PaddlePaddle格式的模型文件(.pdparams),可直接在PaddlePaddle框架中使用。1# Python版本
2Python >= 3.9
3
4# 核心依赖
5paddlepaddle-gpu >= 2.6.0 # GPU版本 (推荐)
6# 或
7paddlepaddle >= 2.6.0 # CPU版本
8
9# 其他依赖
10pip install Pillow opencv-python numpy1import paddle
2from PIL import Image
3import numpy as np
4
5# 这里是简化的示例,完整代码请参考GitHub仓库
6# https://github.com/WangchukMind/thangka-restoration-ai
7
8# 加载模型 (伪代码 - 实际使用请参考完整系统)
9from diffusion_paddle import load_model, load_lora, inpaint
10
11# 加载基础模型
12pipe = load_model(
13 model_path="models/sd2.1_base_paddle",
14 device="gpu" # 或 "cpu"
15)
16
17# 加载LoRA模型
18load_lora(pipe, "models/finetuned/thangka_21_Status_140.safetensors")
19
20# 加载待修复图像
21image = Image.open("damaged_thangka.png").resize((512, 512))
22mask = Image.open("damage_mask.png").resize((512, 512))
23
24# 执行修复
25result = inpaint(
26 pipe=pipe,
27 image=image,
28 mask=mask,
29 prompt="traditional thangka art, Buddha, detailed, vibrant colors, gold outlines",
30 negative_prompt="low quality, blurry, distorted, modern style",
31 num_inference_steps=30,
32 guidance_scale=7.5,
33 strength=0.8
34)
35
36# 保存结果
37result.save("restored_thangka.png")1# 加载ControlNet
2from diffusion_paddle import load_controlnet
3
4controlnet = load_controlnet("models/control_v11p_sd21_canny_paddle")
5
6# 提取边缘
7from skimage.feature import canny
8edges = canny(np.array(image.convert('L')), sigma=1)
9edge_image = Image.fromarray((edges * 255).astype(np.uint8))
10
11# 使用ControlNet修复
12result = inpaint_with_control(
13 pipe=pipe,
14 image=image,
15 mask=mask,
16 control_image=edge_image,
17 controlnet=controlnet,
18 prompt="traditional thangka art, detailed restoration",
19 num_inference_steps=30
20)1# 克隆完整系统
2git clone https://github.com/WangchukMind/thangka-restoration-ai.git
3cd thangka-restoration-ai
4
5# 安装依赖
6cd Django
7pip install -r requirements_paddle.txt
8
9# 下载模型文件
10# 模型文件较大,请从以下地址下载:
11# Hugging Face: https://huggingface.co/Wangchuk1376/ThangkaModels
12# 或参考 MODEL_DOWNLOAD.md
13
14# 启动系统
15python start_server.py runserver
16
17# 或使用MVP简化版本
18cd ..
19python start_mvp_product.pyhttp://localhost:3000 使用Web界面。