File size: 710 Bytes
c968fc3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# Copyright (c) 2023 Amphion.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#################### GAN utils ####################
import typing as tp
def get_padding(kernel_size, dilation=1):
return int((kernel_size * dilation - dilation) / 2)
def get_2d_padding(
kernel_size: tp.Tuple[int, int], dilation: tp.Tuple[int, int] = (1, 1)
):
return (
((kernel_size[0] - 1) * dilation[0]) // 2,
((kernel_size[1] - 1) * dilation[1]) // 2,
)
def init_weights(m, mean=0.0, std=0.01):
classname = m.__class__.__name__
if classname.find("Conv") != -1:
m.weight.data.normal_(mean, std)
|