本文整理匯總了Python中torch.nn.init.kaiming_uniform方法的典型用法代碼示例。如果您正苦於以下問題:Python init.kaiming_uniform方法的具體用法?Python init.kaiming_uniform怎麽用?Python init.kaiming_uniform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torch.nn.init
的用法示例。
在下文中一共展示了init.kaiming_uniform方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getExpNet
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def getExpNet(NoLabels1, dilations, isPriv, NoLabels2 = 209, withASPP = True):
model = expNet(NoLabels1, dilations, isPriv, NoLabels2 = NoLabels2, withASPP = withASPP)
for m in model.modules():
if isinstance(m,nn.Conv3d):
init.kaiming_uniform(m.weight)
elif isinstance(m, nn.Sequential):
for m_1 in m.modules():
if isinstance(m_1, nn.Conv3d):
init.kaiming_uniform(m_1.weight)
return model
示例2: getSmallHRNet
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def getSmallHRNet(NoLabels=3):
model = SmallHighResNet(NoLabels)
for m in model.modules():
if isinstance(m,nn.Conv3d):
init.kaiming_uniform(m.weight)
elif isinstance(m, nn.Sequential):
for m_1 in m.modules():
if isinstance(m_1, nn.Conv3d):
init.kaiming_uniform(m_1.weight)
return model
#or m in net.modules():
#m.weight.data.fill_(1)
#m.bias.data.fill_(0)
示例3: getHRNet
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def getHRNet(NoLabels=3):
model = HighResNet(NoLabels)
for m in model.modules():
if isinstance(m,nn.Conv3d):
init.kaiming_uniform(m.weight)
elif isinstance(m, nn.Sequential):
for m_1 in m.modules():
if isinstance(m_1, nn.Conv3d):
init.kaiming_uniform(m_1.weight)
return model
#or m in net.modules():
#m.weight.data.fill_(1)
#m.bias.data.fill_(0)
示例4: init_parameters
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def init_parameters(self,pretrain_vgg16):
##### init parameter using pretrain vgg16 model ###########
conv_blocks = [self.CNN.conv1,
self.CNN.conv2,
self.CNN.conv3,
self.CNN.conv4,
self.CNN.conv5]
ranges = [[0, 4], [5, 9], [10, 16], [17, 23], [24, 29]]
features = list(pretrain_vgg16.features.children())
for idx, conv_block in enumerate(conv_blocks):
for l1, l2 in zip(features[ranges[idx][0]:ranges[idx][1]], conv_block):
if isinstance(l1, nn.Conv2d) and isinstance(l2, nn.Conv2d):
# print idx, l1, l2
assert l1.weight.size() == l2.weight.size()
assert l1.bias.size() == l2.bias.size()
l2.weight.data = l1.weight.data
l2.bias.data = l1.bias.data
init.kaiming_uniform(self.CNN.embedding_layer.weight.data, mode='fan_in')
init.constant(self.CNN.embedding_layer.bias.data, 0)
####### init fc parameters (transplant) ##############
''''''''''
self.fc6[0].weight.data = pretrain_vgg16.classifier[0].weight.data.view(self.fc6[0].weight.size())
self.fc6[0].bias.data = pretrain_vgg16.classifier[0].bias.data.view(self.fc6[0].bias.size())
self.fc7[0].weight.data = pretrain_vgg16.classifier[3].weight.data.view(self.fc7[0].weight.size())
self.fc7[0].bias.data = pretrain_vgg16.classifier[3].bias.data.view(self.fc7[0].bias.size())
###### random init socore layer parameters ###########
assert self.upscore.kernel_size[0] == self.upscore.kernel_size[1]
initial_weight = get_upsampling_weight(self.upscore.in_channels, self.upscore.out_channels, self.upscore.kernel_size[0])
self.upscore.weight.data.copy_(initial_weight)
'''''''''
# https://github.com/shelhamer/fcn.berkeleyvision.org/blob/master/surgery.py
示例5: __init__
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def __init__(self, frame_size, dim, q_levels, weight_norm):
super().__init__()
self.q_levels = q_levels
self.embedding = torch.nn.Embedding(
self.q_levels,
self.q_levels
)
self.input = torch.nn.Conv1d(
in_channels=q_levels,
out_channels=dim,
kernel_size=frame_size,
bias=False
)
init.kaiming_uniform(self.input.weight)
if weight_norm:
self.input = torch.nn.utils.weight_norm(self.input)
self.hidden = torch.nn.Conv1d(
in_channels=dim,
out_channels=dim,
kernel_size=1
)
init.kaiming_uniform(self.hidden.weight)
init.constant(self.hidden.bias, 0)
if weight_norm:
self.hidden = torch.nn.utils.weight_norm(self.hidden)
self.output = torch.nn.Conv1d(
in_channels=dim,
out_channels=q_levels,
kernel_size=1
)
nn.lecun_uniform(self.output.weight)
init.constant(self.output.bias, 0)
if weight_norm:
self.output = torch.nn.utils.weight_norm(self.output)
示例6: init_parameters_from_deeplab
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def init_parameters_from_deeplab(self,pretrain_vgg16_1024):
##### init parameter using pretrain vgg16 model ###########
pretrain_dict_names = convert_dict_names_for_fucking_faults()
keys = sorted(pretrain_dict_names.keys())
conv_blocks = [self.CNN.conv1,
self.CNN.conv2,
self.CNN.conv3,
self.CNN.conv4,
self.CNN.conv5]
ranges = [[0,2], [0,2], [0,2,4], [0,2,4], [0,2,4]]
for key in keys:
dic_name = pretrain_dict_names[key]
base_conv_name,conv_index,sub_index = dic_name[:5],int(dic_name[4]),int(dic_name[-1])
conv_blocks[conv_index -1][ranges[sub_index -1][sub_index -1]].weight.data = pretrain_vgg16_1024[key + '.weight']
conv_blocks[conv_index- 1][ranges[sub_index -1][sub_index -1]].bias.data = pretrain_vgg16_1024[key + '.bias']
####### init fc parameters (transplant) ##############
self.CNN.fc6_1[0].weight.data = pretrain_vgg16_1024['fc6_1.0.weight'].view(self.CNN.fc6_1[0].weight.size())
self.CNN.fc6_1[0].bias.data = pretrain_vgg16_1024['fc6_1.0.bias'].view(self.CNN.fc6_1[0].bias.size())
self.CNN.fc7_1[0].weight.data = pretrain_vgg16_1024['fc7_1.0.weight'].view(self.CNN.fc7_1[0].weight.size())
self.CNN.fc7_1[0].bias.data = pretrain_vgg16_1024['fc7_1.0.bias'].view(self.CNN.fc7_1[0].bias.size())
self.CNN.fc6_2[0].weight.data = pretrain_vgg16_1024['fc6_2.0.weight'].view(self.CNN.fc6_2[0].weight.size())
self.CNN.fc6_2[0].bias.data = pretrain_vgg16_1024['fc6_2.0.bias'].view(self.CNN.fc6_2[0].bias.size())
self.CNN.fc7_2[0].weight.data = pretrain_vgg16_1024['fc7_2.0.weight'].view(self.CNN.fc7_2[0].weight.size())
self.CNN.fc7_2[0].bias.data = pretrain_vgg16_1024['fc7_2.0.bias'].view(self.CNN.fc7_2[0].bias.size())
self.CNN.fc6_3[0].weight.data = pretrain_vgg16_1024['fc6_3.0.weight'].view(self.CNN.fc6_3[0].weight.size())
self.CNN.fc6_3[0].bias.data = pretrain_vgg16_1024['fc6_3.0.bias'].view(self.CNN.fc6_3[0].bias.size())
self.CNN.fc7_3[0].weight.data = pretrain_vgg16_1024['fc7_3.0.weight'].view(self.CNN.fc7_3[0].weight.size())
self.CNN.fc7_3[0].bias.data = pretrain_vgg16_1024['fc7_3.0.bias'].view(self.CNN.fc7_3[0].bias.size())
self.CNN.fc6_4[0].weight.data = pretrain_vgg16_1024['fc6_4.0.weight'].view(self.CNN.fc6_4[0].weight.size())
self.CNN.fc6_4[0].bias.data = pretrain_vgg16_1024['fc6_4.0.bias'].view(self.CNN.fc6_4[0].bias.size())
self.CNN.fc7_4[0].weight.data = pretrain_vgg16_1024['fc7_4.0.weight'].view(self.CNN.fc7_4[0].weight.size())
self.CNN.fc7_4[0].bias.data = pretrain_vgg16_1024['fc7_4.0.bias'].view(self.CNN.fc7_4[0].bias.size())
#init.kaiming_uniform(self.CNN.embedding_layer.weight.data,mode='fan_in')
#init.constant(self.CNN.embedding_layer.bias.data,0)
示例7: __init__
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def __init__(self, version=1.0, num_classes=1000):
super(SqueezeNet, self).__init__()
if version not in [1.0, 1.1]:
raise ValueError("Unsupported SqueezeNet version {version}:"
"1.0 or 1.1 expected".format(version=version))
self.num_classes = num_classes
if version == 1.0:
self.features = nn.Sequential(
nn.Conv2d(3, 96, kernel_size=7, stride=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=False),
Fire(96, 16, 64, 64),
Fire(128, 16, 64, 64),
Fire(128, 32, 128, 128),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=False),
Fire(256, 32, 128, 128),
Fire(256, 48, 192, 192),
Fire(384, 48, 192, 192),
Fire(384, 64, 256, 256),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=False),
Fire(512, 64, 256, 256),
)
else:
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=3, stride=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=False),
Fire(64, 16, 64, 64),
Fire(128, 16, 64, 64),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=False),
Fire(128, 32, 128, 128),
Fire(256, 32, 128, 128),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=False),
Fire(256, 48, 192, 192),
Fire(384, 48, 192, 192),
Fire(384, 64, 256, 256),
Fire(512, 64, 256, 256),
)
# Final convolution is initialized differently form the rest
final_conv = nn.Conv2d(512, self.num_classes, kernel_size=1)
self.classifier = nn.Sequential(
nn.Dropout(p=0.5),
final_conv,
nn.ReLU(inplace=True),
nn.AvgPool2d(13, stride=1)
)
for m in self.modules():
if isinstance(m, nn.Conv2d):
if m is final_conv:
init.normal(m.weight.data, mean=0.0, std=0.01)
else:
init.kaiming_uniform(m.weight.data)
if m.bias is not None:
m.bias.data.zero_()
示例8: __init__
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def __init__(self, version=1.0, num_classes=1000, ceil_mode=False):
super(SqueezeNet, self).__init__()
if version not in [1.0, 1.1]:
raise ValueError("Unsupported SqueezeNet version {version}:"
"1.0 or 1.1 expected".format(version=version))
self.num_classes = num_classes
if version == 1.0:
self.features = nn.Sequential(
nn.Conv2d(3, 96, kernel_size=7, stride=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=ceil_mode),
Fire(96, 16, 64, 64),
Fire(128, 16, 64, 64),
Fire(128, 32, 128, 128),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=ceil_mode),
Fire(256, 32, 128, 128),
Fire(256, 48, 192, 192),
Fire(384, 48, 192, 192),
Fire(384, 64, 256, 256),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=ceil_mode),
Fire(512, 64, 256, 256),
)
else:
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=3, stride=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=ceil_mode),
Fire(64, 16, 64, 64),
Fire(128, 16, 64, 64),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=ceil_mode),
Fire(128, 32, 128, 128),
Fire(256, 32, 128, 128),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=ceil_mode),
Fire(256, 48, 192, 192),
Fire(384, 48, 192, 192),
Fire(384, 64, 256, 256),
Fire(512, 64, 256, 256),
)
# Final convolution is initialized differently form the rest
final_conv = nn.Conv2d(512, self.num_classes, kernel_size=1)
self.classifier = nn.Sequential(
nn.Dropout(p=0.5),
final_conv,
nn.ReLU(inplace=True),
nn.AvgPool2d(13)
)
for m in self.modules():
if isinstance(m, nn.Conv2d):
if m is final_conv:
init.normal(m.weight.data, mean=0.0, std=0.01)
else:
init.kaiming_uniform(m.weight.data)
if m.bias is not None:
m.bias.data.zero_()
示例9: __init__
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def __init__(self, version=1.0, num_classes=10):
super(SqueezeNet, self).__init__()
if version not in [1.0, 1.1]:
raise ValueError("Unsupported SqueezeNet version {version}:"
"1.0 or 1.1 expected".format(version=version))
self.num_classes = num_classes
if version == 1.0:
self.features = nn.Sequential(
nn.Conv2d(3, 96, kernel_size=7, stride=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(96, 16, 64, 64),
Fire(128, 16, 64, 64),
Fire(128, 32, 128, 128),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(256, 32, 128, 128),
Fire(256, 48, 192, 192),
Fire(384, 48, 192, 192),
Fire(384, 64, 256, 256),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(512, 64, 256, 256),
)
else:
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=3, stride=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(64, 16, 64, 64),
Fire(128, 16, 64, 64),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(128, 32, 128, 128),
Fire(256, 32, 128, 128),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(256, 48, 192, 192),
Fire(384, 48, 192, 192),
Fire(384, 64, 256, 256),
Fire(512, 64, 256, 256),
)
# Final convolution is initialized differently form the rest
final_conv = nn.Conv2d(512, self.num_classes, kernel_size=1)
self.classifier = nn.Sequential(
nn.Dropout(p=0.5),
final_conv,
nn.ReLU(inplace=True),
nn.AvgPool2d(13, stride=1)
)
for m in self.modules():
if isinstance(m, nn.Conv2d):
if m is final_conv:
init.normal(m.weight.data, mean=0.0, std=0.01)
else:
init.kaiming_uniform(m.weight.data)
if m.bias is not None:
m.bias.data.zero_()
示例10: __init__
# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform [as 別名]
def __init__(self, version=1.0, num_classes=2, use_ref=False):
super(SqueezeNetQC, self).__init__()
self.use_ref = use_ref
self.feat = 3
if version not in [1.0, 1.1]:
raise ValueError("Unsupported SqueezeNet version {version}:"
"1.0 or 1.1 expected".format(version=version))
self.num_classes = num_classes
if version == 1.0:
self.features = nn.Sequential(
nn.Conv2d(2 if use_ref else 1, 96, kernel_size=7, stride=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(96, 16, 64, 64),
Fire(128, 16, 64, 64),
Fire(128, 32, 128, 128),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(256, 32, 128, 128),
Fire(256, 48, 192, 192),
Fire(384, 48, 192, 192),
Fire(384, 64, 256, 256),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(512, 64, 256, 256),
)
else:
self.features = nn.Sequential(
nn.Conv2d(2 if use_ref else 1, 64, kernel_size=3, stride=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(64, 16, 64, 64),
Fire(128, 16, 64, 64),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(128, 32, 128, 128),
Fire(256, 32, 128, 128),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
Fire(256, 48, 192, 192),
Fire(384, 48, 192, 192),
Fire(384, 64, 256, 256),
Fire(512, 64, 256, 256),
)
# Final convolution is initialized differently form the rest
final_conv = nn.Conv2d(512*self.feat, self.num_classes, kernel_size=1)
self.classifier = nn.Sequential(
nn.Dropout(p=0.5),
final_conv,
nn.ReLU(inplace=True),
nn.AvgPool2d(13, stride=1)
)
for m in self.modules():
if isinstance(m, nn.Conv2d):
if m is final_conv:
init.normal(m.weight.data, mean=0.0, std=0.01)
else:
init.kaiming_uniform(m.weight.data)
if m.bias is not None:
m.bias.data.zero_()