3
EgR @ s, d dl mZmZ d dlZG dd deZG dd deZG dd deZG d d
d
eZ G dd deZ
G d
d deZG dd deZG dd deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd d eZG d!d" d"eZG d#d$ d$eZdS )% )coreutilsNc @ s e Zd ZdZdZdS )RegularizationByZafter_optimizerZon_lossN)__name__
__module____qualname__ZAFTER_OPTIMIZERZON_LOSS r r E/usr/local/lib64/python3.6/site-packages/caffe2/python/regularizer.pyr s r c @ sB e Zd Zdd ZdddZdddZdd Zd
d Zdd
dZdS )Regularizerc C s
d| _ d S )Ng&.>)kEpsilon)selfr r r __init__ s zRegularizer.__init__Nc C sv t |tjsttjt}||j ks>tdj| j ||j d| }t
| |sbtdj| j |t| |||||S )Nz>Regularizer of type {} is called with invalid by={}, not in {}Z_run_z5Regularizer of type {} does not implement function {})
isinstancer Z
BlobReferenceAssertionErrorr ZEnumClassKeyValsr valuesformat __class__hasattrgetattr)r netparam_init_netparamgradZbyZby_enumrun_funcr r r __call__ s
zRegularizer.__call__c C s d S )Nr )r r r r r r r r _run_on_loss' s zRegularizer._run_on_lossc C s d S )Nr )r r r r r r r r _run_after_optimizer* s z Regularizer._run_after_optimizerc C sL |j ||g|jdg}|j|g|jdg}|j|g|jdgdd}|S )N param_mul
param_reducedgrouped_feature_weight_vecg ?)exponent)MulNextScopedBlobReduceFrontSumPow)r r r r r r r r r _feature_grouping- s
zRegularizer._feature_groupingFc
C st |d k r|s|r|| j n|}|d k r8|s.|r8|| j n|}t|tjrV||j|jgn|g} |j| |g||d d S )N)minmax)r r r
GradientSliceindicesr Z
EnsureClipped)
r r r r r&