<filename>dev/local/classification/models.py
#AUTOGENERATED! DO NOT EDIT! File to edit: dev/23_classification_models.ipynb (unless otherwise specified).

__all__ = ['default_configs', 'model_funcs', 'splits', 'get_model', 'EfficientNetB1', 'EfficientNetB2',
           'EfficientNetB3', 'EfficientNetB4', 'EfficientNetB5', 'EfficientNetB6', 'EfficientNetB7',
           'efficientnet_config', 'efficientnetb1', 'efficientnetb2', 'efficientnetb3', 'efficientnetb4',
           'efficientnetb5', 'efficientnetb6', 'efficientnetb7']

#Cell
from fastai.vision import *

#Cell
default_configs = {}
model_funcs = {}
splits = {}

#Cell
def get_model(name, data, config):
    "Get model given name, data and config. Undefined config is defaulted."
    conf, copy_conf = default_configs[name].copy(), default_configs[name].copy()
    conf.update(config)
    f = model_funcs[name]
    model = f(data, conf)
    split_fn = splits.get(name)
    return model, split_fn, copy_conf

#Cell
# https://github.com/lukemelas/EfficientNet-PyTorch
from fastai.vision.models.efficientnet import *

#Cell
# pretrained
def EfficientNetB1(data): return EfficientNet.from_pretrained('efficientnet-b1', num_classes=data.c)
def EfficientNetB2(data): return EfficientNet.from_pretrained('efficientnet-b2', num_classes=data.c)
def EfficientNetB3(data): return EfficientNet.from_pretrained('efficientnet-b3', num_classes=data.c)
def EfficientNetB4(data): return EfficientNet.from_pretrained('efficientnet-b4', num_classes=data.c)
def EfficientNetB5(data): return EfficientNet.from_pretrained('efficientnet-b5', num_classes=data.c)
def EfficientNetB6(data): return EfficientNet.from_pretrained('efficientnet-b6', num_classes=data.c)
def EfficientNetB7(data): return EfficientNet.from_pretrained('efficientnet-b7', num_classes=data.c)

#Cell
def _efficientnet_split(m:nn.Module): return (m._blocks[9], m._blocks[17])
efficientnet_config = {"pretrained":True}

#Cell
def efficientnetb1(data, config): return EfficientNetB1(data)
model_funcs['efficientnetb1'] = efficientnetb1
default_configs['efficientnetb1'] = efficientnet_config
splits['efficientnetb1'] = _efficientnet_split

def efficientnetb2(data, config): return EfficientNetB2(data)
model_funcs['efficientnetb2'] = efficientnetb2
default_configs['efficientnetb2'] = efficientnet_config
splits['efficientnetb2'] = _efficientnet_split

def efficientnetb3(data, config): return EfficientNetB3(data)
model_funcs['efficientnetb3'] = efficientnetb3
default_configs['efficientnetb3'] = efficientnet_config
splits['efficientnetb3'] = _efficientnet_split

def efficientnetb4(data, config): return EfficientNetB4(data)
model_funcs['efficientnetb4'] = efficientnetb4
default_configs['efficientnetb4'] = efficientnet_config
splits['efficientnetb4'] = _efficientnet_split

def efficientnetb5(data, config): return EfficientNetB5(data)
model_funcs['efficientnetb5'] = efficientnetb5
default_configs['efficientnetb5'] = efficientnet_config
splits['efficientnetb5'] = _efficientnet_split

def efficientnetb6(data, config): return EfficientNetB6(data)
model_funcs['efficientnetb6'] = efficientnetb6
default_configs['efficientnetb6'] = efficientnet_config
splits['efficientnetb6'] = _efficientnet_split

def efficientnetb7(data, config): return EfficientNetB7(data)
model_funcs['efficientnetb7'] = efficientnetb7
default_configs['efficientnetb7'] = efficientnet_config
splits['efficientnetb7'] = _efficientnet_split
<filename>dev/local/classification/models.py
#AUTOGENERATED! DO NOT EDIT! File to edit: dev/23_classification_models.ipynb (unless otherwise specified).

