src/vision/utils.py
def prep_resnet_for_maml(model, adapt_all: bool = False, layers=[3]):
    """
    Adapt ResNet model for MAML training.
    """
    # Default inner loop adaptation parameters
    def _inner_params(self):
        if adapt_all:
            return list(self.parameters())
        else:
            params = []
            for l in layers:
                params.extend(getattr(self, f"layer{l}").parameters())
            assert len(params) > 0
            return params

    for mod in model.modules():
        if type(mod) == nn.BatchNorm2d:
            mod.track_running_stats = False

    type(model).inner_params = _inner_params

    Adapt ResNet model for MAML training.
    
Adapt ResNet model for MAML training.
Adapt ResNet model for MAML training .
def prep_resnet_for_maml(model, adapt_all: bool = False, layers=[3]):
    def _inner_params(self):
        if adapt_all:
            return list(self.parameters())
        else:
            params = []
            for l in layers:
                params.extend(getattr(self, f"layer{l}").parameters())
            assert len(params) > 0
            return params
    for mod in model.modules():
        if type(mod) == nn.BatchNorm2d:
            mod.track_running_stats = False
    type(model).inner_params = _inner_params
def prep_resnet_for_maml ( model , adapt_all : bool = False , layers = [ 3 ] ) : def _inner_params ( self ) : if adapt_all : return list ( self . parameters ( ) ) else : params = [ ] for l in layers : params . extend ( getattr ( self , f"layer{l}" ) . parameters ( ) ) assert len ( params ) > 0 return params for mod in model . modules ( ) : if type ( mod ) == nn . BatchNorm2d : mod . track_running_stats = False type ( model ) . inner_params = _inner_params
Adapt ResNet model for MAML training.
Adapt ResNet model for MAML training .
"""
    Adapt ResNet model for MAML training.
    """ # Default inner loop adaptation parameters
model
adapt_all
bool
layers