包含: - 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 排除, 由网盘单独上传。
76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
import numpy as np
|
|
import torch
|
|
from torch import nn
|
|
|
|
def get_norm(norm, out_channels=None):
|
|
"""
|
|
Args:
|
|
norm (str or callable):
|
|
|
|
Returns:
|
|
nn.Module or None: the normalization layer
|
|
"""
|
|
if isinstance(norm, str):
|
|
if len(norm) == 0:
|
|
return None
|
|
norm = {
|
|
"BN": nn.BatchNorm2d,
|
|
"IN": nn.InstanceNorm2d,
|
|
"GN": lambda channels: nn.GroupNorm(32, channels),
|
|
"nnSyncBN": nn.SyncBatchNorm, # keep for debugging
|
|
}[norm]
|
|
if out_channels is not None:
|
|
return norm(out_channels)
|
|
else:
|
|
return norm
|
|
|
|
class Conv2d(torch.nn.Conv2d):
|
|
"""
|
|
A wrapper around :class:`torch.nn.Conv2d` to support zero-size tensor and more features.
|
|
"""
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
"""
|
|
Extra keyword arguments supported in addition to those in `torch.nn.Conv2d`:
|
|
|
|
Args:
|
|
norm (nn.Module, optional): a normalization layer
|
|
activation (callable(Tensor) -> Tensor): a callable activation function
|
|
|
|
It assumes that norm layer is used before activation.
|
|
"""
|
|
norm = kwargs.pop("norm", None)
|
|
activation = kwargs.pop("activation", None)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.norm = norm
|
|
self.activation = activation
|
|
|
|
def forward(self, x):
|
|
x = super().forward(x)
|
|
if self.norm is not None:
|
|
x = self.norm(x)
|
|
if self.activation is not None:
|
|
x = self.activation(x)
|
|
return x
|
|
|
|
class Backbone(nn.Module):
|
|
"""
|
|
Abstract base class for network backbones.
|
|
"""
|
|
|
|
def __init__(self):
|
|
"""
|
|
The `__init__` method of any subclass can specify its own set of arguments.
|
|
"""
|
|
super().__init__()
|
|
|
|
def forward(self):
|
|
"""
|
|
Subclasses must override this method, but adhere to the same return type.
|
|
|
|
Returns:
|
|
dict[str: Tensor]: mapping from feature name (e.g., "res2") to tensor
|
|
"""
|
|
pass
|