__all__ = ['default_configs', 'model_funcs', 'splits', 'get_model', 'EfficientNetB1', 'EfficientNetB2',
           'EfficientNetB3', 'EfficientNetB4', 'EfficientNetB5', 'EfficientNetB6', 'EfficientNetB7',
           'efficientnet_config', 'efficientnetb1', 'efficientnetb2', 'efficientnetb3', 'efficientnetb4',
           'efficientnetb5', 'efficientnetb6', 'efficientnetb7']

#Cell
from fastai.vision import *

#Cell
default_configs = {}
model_funcs = {}
splits = {}

#Cell
def get_model(name, data, config):
    "Get model given name, data and config. Undefined config is defaulted."
    conf, copy_conf = default_configs[name].copy(), default_configs[name].copy()
    conf.update(config)
    f = model_funcs[name]
    model = f(data, conf)
    split_fn = splits.get(name)
    return model, split_fn, copy_conf

#Cell
# https://github.com/lukemelas/EfficientNet-PyTorch
from fastai.vision.models.efficientnet import *

#Cell
# pretrained
def EfficientNetB1(data): return EfficientNet.from_pretrained('efficientnet-b1', num_classes=data.c)
def EfficientNetB2(data): return EfficientNet.from_pretrained('efficientnet-b2', num_classes=data.c)
def EfficientNetB3(data): return EfficientNet.from_pretrained('efficientnet-b3', num_classes=data.c)
def EfficientNetB4(data): return EfficientNet.from_pretrained('efficientnet-b4', num_classes=data.c)
def EfficientNetB5(data): return EfficientNet.from_pretrained('efficientnet-b5', num_classes=data.c)
def EfficientNetB6(data): return EfficientNet.from_pretrained('efficientnet-b6', num_classes=data.c)
def EfficientNetB7(data): return EfficientNet.from_pretrained('efficientnet-b7', num_classes=data.c)

#Cell
def _efficientnet_split(m:nn.Module): return (m._blocks[9], m._blocks[17])
efficientnet_config = {"pretrained":True}

#Cell
def efficientnetb1(data, config): return EfficientNetB1(data)
model_funcs['efficientnetb1'] = efficientnetb1
default_configs['efficientnetb1'] = efficientnet_config
splits['efficientnetb1'] = _efficientnet_split

def efficientnetb2(data, config): return EfficientNetB2(data)
model_funcs['efficientnetb2'] = efficientnetb2
default_configs['efficientnetb2'] = efficientnet_config
splits['efficientnetb2'] = _efficientnet_split

def efficientnetb3(data, config): return EfficientNetB3(data)
model_funcs['efficientnetb3'] = efficientnetb3
default_configs['efficientnetb3'] = efficientnet_config
splits['efficientnetb3'] = _efficientnet_split

def efficientnetb4(data, config): return EfficientNetB4(data)
model_funcs['efficientnetb4'] = efficientnetb4
default_configs['efficientnetb4'] = efficientnet_config
splits['efficientnetb4'] = _efficientnet_split

def efficientnetb5(data, config): return EfficientNetB5(data)
model_funcs['efficientnetb5'] = efficientnetb5
default_configs['efficientnetb5'] = efficientnet_config
splits['efficientnetb5'] = _efficientnet_split

def efficientnetb6(data, config): return EfficientNetB6(data)
model_funcs['efficientnetb6'] = efficientnetb6
default_configs['efficientnetb6'] = efficientnet_config
splits['efficientnetb6'] = _efficientnet_split

def efficientnetb7(data, config): return EfficientNetB7(data)
model_funcs['efficientnetb7'] = efficientnetb7
default_configs['efficientnetb7'] = efficientnet_config
splits['efficientnetb7'] = _efficientnet_split
#AUTOGENERATED! DO NOT EDIT! File to edit: dev/23_classification_models.ipynb (unless otherwise specified). #Cell #Cell #Cell #Cell # https://github.com/lukemelas/EfficientNet-PyTorch #Cell # pretrained #Cell #Cell