## 主要更新 - ✨ 更新所有依赖到最新稳定版本 - 📝 添加详细的项目文档和模型推荐 - 🔧 配置 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
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
import torch
|
|
from copy import deepcopy
|
|
|
|
from ..utils import load_file_from_url
|
|
from .retinaface import RetinaFace
|
|
|
|
|
|
def init_detection_model(model_name, half=False, device='cuda', model_rootpath=None):
|
|
if model_name == 'retinaface_resnet50':
|
|
model = RetinaFace(network_name='resnet50', half=half, device=device)
|
|
model_url = 'https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth'
|
|
elif model_name == 'retinaface_mobile0.25':
|
|
model = RetinaFace(network_name='mobile0.25', half=half, device=device)
|
|
model_url = 'https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_mobilenet0.25_Final.pth'
|
|
else:
|
|
raise NotImplementedError(f'{model_name} is not implemented.')
|
|
|
|
model_path = load_file_from_url(
|
|
url=model_url, model_dir='facexlib/weights', progress=True, file_name=None, save_dir=model_rootpath)
|
|
|
|
# TODO: clean pretrained model
|
|
load_net = torch.load(model_path, map_location=lambda storage, loc: storage)
|
|
# remove unnecessary 'module.'
|
|
for k, v in deepcopy(load_net).items():
|
|
if k.startswith('module.'):
|
|
load_net[k[7:]] = v
|
|
load_net.pop(k)
|
|
model.load_state_dict(load_net, strict=True)
|
|
model.eval()
|
|
model = model.to(device)
|
|
return model
|