Files
change_hair/project/hair_service_sd/keypoints/lib/utils/zipreader.py
T
xsl ce445b64a6 完善部署并训练5个新发型 + 换发型集成文档
部署修复:
- torch.load 增加 weights_only=False patch,兼容 PyTorch 2.6+ 加载旧权重
- OSS 改为懒加载,本地用 output_format=base64 无需配凭证即可启动
- 补全被 gitignore 误排除的必需代码:core/models/layers/data、models/layers/data、keypoints/lib
- webui 训练命令 --xformers 改 --sdpa(修复 xformers 无 CUDA 支持报错)

功能调整:
- hair_grow_service 端口改 8899、preview 路由修复(send_file)
- list_hairstyles 增加发型白名单,测试页只展示当前5个发型

新增脚本:
- train_lora_parallel.py:直接调 kohya 并行训练 LoRA(绕过 photo_service 串行限制)
- train_hairstyles_parallel.py / train_batch_stepC.py:批量训练辅助脚本
- scripts/sync_data_to_server.sh:大文件断点续传到云服务器

文档:
- docs/换发型集成文档.md:换发型完整流程、服务架构、资源依赖、训练方法、集成步骤
2026-07-09 20:45:08 +08:00

71 lines
2.1 KiB
Python

# ------------------------------------------------------------------------------
# Copyright (c) Microsoft
# Licensed under the MIT License.
# Written by Bin Xiao (Bin.Xiao@microsoft.com)
# ------------------------------------------------------------------------------
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import zipfile
import xml.etree.ElementTree as ET
import cv2
import numpy as np
_im_zfile = []
_xml_path_zip = []
_xml_zfile = []
def imread(filename, flags=cv2.IMREAD_COLOR):
global _im_zfile
path = filename
pos_at = path.index('@')
if pos_at == -1:
print("character '@' is not found from the given path '%s'"%(path))
assert 0
path_zip = path[0: pos_at]
path_img = path[pos_at + 2:]
if not os.path.isfile(path_zip):
print("zip file '%s' is not found"%(path_zip))
assert 0
for i in range(len(_im_zfile)):
if _im_zfile[i]['path'] == path_zip:
data = _im_zfile[i]['zipfile'].read(path_img)
return cv2.imdecode(np.frombuffer(data, np.uint8), flags)
_im_zfile.append({
'path': path_zip,
'zipfile': zipfile.ZipFile(path_zip, 'r')
})
data = _im_zfile[-1]['zipfile'].read(path_img)
return cv2.imdecode(np.frombuffer(data, np.uint8), flags)
def xmlread(filename):
global _xml_path_zip
global _xml_zfile
path = filename
pos_at = path.index('@')
if pos_at == -1:
print("character '@' is not found from the given path '%s'"%(path))
assert 0
path_zip = path[0: pos_at]
path_xml = path[pos_at + 2:]
if not os.path.isfile(path_zip):
print("zip file '%s' is not found"%(path_zip))
assert 0
for i in xrange(len(_xml_path_zip)):
if _xml_path_zip[i] == path_zip:
data = _xml_zfile[i].open(path_xml)
return ET.fromstring(data.read())
_xml_path_zip.append(path_zip)
print("read new xml file '%s'"%(path_zip))
_xml_zfile.append(zipfile.ZipFile(path_zip, 'r'))
data = _xml_zfile[-1].open(path_xml)
return ET.fromstring(data.read())