Python torchvision.models.inception_v3() Examples

The following are 30 code examples of torchvision.models.inception_v3(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module torchvision.models , or try the search function .
Example #1
Source File: model.py    From AttnGAN with MIT License 6 votes vote down vote up
def __init__(self, nef):
        super(CNN_ENCODER, self).__init__()
        if cfg.TRAIN.FLAG:
            self.nef = nef
        else:
            self.nef = 256  # define a uniform ranker

        model = models.inception_v3()
        url = 'https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth'
        model.load_state_dict(model_zoo.load_url(url))
        for param in model.parameters():
            param.requires_grad = False
        print('Load pretrained model from ', url)
        # print(model)

        self.define_module(model)
        self.init_trainable_weights() 
Example #2
Source File: model.py    From semantic-object-accuracy-for-generative-text-to-image-synthesis with MIT License 6 votes vote down vote up
def __init__(self, nef):
        super(CNN_ENCODER, self).__init__()
        if cfg.TRAIN.FLAG:
            self.nef = nef
        else:
            self.nef = 256  # define a uniform ranker

        model = models.inception_v3()
        url = 'https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth'
        model.load_state_dict(model_zoo.load_url(url))
        for param in model.parameters():
            param.requires_grad = False
        print('Load pretrained model from ', url)
        # print(model)

        self.define_module(model)
        self.init_trainable_weights() 
Example #3
Source File: main.py    From Grad-CAM.pytorch with Apache License 2.0 6 votes vote down vote up
def get_net(net_name, weight_path=None):
    """
    根据网络名称获取模型
    :param net_name: 网络名称
    :param weight_path: 与训练权重路径
    :return:
    """
    pretrain = weight_path is None  # 没有指定权重路径,则加载默认的预训练权重
    if net_name in ['vgg', 'vgg16']:
        net = models.vgg16(pretrained=pretrain)
    elif net_name == 'vgg19':
        net = models.vgg19(pretrained=pretrain)
    elif net_name in ['resnet', 'resnet50']:
        net = models.resnet50(pretrained=pretrain)
    elif net_name == 'resnet101':
        net = models.resnet101(pretrained=pretrain)
    elif net_name in ['densenet', 'densenet121']:
        net = models.densenet121(pretrained=pretrain)
    elif net_name in ['inception']:
        net = models.inception_v3(pretrained=pretrain)
    elif net_name in ['mobilenet_v2']:
        net = models.mobilenet_v2(pretrained=pretrain)
    elif net_name in ['shufflenet_v2']:
        net = models.shufflenet_v2_x1_0(pretrained=pretrain)
    else:
        raise ValueError('invalid network name:{}'.format(net_name))
    # 加载指定路径的权重参数
    if weight_path is not None and net_name.startswith('densenet'):
        pattern = re.compile(
            r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$')
        state_dict = torch.load(weight_path)
        for key in list(state_dict.keys()):
            res = pattern.match(key)
            if res:
                new_key = res.group(1) + res.group(2)
                state_dict[new_key] = state_dict[key]
                del state_dict[key]
        net.load_state_dict(state_dict)
    elif weight_path is not None:
        net.load_state_dict(torch.load(weight_path))
    return net 
Example #4
Source File: model.py    From torch-light with MIT License 6 votes vote down vote up
def __init__(self, vocab_size, dec_hsz, rnn_layers, bsz, max_len, dropout, use_cuda):
        super().__init__()

        self.torch = torch.cuda if use_cuda else torch
        self.dec_hsz = dec_hsz
        self.rnn_layers = rnn_layers
        self.bsz = bsz
        self.max_len = max_len
        self.vocab_size = vocab_size
        self.dropout = dropout

        self.enc = inception_v3(True)
        self.enc_out = nn.Linear(1000, dec_hsz)
        self.lookup_table = nn.Embedding(vocab_size, dec_hsz, padding_idx=PAD)
        self.rnn = nn.LSTM(dec_hsz + dec_hsz, dec_hsz, rnn_layers,
                           batch_first=True,
                           dropout=dropout)
        self.attn = Attention(dec_hsz)
        self.out = nn.Linear(self.dec_hsz, vocab_size)

        self._reset_parameters() 
Example #5
Source File: model.py    From attn-gan with MIT License 6 votes vote down vote up
def __init__(self, nef):
        super(CNN_ENCODER, self).__init__()
        if cfg.TRAIN.FLAG:
            self.nef = nef
        else:
            self.nef = 256  # define a uniform ranker

        model = models.inception_v3()
        url = 'https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth'
        model.load_state_dict(model_zoo.load_url(url))
        for param in model.parameters():
            param.requires_grad = False
        print('Load pretrained model from ', url)
        # print(model)

        self.define_module(model)
        self.init_trainable_weights() 
Example #6
Source File: utils.py    From SMIT with MIT License 6 votes vote down vote up
def load_inception(path='data/RafD/normal/inception_v3.pth'):
    from torchvision.models import inception_v3
    import torch
    import torch.nn as nn
    state_dict = torch.load(path)
    net = inception_v3(pretrained=False, transform_input=True)
    print("Loading inception_v3 from " + path)
    net.aux_logits = False
    num_ftrs = net.fc.in_features
    net.fc = nn.Linear(num_ftrs, state_dict['fc.weight'].size(0))
    net.load_state_dict(state_dict)
    for param in net.parameters():
        param.requires_grad = False
    return net


# ==================================================================#
# ==================================================================# 
Example #7
Source File: strike_utils.py    From strike-with-a-pose with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, device):
        super(Model, self).__init__()
        self.device = device

        self.net = models.inception_v3(pretrained=True)

        self.net.eval()
        for param in self.net.parameters():
            param.requires_grad = False

        # Set up preprocessor.
        self.preprocess = transforms.Normalize(
            mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
        )

        (self.width, self.height) = (299, 299) 
Example #8
Source File: model.py    From multiple-objects-gan with MIT License 6 votes vote down vote up
def __init__(self, nef):
        super(CNN_ENCODER, self).__init__()
        if cfg.TRAIN.FLAG:
            self.nef = nef
        else:
            self.nef = 256  # define a uniform ranker

        model = models.inception_v3()
        url = 'https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth'
        model.load_state_dict(model_zoo.load_url(url))
        for param in model.parameters():
            param.requires_grad = False
        print('Load pretrained model from ', url)
        # print(model)

        self.define_module(model)
        self.init_trainable_weights() 
Example #9
Source File: image_classifier.py    From strike-with-a-pose with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, true_class):
        super(ImageClassifier, self).__init__()
        self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
        self.net = models.inception_v3(pretrained=True).to(self.device)
        self.net.eval()
        for param in self.net.parameters():
            param.requires_grad = False

        self.preprocess = transforms.Normalize(
            mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
        )

        self.label_map = self.load_imagenet_label_map()

        self.true_class = true_class
        self.true_label = self.label_map[self.true_class] 
