包含: - hair_service_sd: 换发型/换发色算法服务 (端口 8801) - photo_service: LoRA 训练调度服务 (端口 32678) - stable-diffusion-webui: SD WebUI 推理服务 (端口 57860) - kohya_ss_home: 训练环境代码 - meidaojia: 监控测试脚本 - setup.sh: 一键部署脚本 (conda环境恢复 + 配置生成 + 完整性检查) - start_all_services.sh: 启动3个服务 - configure.ini.template: 路径模板化 (BASE_DIR自动推导) - conda_envs/py310.yml: py310 环境定义 大文件 (weights/, models/, data/, conda_envs/*.tar.gz 等) 通过 .gitignore 排除, 由网盘单独上传。
25 lines
1.3 KiB
Python
25 lines
1.3 KiB
Python
import os
|
|
import torch
|
|
|
|
def load_model_by_path(model_save_path, model, gpu_id = None):
|
|
if not os.path.exists(model_save_path): return
|
|
loc = 'cpu' if gpu_id is None else 'cuda:{}'.format(gpu_id)
|
|
pretrained_dict = torch.load(model_save_path, map_location=loc)
|
|
if 'state_dict' in pretrained_dict: pretrained_dict = pretrained_dict['state_dict']
|
|
model_dict = model.state_dict()
|
|
# pretrained_dict.pop('netG.model.1.weight', '404')
|
|
pretrained_dict_new = {k: v for k, v in pretrained_dict.items()
|
|
if (k in model_dict and model_dict[k].data.shape == v.data.shape)}
|
|
# if 'netG.model.1.weight' not in pretrained_dict_new and 'netG.model.1.weight' in model_dict:
|
|
# pretrained_dict_new['netG.model.1.weight'] = model_dict['netG.model.1.weight']
|
|
# pretrained_dict_new['netG.model.1.weight'][:,:12] = pretrained_dict['netG.model.1.weight']
|
|
|
|
model_dict.update(pretrained_dict_new)
|
|
model.load_state_dict(model_dict)
|
|
print("load model: ", model_save_path)
|
|
|
|
def save_model_by_path(model_save_path, model):
|
|
save_dir, _ = os.path.split(model_save_path)
|
|
if not os.path.isdir(save_dir): os.makedirs(save_dir)
|
|
model_dic={k.replace('.module', ''):v for k,v in model.state_dict().items()}
|
|
torch.save(model_dic, model_save_path) |