本文整理汇总了Python中caffe2.python.modeling.initializers.Initializer方法的典型用法代码示例。如果您正苦于以下问题:Python initializers.Initializer方法的具体用法?Python initializers.Initializer怎么用?Python initializers.Initializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe2.python.modeling.initializers
的用法示例。
在下文中一共展示了initializers.Initializer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AffineChannel
# 需要导入模块: from caffe2.python.modeling import initializers [as 别名]
# 或者: from caffe2.python.modeling.initializers import Initializer [as 别名]
def AffineChannel(self, blob_in, blob_out, dim, inplace=False):
"""Affine transformation to replace BN in networks where BN cannot be
used (e.g., because the minibatch size is too small).
The operations can be done in place to save memory.
"""
blob_out = blob_out or self.net.NextName()
param_prefix = blob_out
scale = self.create_param(
param_name=param_prefix + '_s',
initializer=initializers.Initializer("ConstantFill", value=1.),
tags=ParameterTags.WEIGHT,
shape=[dim, ],
)
bias = self.create_param(
param_name=param_prefix + '_b',
initializer=initializers.Initializer("ConstantFill", value=0.),
tags=ParameterTags.BIAS,
shape=[dim, ],
)
if inplace:
return self.net.AffineChannel([blob_in, scale, bias], blob_in)
else:
return self.net.AffineChannel([blob_in, scale, bias], blob_out)
示例2: create_model
# 需要导入模块: from caffe2.python.modeling import initializers [as 别名]
# 或者: from caffe2.python.modeling.initializers import Initializer [as 别名]
def create_model(model_builder, model, enable_tensor_core, float16_compute, loss_scale=1.0):
"""Creates one model replica.
:param obj model_builder: A model instance that contains `forward_pass_builder` method.
:param model: Caffe2's model helper class instances.
:type model: :py:class:`caffe2.python.model_helper.ModelHelper`
:param bool enable_tensor_core: If true, Volta's tensor core ops are enabled.
:param float loss_scale: Scale loss for multi-GPU training.
:return: Head nodes (softmax or loss depending on phase)
"""
initializer = (pFP16Initializer if model_builder.dtype == 'float16' else Initializer)
with brew.arg_scope([brew.conv, brew.fc],
WeightInitializer=initializer,
BiasInitializer=initializer,
enable_tensor_core=enable_tensor_core,
float16_compute=float16_compute):
outputs = model_builder.forward_pass_builder(model, loss_scale=loss_scale)
return outputs