pytorch/caffe2/python/helpers/nonlinearity.py
Andrey Malevich ff61ed358e Refactoring of the parameters step 0. Add simple tags and unify interface for params and computed_params
Summary:
This diff is the first step in the effort for refactoring all paramters. As a
first step - I'm merging concept of params and computed_params, that is going
to be based on tags instead (in the first version it's still using old data
structs to store all the BlobReferences).

Renaming computed_params to non-trainable/non-backprop params should be done is
some other diff.

Reviewed By: salexspb

Differential Revision: D5119830

fbshipit-source-id: 2001090a37346eb12abbb234e13e727c288eb8a7
2017-05-31 22:36:36 -07:00

37 lines
1.0 KiB
Python

## @package nonlinearity
# Module caffe2.python.helpers.nonlinearity
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from caffe2.python import core
def prelu(model, blob_in, blob_out, num_channels=1, slope_init=None,
**kwargs):
"""PRelu"""
slope_init = (
slope_init if slope_init else ('ConstantFill', {'value': 0.25}))
if model.init_params:
slope = model.param_init_net.__getattr__(slope_init[0])(
[],
blob_out + '_slope',
shape=[num_channels],
**slope_init[1]
)
else:
slope = core.ScopedBlobReference(
blob_out + '_slope', model.param_init_net)
model.AddParameter(slope)
return model.net.PRelu([blob_in, slope], [blob_out])
def relu(model, blob_in, blob_out, use_cudnn=False, order="NCHW", **kwargs):
"""Relu."""
if use_cudnn:
kwargs['engine'] = 'CUDNN'
return model.net.Relu(blob_in, blob_out, order=order, **kwargs)