(self, layer, layername, aka)
Internal method to replace a forward method with a closure that
        intercepts the call, and tracks the hook so that it can be reverted.
Internal method to replace a forward method with a closure that
        intercepts the call, and tracks the hook so that it can be reverted.
Internal method to replace a forward method with a closure that intercepts the call and tracks the hook so that it can be reverted .
def _hook_layer(self, layer, layername, aka):
        '''
        Internal method to replace a forward method with a closure that
        intercepts the call, and tracks the hook so that it can be reverted.
        '''
        if aka in self._hooked_layer:
            raise ValueError('Layer %s already hooked' % aka)
        if layername in self._old_forward:
            raise ValueError('Layer %s already hooked' % layername)
        self._hooked_layer[aka] = layername
        self._old_forward[layername] = (layer, aka,
                layer.__dict__.get('forward', None))
        editor = self
        original_forward = layer.forward
        def new_forward(self, *inputs, **kwargs):
            original_x = original_forward(*inputs, **kwargs)
            x = editor._postprocess_forward(original_x, aka)
            return x
        layer.forward = types.MethodType(new_forward, layer)
def _hook_layer ( self , layer , layername , aka ) : if aka in self . _hooked_layer : raise ValueError ( 'Layer %s already hooked' % aka ) if layername in self . _old_forward : raise ValueError ( 'Layer %s already hooked' % layername ) self . _hooked_layer [ aka ] = layername self . _old_forward [ layername ] = ( layer , aka , layer . __dict__ . get ( 'forward' , None ) ) editor = self original_forward = layer . forward def new_forward ( self , * inputs , * * kwargs ) : original_x = original_forward ( * inputs , * * kwargs ) x = editor . _postprocess_forward ( original_x , aka ) return x layer . forward = types . MethodType ( new_forward , layer )