Example #10
Source File: test_attack_MotionBlurAttack.py    From perceptron-benchmark with Apache License 2.0 6 votes vote down vote up
def test_untargeted_inception_v3(image, label=None):
    import torch
    import torchvision.models as models
    from perceptron.models.classification import PyTorchModel
    mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
    std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
    model_pyt = models.inception_v3(pretrained=True).eval()
    if torch.cuda.is_available():
        model_pyt = model_pyt.cuda()
    model = PyTorchModel(
        model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std))
    print(np.argmax(model.predictions(image)))
    attack = Attack(model, criterion=Misclassification())
    adversarial_obj = attack(image, label, unpack=False, epsilons=10000)
    distance = adversarial_obj.distance
    adversarial = adversarial_obj.image
    return distance, adversarial 
Example #11
Source File: test_attack_BlendedUniformNoiseAttack.py    From perceptron-benchmark with Apache License 2.0 6 votes vote down vote up
def test_untargeted_inception_v3(image, label=None):
    import torch
    import torchvision.models as models
    from perceptron.models.classification import PyTorchModel
    mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
    std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
    model_pyt = models.inception_v3(pretrained=True).eval()
    if torch.cuda.is_available():
        model_pyt = model_pyt.cuda()
    model = PyTorchModel(
        model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std))
    print(np.argmax(model.predictions(image)))
    attack = Attack(model, criterion=Misclassification())
    adversarial_obj = attack(image, label, unpack=False, epsilons=10000)
    distance = adversarial_obj.distance
    adversarial = adversarial_obj.image
    return distance, adversarial 
