mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: There is a module called `2to3` which you can target for future specifically to remove these, the directory of `caffe2` has the most redundant imports: ```2to3 -f future -w caffe2``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/45033 Reviewed By: seemethere Differential Revision: D23808648 Pulled By: bugra fbshipit-source-id: 38971900f0fe43ab44a9168e57f2307580d36a38
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
## @package nonlinearity
|
|
# Module caffe2.python.helpers.nonlinearity
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
def tanh(model, blob_in, blob_out, use_cudnn=False, order="NCHW", **kwargs):
|
|
"""Tanh."""
|
|
if use_cudnn:
|
|
kwargs['engine'] = 'CUDNN'
|
|
return model.net.Tanh(blob_in, blob_out, order=order, **kwargs)
|