(self, layernames)
Sets up a set of layers to be hooked.

        Usually not called directly: use edit_layer or retain_layer instead.
Sets up a set of layers to be hooked.
Sets up a set of layers to be hooked .
def add_hooks(self, layernames):
        '''
        Sets up a set of layers to be hooked.

        Usually not called directly: use edit_layer or retain_layer instead.
        '''
        needed = set()
        aka_map = {}
        for name in layernames:
            aka = name
            if not isinstance(aka, str):
                name, aka = name
            if self._hooked_layer.get(aka, None) != name:
                aka_map[name] = aka
                needed.add(name)
        if not needed:
            return
        for name, layer in self.model.named_modules():
            if name in aka_map:
                needed.remove(name)
                aka = aka_map[name]
                self._hook_layer(layer, name, aka)
        for name in needed:
            raise ValueError('Layer %s not found in model' % name)
def add_hooks ( self , layernames ) : needed = set ( ) aka_map = { } for name in layernames : aka = name if not isinstance ( aka , str ) : name , aka = name if self . _hooked_layer . get ( aka , None ) != name : aka_map [ name ] = aka needed . add ( name ) if not needed : return for name , layer in self . model . named_modules ( ) : if name in aka_map : needed . remove ( name ) aka = aka_map [ name ] self . _hook_layer ( layer , name , aka ) for name in needed : raise ValueError ( 'Layer %s not found in model' % name )