Example #12
Source File: test_attack_SaltAndPepperNoiseAttack.py    From perceptron-benchmark with Apache License 2.0 6 votes vote down vote up
def test_untargeted_inception_v3(image, label=None):
    import torch
    import torchvision.models as models
    from perceptron.models.classification import PyTorchModel
    mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
    std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
    model_pyt = models.inception_v3(pretrained=True).eval()
    if torch.cuda.is_available():
        model_pyt = model_pyt.cuda()
    model = PyTorchModel(
        model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std))
    print(np.argmax(model.predictions(image)))
    attack = Attack(model, criterion=Misclassification())
    adversarial_obj = attack(image, label, unpack=False, epsilons=10000)
    distance = adversarial_obj.distance
    adversarial = adversarial_obj.image
    return distance, adversarial 
Example #13
Source File: test_attack_AdditiveUniformNoiseAttack.py    From perceptron-benchmark with Apache License 2.0 6 votes vote down vote up
def test_untargeted_inception_v3(image, label=None):
    import torch
    import torchvision.models as models
    from perceptron.models.classification import PyTorchModel
    mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
    std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
    model_pyt = models.inception_v3(pretrained=True).eval()
    if torch.cuda.is_available():
        model_pyt = model_pyt.cuda()
    model = PyTorchModel(
        model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std))
    print(np.argmax(model.predictions(image)))
    attack = Attack(model, criterion=Misclassification())
    adversarial_obj = attack(image, label, unpack=False, epsilons=10000)
    distance = adversarial_obj.distance
    adversarial = adversarial_obj.image
    return distance, adversarial 
Example #14
Source File: test_attack_Gaussian_blur.py    From perceptron-benchmark with Apache License 2.0 6 votes vote down vote up
def test_untargeted_inception_v3(image, label=None):
    import torch
    import torchvision.models as models
    from perceptron.models.classification import PyTorchModel
    mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
    std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
    model_pyt = models.inception_v3(pretrained=True).eval()
    if torch.cuda.is_available():
        model_pyt = model_pyt.cuda()
    model = PyTorchModel(
        model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std))
    print(np.argmax(model.predictions(image)))
    attack = Attack(model, criterion=Misclassification())
    adversarial_obj = attack(image, label, unpack=False, epsilons=10000)
    distance = adversarial_obj.distance
    adversarial = adversarial_obj.image
    return distance, adversarial 
Example #15
Source File: tools.py    From perceptron-benchmark with Apache License 2.0 6 votes vote down vote up
def get_image_format(framework_name, model_name):
    """Return the correct input range and shape for target framework and model"""
    special_shape = {'pytorch':{'inception_v3': (299, 299)},
                     'keras': {'xception': (299, 299),
                               'inception_v3':(299, 299),
                               'yolo_v3': (416, 416),
                               'ssd300': (300, 300)}}
    special_bound = {'keras':{'vgg16':(0, 255),
                              'vgg19':(0, 255),
                              'resnet50':(0, 255),
                              'ssd300': (0, 255)},
                     'cloud': {'aip_antiporn': (0, 255),
                               'google_safesearch': (0, 255),
                               'google_objectdetection': (0, 255)}}
    default_shape = (224, 224)
    default_bound = (0, 1)
    if special_shape.get(framework_name, None):
        if special_shape[framework_name].get(model_name, None):
            default_shape = special_shape[framework_name][model_name]
    if special_bound.get(framework_name, None):
        if special_bound[framework_name].get(model_name, None):
            default_bound = special_bound[framework_name][model_name]
    return {'shape': default_shape, 'bounds': default_bound} 
