## 主要更新 - ✨ 更新所有依赖到最新稳定版本 - 📝 添加详细的项目文档和模型推荐 - 🔧 配置 VSCode Cloud Studio 预览功能 - 🐛 修复 PyTorch API 弃用警告 ## 依赖更新 - diffusers: 0.27.2 → 0.35.2 - gradio: 4.21.0 → 5.46.0 - peft: 0.7.1 → 0.18.0 - Pillow: 9.5.0 → 11.3.0 - fastapi: 0.108.0 → 0.116.2 ## 新增文件 - CLAUDE.md - 项目架构和开发指南 - UPGRADE_NOTES.md - 详细的升级说明 - .vscode/preview.yml - 预览配置 - .vscode/LAUNCH_GUIDE.md - 启动指南 - .gitignore - 更新的忽略规则 ## 代码修复 - 修复 iopaint/model/ldm.py 中的 torch.cuda.amp.autocast() 弃用警告 ## 文档更新 - README.md - 添加模型推荐和使用指南 - 完整的项目源码(iopaint/) - Web 前端源码(web_app/) 🤖 Generated with Claude Code
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import os
|
|
import torch
|
|
|
|
from omegaconf import OmegaConf
|
|
from iopaint.model.anytext.ldm.util import instantiate_from_config
|
|
|
|
|
|
def get_state_dict(d):
|
|
return d.get("state_dict", d)
|
|
|
|
|
|
def load_state_dict(ckpt_path, location="cpu"):
|
|
_, extension = os.path.splitext(ckpt_path)
|
|
if extension.lower() == ".safetensors":
|
|
import safetensors.torch
|
|
|
|
state_dict = safetensors.torch.load_file(ckpt_path, device=location)
|
|
else:
|
|
state_dict = get_state_dict(
|
|
torch.load(ckpt_path, map_location=torch.device(location))
|
|
)
|
|
state_dict = get_state_dict(state_dict)
|
|
print(f"Loaded state_dict from [{ckpt_path}]")
|
|
return state_dict
|
|
|
|
|
|
def create_model(config_path, device, cond_stage_path=None, use_fp16=False):
|
|
config = OmegaConf.load(config_path)
|
|
# if cond_stage_path:
|
|
# config.model.params.cond_stage_config.params.version = (
|
|
# cond_stage_path # use pre-downloaded ckpts, in case blocked
|
|
# )
|
|
config.model.params.cond_stage_config.params.device = str(device)
|
|
if use_fp16:
|
|
config.model.params.use_fp16 = True
|
|
config.model.params.control_stage_config.params.use_fp16 = True
|
|
config.model.params.unet_config.params.use_fp16 = True
|
|
model = instantiate_from_config(config.model).cpu()
|
|
print(f"Loaded model config from [{config_path}]")
|
|
return model
|