File size: 7,255 Bytes
36bf676
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29e00b3
36bf676
 
 
 
 
4d657d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c980846
 
 
 
 
36bf676
 
 
4d657d1
36bf676
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
---
license: mit
language:
- zh
- en
tags:
- thangka
- image-restoration
- stable-diffusion
- lora
- cultural-heritage
- paddlepaddle
- buddhist-art
datasets:
- custom-thangka-1376
metrics:
- psnr
- ssim
pipeline_tag: image-to-image
widget:
- text: "traditional thangka art, Shakyamuni Buddha, detailed painting, vibrant colors, gold outlines"
  example_title: "Buddha Restoration"
- text: "traditional thangka art, Green Tara, 18th century Tibetan style, mineral pigments, masterpiece"
  example_title: "Tara Restoration"
---


<div align="center">

[![GitHub](https://img.shields.io/badge/GitHub-WangchukMind-blue?logo=github)](https://github.com/WangchukMind/thangka-restoration-ai)
[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![PaddlePaddle](https://img.shields.io/badge/PaddlePaddle-2.6.2-orange.svg)](https://paddlepaddle.org.cn)
[![HuggingFace](https://img.shields.io/badge/🤗-Hugging%20Face-yellow)](https://huggingface.co/Wangchuk1376)

**🎨 唐卡修复AI模型 / Thangka Restoration AI Models**

[English](#english-version) | [中文](#chinese-version)

</div>


The Thangka Restoration AI Models are a collection of deep learning models specifically designed for **Tibetan Buddhist Thangka art restoration**. Built upon the latest **Stable Diffusion 2.1** architecture and **LoRA (Low-Rank Adaptation)** fine-tuning technology, these models are meticulously trained on **1376** professionally annotated high-quality Thangka images.

### Why AI for Thangka Restoration?

Thangka, as an important art form of Tibetan Buddhism, carries profound religious and cultural significance, known as the "**Encyclopedia of Tibet**". However:

- 📜 **Fragile Materials**: Cotton, silk, and mineral pigments are easily damaged
-**Historical Age**: Many Thangkas are centuries old
- 💰 **Expensive Restoration**: Traditional manual restoration is costly and time-consuming
- 👨‍🎨 **Expert Scarcity**: Limited number of professional restorers
- ⚠️ **High Risk**: Chemical restoration may cause secondary damage

This project leverages AI technology to provide:
-**Efficient Restoration**: Complete initial restoration in minutes
-**Cultural Accuracy**: >95% cultural feature preservation
-**Cost Reduction**: Significantly lower restoration barriers
-**Non-destructive**: Virtual restoration without damaging originals

### 项目链接
- **完整系统**: [GitHub Repository](https://github.com/WangchukMind/thangka-restoration-ai)
- **模型仓库**: [Hugging Face Models](https://huggingface.co/Wangchuk1376/ThangkaModels)
- **在线演示**: [Demo Site](https://api-ydh5rc33c7a9bbs2.aistudio-app.com/) 
- **技术文档**: [Documentation](https://github.com/WangchukMind/thangka-restoration-ai/wiki)

## <a name="chinese-version"></a>🌟 项目简介

这是一套专门用于藏传佛教唐卡艺术修复的AI模型集合,基于**Stable Diffusion 2.1****LoRA微调技术**,在专业标注的唐卡图像上训练而成。

### 核心特点

-**高效修复**: 基于LoRA技术,快速适应不同风格
-**多种模型**: 提供多个LoRA模型,适应不同修复需求
-**PaddlePaddle**: 完全适配PaddlePaddle深度学习框架

### 开发信息

- **开发者**: Wangchuk Mind
- **机构**: 四川大学计算机学院
- **框架**: PaddlePaddle 2.6.2
- **基础模型**: Stable Diffusion 2.1
- **许可证**: MIT License

---

## 📦 模型列表

### 1. 基础模型

#### Stable Diffusion 2.1 Base (PaddlePaddle版)
- **输入分辨率**: 512×512 (标准), 768×768, 1024×1024

### 2. LoRA微调模型

#### thangka_21_Status_140 ⭐ (推荐)

#### thangka_21_ACD_250

### 3. PaddlePaddle专用模型

位于 `models/finetuned_paddle/``models/sd2.1_base_paddle/`,这些是转换为PaddlePaddle格式的模型文件(`.pdparams`),可直接在PaddlePaddle框架中使用。


## 💻 使用方法

### 环境要求

```bash
# Python版本
Python >= 3.9

# 核心依赖
paddlepaddle-gpu >= 2.6.0  # GPU版本 (推荐)
# 或
paddlepaddle >= 2.6.0      # CPU版本

# 其他依赖
pip install Pillow opencv-python numpy
```

### 快速开始

#### 1. 基础修复示例

```python
import paddle
from PIL import Image
import numpy as np

# 这里是简化的示例,完整代码请参考GitHub仓库
# https://github.com/WangchukMind/thangka-restoration-ai

# 加载模型 (伪代码 - 实际使用请参考完整系统)
from diffusion_paddle import load_model, load_lora, inpaint

# 加载基础模型
pipe = load_model(
    model_path="models/sd2.1_base_paddle",
    device="gpu"  # 或 "cpu"
)

# 加载LoRA模型
load_lora(pipe, "models/finetuned/thangka_21_Status_140.safetensors")

# 加载待修复图像
image = Image.open("damaged_thangka.png").resize((512, 512))
mask = Image.open("damage_mask.png").resize((512, 512))

# 执行修复
result = inpaint(
    pipe=pipe,
    image=image,
    mask=mask,
    prompt="traditional thangka art, Buddha, detailed, vibrant colors, gold outlines",
    negative_prompt="low quality, blurry, distorted, modern style",
    num_inference_steps=30,
    guidance_scale=7.5,
    strength=0.8
)

# 保存结果
result.save("restored_thangka.png")
```

#### 2. 使用ControlNet边缘控制

```python
# 加载ControlNet
from diffusion_paddle import load_controlnet

controlnet = load_controlnet("models/control_v11p_sd21_canny_paddle")

# 提取边缘
from skimage.feature import canny
edges = canny(np.array(image.convert('L')), sigma=1)
edge_image = Image.fromarray((edges * 255).astype(np.uint8))

# 使用ControlNet修复
result = inpaint_with_control(
    pipe=pipe,
    image=image,
    mask=mask,
    control_image=edge_image,
    controlnet=controlnet,
    prompt="traditional thangka art, detailed restoration",
    num_inference_steps=30
)
```

### 完整系统安装

完整的Web应用系统请访问GitHub:

```bash
# 克隆完整系统
git clone https://github.com/WangchukMind/thangka-restoration-ai.git
cd thangka-restoration-ai

# 安装依赖
cd Django
pip install -r requirements_paddle.txt

# 下载模型文件
# 模型文件较大,请从以下地址下载:
# Hugging Face: https://huggingface.co/Wangchuk1376/ThangkaModels
# 或参考 MODEL_DOWNLOAD.md

# 启动系统
python start_server.py runserver

# 或使用MVP简化版本
cd ..
python start_mvp_product.py
```

访问 `http://localhost:3000` 使用Web界面。



### 问题反馈
- **Bug报告**: [GitHub Issues](https://github.com/WangchukMind/thangka-restoration-ai/issues)
- **功能建议**: [GitHub Discussions](https://github.com/WangchukMind/thangka-restoration-ai/discussions)
- **技术交流**: [Discussions](https://huggingface.co/Wangchuk1376/ThangkaModels/discussions)

---

## 🌟 Star History

如果这个项目对您有帮助,请给我们一个⭐️!

[![Star History Chart](https://api.star-history.com/svg?repos=WangchukMind/thangka-restoration-ai&type=Date)](https://star-history.com/#WangchukMind/thangka-restoration-ai&Date)


### Contact

- **Developer**: Wangchuk Mind
- **GitHub**: [@WangchukMind](https://github.com/WangchukMind)
- **Hugging Face**: [@Wangchuk1376](https://huggingface.co/Wangchuk1376)

---

**🎨 Preserving millennium-old Thangka culture with AI technology!**