Example #16
Source File: model.py    From DM-GAN with MIT License 6 votes vote down vote up
def __init__(self, nef):
        super(CNN_ENCODER, self).__init__()
        if cfg.TRAIN.FLAG:
            self.nef = nef
        else:
            self.nef = 256  # define a uniform ranker

        model = models.inception_v3()
        url = 'https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth'
        model.load_state_dict(model_zoo.load_url(url))
        for param in model.parameters():
            param.requires_grad = False
        print('Load pretrained model from ', url)
        # print(model)

        self.define_module(model)
        self.init_trainable_weights() 
Example #17
Source File: model.py    From AttnGAN with MIT License 6 votes vote down vote up
def __init__(self, nef):
        super(CNN_ENCODER, self).__init__()
        if cfg.TRAIN.FLAG:
            self.nef = nef
        else:
            self.nef = 256  # define a uniform ranker

        model = models.inception_v3()
        url = 'https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth'
        model.load_state_dict(model_zoo.load_url(url))
        for param in model.parameters():
            param.requires_grad = False
        print('Load pretrained model from ', url)
        # print(model)

        self.define_module(model)
        self.init_trainable_weights() 
Example #18
Source File: class_activation_mapper.py    From strike-with-a-pose with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, true_class):
        super(ClassActivationMapper, self).__init__()
        self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
        self.net = models.inception_v3(pretrained=True).to(self.device)
        self.net.eval()
        for param in self.net.parameters():
            param.requires_grad = False

        self.preprocess = transforms.Normalize(
            mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
        )

        self.label_map = self.load_imagenet_label_map()
        self.true_class = true_class
        self.true_label = self.label_map[self.true_class]

        feature_params = list(self.net.parameters())[-2]
        self.weight_softmax = np.squeeze(feature_params.data.detach().cpu().numpy())
        # Get features from Mixed_7c layer.
        self.features = torch.zeros((1, 2048, 8, 8))

        def copy_data(module, input, output):
            self.features.data.copy_(output.data)

        self.net._modules.get("Mixed_7c").register_forward_hook(copy_data)
        (bn, feat_nc, feat_h, feat_w) = self.features.shape
        self.feat_shape = (feat_nc, feat_h * feat_w)
        self.cam_shape = (feat_h, feat_w)

        self.out_shape = (299, 299) 
Example #19
Source File: test_torchvision_models.py    From pytorch-cnn-finetune with MIT License 5 votes vote down vote up
def test_inception_v3_model(input_var):
    original_model = torchvision_models.inception_v3(
        pretrained=True,
        transform_input=False,
    )
    finetune_model = make_model(
        'inception_v3', num_classes=1000, pool=default, pretrained=True
    )
    copy_module_weights(original_model.fc, finetune_model._classifier)
    assert_equal_model_outputs(input_var, original_model, finetune_model) 
Example #20
Source File: test_torchvision_models.py    From pytorch-cnn-finetune with MIT License 5 votes vote down vote up
def test_inception_v3_model_with_another_input_size(input_var):
    model = make_model('inception_v3', num_classes=1000, pretrained=True)
    model(input_var) 
Example #21
Source File: model.py    From StackGAN-v2 with MIT License 5 votes vote down vote up
def __init__(self):
        super(INCEPTION_V3, self).__init__()
        self.model = models.inception_v3()
        url = 'https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth'
        # print(next(model.parameters()).data)
        state_dict = \
            model_zoo.load_url(url, map_location=lambda storage, loc: storage)
        self.model.load_state_dict(state_dict)
        for param in self.model.parameters():
            param.requires_grad = False
        print('Load pretrained model from ', url)
        # print(next(self.model.parameters()).data)
        # print(self.model) 
Example #22
Source File: fid.py    From sagan-pytorch with Apache License 2.0 5 votes vote down vote up
def load_patched_inception_v3():
    inception = inception_v3(pretrained=True)
    inception.eval()
    inception.forward = forward.__get__(inception, Inception3)

    return inception.to(device) 
Example #23
Source File: basenet.py    From MCD_DA with MIT License 5 votes vote down vote up
def __init__(self):
        super(InceptionBase, self).__init__()
        model_ft = models.inception_v3(pretrained=True)
        #mod = list(model_ft.children())
        #mod.pop()
        self.features = model_ft#nn.Sequential(*mod) 
