def get_regularizer(desc): """Get regularizer function.""" if desc.type == 'l1_regularizer': return slim.l1_regularizer(scale=float(desc.weight)) elif desc.type == 'l2_regularizer': return slim.l2_regularizer(scale=float(desc.weight)) else: raise ValueError('Unknown regularizer type: {}'.format(desc.type))
def get_real_model(self): """Get real model of regularizer.""" if self.model: return self.model else: if self.type == 'l1_regularizer': self.model = slim.l1_regularizer(scale=float(self.weight)) elif self.type == 'l2_regularizer': self.model = slim.l2_regularizer(scale=float(self.weight)) else: self.model = None raise ValueError('Unknown regularizer type: {}'.format( self.type)) return self.model
def _build_slim_regularizer(regularizer): """Builds a tf-slim regularizer from config. Args: regularizer: hyperparams_pb2.Hyperparams.regularizer proto. Returns: tf-slim regularizer. Raises: ValueError: On unknown regularizer. """ regularizer_oneof = regularizer.WhichOneof('regularizer_oneof') if regularizer_oneof == 'l1_regularizer': return slim.l1_regularizer(scale=float(regularizer.l1_regularizer.weight)) if regularizer_oneof == 'l2_regularizer': return slim.l2_regularizer(scale=float(regularizer.l2_regularizer.weight)) if regularizer_oneof is None: return None raise ValueError('Unknown regularizer function: {}'.format(regularizer_oneof))