(self)
Replaces 'forward' of sequential with a version that takes
        additional keyword arguments: layer allows a single layer to be run;
        first_layer and last_layer allow a subsequence of layers to be run.
Replaces 'forward' of sequential with a version that takes
        additional keyword arguments: layer allows a single layer to be run;
        first_layer and last_layer allow a subsequence of layers to be run.
Replaces forward of sequential with a version that takes additional keyword arguments : layer allows a single layer to be run ; first_layer and last_layer allow a subsequence of layers to be run .
def _hook_sequential(self):
        '''
        Replaces 'forward' of sequential with a version that takes
        additional keyword arguments: layer allows a single layer to be run;
        first_layer and last_layer allow a subsequence of layers to be run.
        '''
        model = self.model
        self._hooked_layer['.'] = '.'
        self._old_forward['.'] = (model, '.',
                model.__dict__.get('forward', None))
        def new_forward(this, x, layer=None, first_layer=None, last_layer=None):
            assert layer is None or (first_layer is None and last_layer is None)
            first_layer, last_layer = [str(layer) if layer is not None
                    else str(d) if d is not None else None
                    for d in [first_layer, last_layer]]
            including_children = (first_layer is None)
            for name, layer in this._modules.items():
                if name == first_layer:
                    first_layer = None
                    including_children = True
                if including_children:
                    x = layer(x)
                if name == last_layer:
                    last_layer = None
                    including_children = False
            assert first_layer is None, '%s not found' % first_layer
            assert last_layer is None, '%s not found' % last_layer
            return x
        model.forward = types.MethodType(new_forward, model)
def _hook_sequential ( self ) : model = self . model self . _hooked_layer [ '.' ] = '.' self . _old_forward [ '.' ] = ( model , '.' , model . __dict__ . get ( 'forward' , None ) ) def new_forward ( this , x , layer = None , first_layer = None , last_layer = None ) : assert layer is None or ( first_layer is None and last_layer is None ) first_layer , last_layer = [ str ( layer ) if layer is not None else str ( d ) if d is not None else None for d in [ first_layer , last_layer ] ] including_children = ( first_layer is None ) for name , layer in this . _modules . items ( ) : if name == first_layer : first_layer = None including_children = True if including_children : x = layer ( x ) if name == last_layer : last_layer = None including_children = False assert first_layer is None , '%s not found' % first_layer assert last_layer is None , '%s not found' % last_layer return x model . forward = types . MethodType ( new_forward , model )