Example #24
Source File: model.py    From Recipe2ImageGAN with MIT License 5 votes vote down vote up
def __init__(self):
        super(INCEPTION_V3, self).__init__()
        self.model = models.inception_v3()
        url = 'https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth'
        # print(next(model.parameters()).data)
        state_dict = \
            model_zoo.load_url(url, map_location=lambda storage, loc: storage)
        self.model.load_state_dict(state_dict)
        for param in self.model.parameters():
            param.requires_grad = False
        print('Load pretrained model from ', url)
        # print(next(self.model.parameters()).data)
        # print(self.model) 
Example #25
Source File: fid.py    From DeepPrivacy with MIT License 5 votes vote down vote up
def __init__(self, transform_input=True):
        super().__init__()
        self.inception_network = inception_v3(pretrained=False, transform_input=False)
        # Load state dict
        state_dict = torch.utils.model_zoo.load_url("https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth", model_dir="metrics/inception")
        self.inception_network.load_state_dict(state_dict)
        self.inception_network.Mixed_7c.register_forward_hook(self.output_hook)
        self.transform_input = transform_input 
Example #26
Source File: eval_inception.py    From RobGAN with MIT License 5 votes vote down vote up
def load_inception():
    inception_model = inception_v3(pretrained=True, transform_input=False)
    inception_model.cuda()
    inception_model = torch.nn.DataParallel(inception_model, \
            device_ids=range(opt.ngpu))
    inception_model.eval()
    return inception_model 
Example #27
Source File: test_backprop.py    From flashtorch with MIT License 5 votes vote down vote up
def test_checks_input_size_for_inception_model(mocker):
    with pytest.raises(ValueError) as error:
        model = models.inception_v3()
        backprop = Backprop(model)

        target_class = 5
        input_ = torch.zeros([1, 3, 224, 224])

        backprop.calculate_gradients(input_, target_class)

    assert 'Image must be 299x299 for Inception models.' in str(error.value) 
Example #28
Source File: tools.py    From perceptron-benchmark with Apache License 2.0 5 votes vote down vote up
def load_pytorch_model(model_name):
    import torchvision.models as models
    switcher = {
        'alexnet': lambda: models.alexnet(pretrained=True).eval(),
        "vgg11": lambda: models.vgg11(pretrained=True).eval(),
        "vgg11_bn": lambda: models.vgg11_bn(pretrained=True).eval(),
        "vgg13": lambda: models.vgg13(pretrained=True).eval(),
        "vgg13_bn": lambda: models.vgg13_bn(pretrained=True).eval(),
        "vgg16": lambda: models.vgg16(pretrained=True).eval(),
        "vgg16_bn": lambda: models.vgg16_bn(pretrained=True).eval(),
        "vgg19": lambda: models.vgg19(pretrained=True).eval(),
        "vgg19_bn": lambda: models.vgg19_bn(pretrained=True).eval(),
        "resnet18": lambda: models.resnet18(pretrained=True).eval(),
        "resnet34": lambda: models.resnet34(pretrained=True).eval(),
        "resnet50": lambda: models.resnet50(pretrained=True).eval(),
        "resnet101": lambda: models.resnet101(pretrained=True).eval(),
        "resnet152": lambda: models.resnet152(pretrained=True).eval(),
        "squeezenet1_0": lambda: models.squeezenet1_0(pretrained=True).eval(),
        "squeezenet1_1": lambda: models.squeezenet1_1(pretrained=True).eval(),
        "densenet121": lambda: models.densenet121(pretrained=True).eval(),
        "densenet161": lambda: models.densenet161(pretrained=True).eval(),
        "densenet201": lambda: models.densenet201(pretrained=True).eval(),
        "inception_v3": lambda: models.inception_v3(pretrained=True).eval(),
    }

    _load_model = switcher.get(model_name, None)
    _model = _load_model()
    return _model 
