mirror of
https://github.com/Haoming02/sd-webui-old-photo-restoration.git
synced 2026-05-01 03:31:48 +00:00
commit cd7a9c103d1ea981ecd236d4e9111fd3c1cd6c2b Author: Haoming <hmstudy02@gmail.com> Date: Tue Dec 19 11:33:44 2023 +0800 add README commit 30127cbb2a8e5f461c540729dc7ad457f66eb94c Author: Haoming <hmstudy02@gmail.com> Date: Tue Dec 19 11:12:16 2023 +0800 fix Face Enhancement distortion commit 6d52de5368c6cfbd9342465b5238725c186e00b9 Author: Haoming <hmstudy02@gmail.com> Date: Mon Dec 18 18:27:25 2023 +0800 better? args handling commit 0d1938b59eb77a038ee0a91a66b07fb9d7b3d6d4 Author: Haoming <hmstudy02@gmail.com> Date: Mon Dec 18 17:40:19 2023 +0800 bug fix related to Scratch commit 8315cd05ffeb2d651b4c57d70bf04b413ca8901d Author: Haoming <hmstudy02@gmail.com> Date: Mon Dec 18 17:24:52 2023 +0800 implement step 2 ~ 4 commit a5feb04b3980bdd80c6b012a94c743ba48cdfe39 Author: Haoming <hmstudy02@gmail.com> Date: Mon Dec 18 11:55:20 2023 +0800 process scratch commit3b18f7b042Author: Haoming <hmstudy02@gmail.com> Date: Wed Dec 13 11:57:20 2023 +0800 "init" commitd0148e0e82Author: Haoming <hmstudy02@gmail.com> Date: Wed Dec 13 10:34:39 2023 +0800 clone repo
59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
# Copyright (c) Microsoft Corporation.
|
|
# Licensed under the MIT License.
|
|
|
|
import torch.nn as nn
|
|
from torch.nn import init
|
|
|
|
|
|
class BaseNetwork(nn.Module):
|
|
def __init__(self):
|
|
super(BaseNetwork, self).__init__()
|
|
|
|
@staticmethod
|
|
def modify_commandline_options(parser, is_train):
|
|
return parser
|
|
|
|
def print_network(self):
|
|
if isinstance(self, list):
|
|
self = self[0]
|
|
num_params = 0
|
|
for param in self.parameters():
|
|
num_params += param.numel()
|
|
print(
|
|
"Network [%s] was created. Total number of parameters: %.1f million."
|
|
% (type(self).__name__, num_params / 1000000)
|
|
)
|
|
|
|
def init_weights(self, init_type="normal", gain=0.02):
|
|
def init_func(m):
|
|
classname = m.__class__.__name__
|
|
if classname.find("BatchNorm2d") != -1:
|
|
if hasattr(m, "weight") and m.weight is not None:
|
|
init.normal_(m.weight.data, 1.0, gain)
|
|
if hasattr(m, "bias") and m.bias is not None:
|
|
init.constant_(m.bias.data, 0.0)
|
|
elif hasattr(m, "weight") and (classname.find("Conv") != -1 or classname.find("Linear") != -1):
|
|
if init_type == "normal":
|
|
init.normal_(m.weight.data, 0.0, gain)
|
|
elif init_type == "xavier":
|
|
init.xavier_normal_(m.weight.data, gain=gain)
|
|
elif init_type == "xavier_uniform":
|
|
init.xavier_uniform_(m.weight.data, gain=1.0)
|
|
elif init_type == "kaiming":
|
|
init.kaiming_normal_(m.weight.data, a=0, mode="fan_in")
|
|
elif init_type == "orthogonal":
|
|
init.orthogonal_(m.weight.data, gain=gain)
|
|
elif init_type == "none": # uses pytorch's default init method
|
|
m.reset_parameters()
|
|
else:
|
|
raise NotImplementedError("initialization method [%s] is not implemented" % init_type)
|
|
if hasattr(m, "bias") and m.bias is not None:
|
|
init.constant_(m.bias.data, 0.0)
|
|
|
|
self.apply(init_func)
|
|
|
|
# propagate to children
|
|
for m in self.children():
|
|
if hasattr(m, "init_weights"):
|
|
m.init_weights(init_type, gain)
|