pytorch/caffe2/python/layers/sampling_trainable_mixin.py
skyline75489 46b83212d1 Remove unused six code for Python 2/3 compatibility (#48077)
Summary:
This is basically a reborn version of https://github.com/pytorch/pytorch/issues/45254 .

Ref: https://github.com/pytorch/pytorch/issues/42919

Pull Request resolved: https://github.com/pytorch/pytorch/pull/48077

Reviewed By: ngimel

Differential Revision: D25687042

Pulled By: bugra

fbshipit-source-id: 05f20a6f3c5212f73d0b1505b493b720e6cf74e5
2020-12-22 18:07:08 -08:00

54 lines
1.3 KiB
Python

## @package sampling_trainable_mixin
# Module caffe2.python.layers.sampling_trainable_mixin
import abc
class SamplingTrainableMixin(metaclass=abc.ABCMeta):
def __init__(self, *args, **kwargs):
super(SamplingTrainableMixin, self).__init__(*args, **kwargs)
self._train_param_blobs = None
self._train_param_blobs_frozen = False
@property
@abc.abstractmethod
def param_blobs(self):
"""
List of parameter blobs for prediction net
"""
pass
@property
def train_param_blobs(self):
"""
If train_param_blobs is not set before used, default to param_blobs
"""
if self._train_param_blobs is None:
self.train_param_blobs = self.param_blobs
return self._train_param_blobs
@train_param_blobs.setter
def train_param_blobs(self, blobs):
assert not self._train_param_blobs_frozen
assert blobs is not None
self._train_param_blobs_frozen = True
self._train_param_blobs = blobs
@abc.abstractmethod
def _add_ops(self, net, param_blobs):
"""
Add ops to the given net, using the given param_blobs
"""
pass
def add_ops(self, net):
self._add_ops(net, self.param_blobs)
def add_train_ops(self, net):
self._add_ops(net, self.train_param_blobs)