in lib/modeling/detector_rel.py [0:0]
def add_Conv_layer_with_weight_name(
self, weights_prefix, blob_in, blob_out, dim_in, dim_out,
kernel, weight_init=None, bias_init=None, group=1, **kwargs):
weights_name = weights_prefix + '_w'
bias_name = weights_prefix + '_b'
scope_str = scope.CurrentNameScope()
use_bias = False if ("no_bias" in kwargs and kwargs["no_bias"]) else True
weight_init = weight_init if weight_init else ('XavierFill', {})
bias_init = bias_init if bias_init else ('ConstantFill', {})
blob_out = blob_out or self.net.NextName()
weight_shape = (
[dim_out, int(dim_in / group), kernel, kernel]
if self.order == "NCHW" else
[dim_out, kernel, kernel, int(dim_in / group)]
)
if scope_str + weights_name not in self.params:
weight = self.param_init_net.__getattr__(weight_init[0])(
[],
weights_name,
shape=weight_shape,
**weight_init[1]
)
self.weights.append(weight)
if use_bias:
bias = self.param_init_net.__getattr__(bias_init[0])(
[],
bias_name,
shape=[dim_out, ],
**bias_init[1]
)
self.params.extend([weight, bias])
self.biases.append(bias)
else:
self.params.extend([weight])
else:
weight = core.ScopedBlobReference(
weights_name, self.param_init_net)
if use_bias:
bias = core.ScopedBlobReference(
bias_name, self.param_init_net)
if self.use_cudnn:
kwargs['engine'] = 'CUDNN'
kwargs['exhaustive_search'] = self.cudnn_exhaustive_search
if self.ws_nbytes_limit:
kwargs['ws_nbytes_limit'] = self.ws_nbytes_limit
inputs = []
if use_bias:
inputs = [blob_in, weight, bias]
else:
inputs = [blob_in, weight]
# For the operator, we no longer need to provide the no_bias field
# because it can automatically figure this out from the number of
# inputs.
if 'no_bias' in kwargs:
del kwargs['no_bias']
if group != 1:
kwargs['group'] = group
return self.net.Conv(
inputs,
blob_out,
kernel=kernel,
order=self.order,
**kwargs
)