@@ -0,0 +1,1745 @@
+# @package optimizer%0A# Module caffe2.python.optimizer%0Afrom __future__ import absolute_import%0Afrom __future__ import division%0Afrom __future__ import print_function%0Afrom __future__ import unicode_literals%0A%0A%0Afrom caffe2.python import core%0A%0A%0Aclass Regularizer(object):%0A    def __init__(self):%0A        pass%0A%0A    '''%0A    Adds regularization to train_net for given parameter. Its factor ahead of%0A    regularization is given when initialization.%0A    The param should be a BlobReference.%0A    '''%0A%0A    def __call__(self, train_net, param):%0A        assert isinstance(param, core.BlobReference)%0A        return self._run(train_net, param)%0A%0A    def _run(self, train_net, param):%0A        raise Exception(%22Not Impelemented%22)%0A%0A%0Aclass L1Norm(Regularizer):%0A    def __init__(self, reg_lambda):%0A        super(L1Norm, self).__init__()%0A        assert reg_lambda %3E= 0,%5C%0A            'factor ahead of regularization should be 0 or positive'%0A%0A        self.reg_lambda = reg_lambda%0A%0A    def _run(self, train_net, param):%0A        output_blob = train_net.NextScopedBlob(param + '_l1_regularization')%0A        train_net.LpNorm(%5Bparam%5D, %5Boutput_blob%5D, p=1)%0A        train_net.Scale(%5Boutput_blob%5D, %5Boutput_blob%5D, scale=self.reg_lambda)%0A        return output_blob%0A%0A%0Aclass L2Norm(Regularizer):%0A    def __init__(self, reg_lambda):%0A        super(L2Norm, self).__init__()%0A        assert reg_lambda %3E= 0,%5C%0A            'factor ahead of regularization should be 0 or positive'%0A%0A        self.reg_lambda = reg_lambda%0A%0A    def _run(self, train_net, param):%0A        output_blob = train_net.NextScopedBlob(param + '_l2_regularization')%0A        train_net.LpNorm(%5Bparam%5D, %5Boutput_blob%5D, p=2)%0A        train_net.Scale(%5Boutput_blob%5D, %5Boutput_blob%5D, scale=self.reg_lambda)%0A        return output_blob%0A

add regulariztion in caffe2 and dper