当前位置: 首页>>代码示例>>Python>>正文


Python models.inception_v3方法代码示例

本文整理汇总了Python中torchvision.models.inception_v3方法的典型用法代码示例。如果您正苦于以下问题:Python models.inception_v3方法的具体用法?Python models.inception_v3怎么用?Python models.inception_v3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torchvision.models的用法示例。


在下文中一共展示了models.inception_v3方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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() 
开发者ID:MinfengZhu,项目名称:DM-GAN,代码行数:19,代码来源:model.py

示例2: get_image_format

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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} 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:25,代码来源:tools.py

示例3: test_untargeted_inception_v3

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:19,代码来源:test_attack_Gaussian_blur.py

示例4: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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() 
开发者ID:ne7ermore,项目名称:torch-light,代码行数:23,代码来源:model.py

示例5: load_inception

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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


# ==================================================================#
# ==================================================================# 
开发者ID:BCV-Uniandes,项目名称:SMIT,代码行数:20,代码来源:utils.py

示例6: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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) 
开发者ID:airalcorn2,项目名称:strike-with-a-pose,代码行数:18,代码来源:strike_utils.py

示例7: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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] 
开发者ID:airalcorn2,项目名称:strike-with-a-pose,代码行数:18,代码来源:image_classifier.py

示例8: InceptionV3

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
def InceptionV3(config):
    return models.inception_v3(pretrained=True) 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py

示例9: load_patched_inception_v3

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
def load_patched_inception_v3():
    inception = inception_v3(pretrained=True)
    inception.eval()
    inception.forward = forward.__get__(inception, Inception3)

    return inception.to(device) 
开发者ID:rosinality,项目名称:sagan-pytorch,代码行数:8,代码来源:fid.py

示例10: _load_keras_model

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:40,代码来源:tools.py

示例11: _load_pytorch_model

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:41,代码来源:tools.py

示例12: load_pytorch_model

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:30,代码来源:tools.py

示例13: test_checks_input_size_for_inception_model

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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) 
开发者ID:MisaOgura,项目名称:flashtorch,代码行数:13,代码来源:test_backprop.py

示例14: load_inception

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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 
开发者ID:xuanqing94,项目名称:RobGAN,代码行数:9,代码来源:eval_inception.py

示例15: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import inception_v3 [as 别名]
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 
开发者ID:hukkelas,项目名称:DeepPrivacy,代码行数:10,代码来源:fid.py


注:本文中的torchvision.models.inception_v3方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。