Example #29
Source File: tools.py    From perceptron-benchmark with Apache License 2.0 5 votes vote down vote up
def _load_pytorch_model(model_name, summary):
    import torchvision.models as models
    switcher = {
        'alexnet': lambda: models.alexnet(pretrained=True).eval(),
        "vgg11": lambda: models.vgg11(pretrained=True).eval(),
        "vgg11_bn": lambda: models.vgg11_bn(pretrained=True).eval(),
        "vgg13": lambda: models.vgg13(pretrained=True).eval(),
        "vgg13_bn": lambda: models.vgg13_bn(pretrained=True).eval(),
        "vgg16": lambda: models.vgg16(pretrained=True).eval(),
        "vgg16_bn": lambda: models.vgg16_bn(pretrained=True).eval(),
        "vgg19": lambda: models.vgg19(pretrained=True).eval(),
        "vgg19_bn": lambda: models.vgg19_bn(pretrained=True).eval(),
        "resnet18": lambda: models.resnet18(pretrained=True).eval(),
        "resnet34": lambda: models.resnet34(pretrained=True).eval(),
        "resnet50": lambda: models.resnet50(pretrained=True).eval(),
        "resnet101": lambda: models.resnet101(pretrained=True).eval(),
        "resnet152": lambda: models.resnet152(pretrained=True).eval(),
        "squeezenet1_0": lambda: models.squeezenet1_0(pretrained=True).eval(),
        "squeezenet1_1": lambda: models.squeezenet1_1(pretrained=True).eval(),
        "densenet121": lambda: models.densenet121(pretrained=True).eval(),
        "densenet161": lambda: models.densenet161(pretrained=True).eval(),
        "densenet201": lambda: models.densenet201(pretrained=True).eval(),
        "inception_v3": lambda: models.inception_v3(pretrained=True).eval(),
    }

    _load_model = switcher.get(model_name, None)
    _model = _load_model()
    import torch
    if torch.cuda.is_available():
        _model = _model.cuda()
    from perceptron.models.classification.pytorch import PyTorchModel as ClsPyTorchModel
    import numpy as np
    mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
    std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
    pmodel = ClsPyTorchModel(
        _model, bounds=(
            0, 1), num_classes=1000, preprocessing=(
            mean, std))
    return pmodel 
Example #30
Source File: tools.py    From perceptron-benchmark with Apache License 2.0 5 votes vote down vote up
def _load_keras_model(model_name, summary):
    import keras.applications as models
    switcher = {
        'xception': lambda: models.xception.Xception(weights='imagenet'),
        'vgg16': lambda: models.vgg16.VGG16(weights='imagenet'),
        'vgg19': lambda: models.vgg19.VGG19(weights='imagenet'),
        "resnet50": lambda: models.resnet50.ResNet50(weights='imagenet'),
        "inception_v3": lambda: models.inception_v3.InceptionV3(weights='imagenet'),
        "yolo_v3": lambda: _load_yolov3_model(),
        "ssd300": lambda: _load_ssd300_model(),
        "retina_resnet_50": lambda: _load_retinanet_resnet50_model()
    }

    _load_model = switcher.get(model_name, None)
    _model = _load_model()

    from perceptron.models.classification.keras import KerasModel as ClsKerasModel
    from perceptron.models.detection.keras_ssd300 import KerasSSD300Model
    from perceptron.models.detection.keras_yolov3 import KerasYOLOv3Model
    from perceptron.models.detection.keras_retina_resnet50 import KerasResNet50RetinaNetModel
    import numpy as np
    format = get_image_format('keras', model_name)
    if format['bounds'][1] == 1:
        mean = np.array([0.485, 0.456, 0.406]).reshape((1, 1, 3))
        std = np.array([0.229, 0.224, 0.225]).reshape((1, 1, 3))
        preprocessing = (mean, std)
    else:
        preprocessing = (np.array([104, 116, 123]), 1)
    switcher = {
        'yolo_v3': lambda x: KerasYOLOv3Model(x, bounds=(0, 1)),
        'ssd300': lambda x: KerasSSD300Model(x, bounds=(0, 255)),
        'retina_resnet_50': lambda x: KerasResNet50RetinaNetModel(None, bounds=(0, 255)),
    }
    _wrap_model = switcher.get(
        model_name,
        lambda x: ClsKerasModel(x, bounds=format['bounds'], preprocessing=preprocessing))
    kmodel = _wrap_model(_model)
    return kmodel