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


Python models.alexnet方法代码示例

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


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

示例1: test_untargeted_AlexNet

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

示例2: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def __init__(self,feature,hidden_unit, D_in, D_out):
        """
        In the constructor we instantiate two nn.Linear modules and assign them as
        member variables.
        """
        super(cnn_lstm, self).__init__()
        self.model_ft = models.alexnet(pretrained=True)
        # print (model_ft)

        self.num_ftrs = self.model_ft.classifier[6].in_features
        self.feature_model = list(self.model_ft.classifier.children())
        self.feature_model.pop()
        self.feature_model.pop()
        # feature_model.append(nn.Linear(num_ftrs, 3))
        self.feature_model.append(nn.Linear(self.num_ftrs, 1046))
        self.feature_model.append(nn.Linear(1046, 100))

        self.model_ft.classifier = nn.Sequential(*self.feature_model)

        self.rnn = nn.LSTM(feature,hidden_unit,batch_first=True).cuda()
        self.linear = torch.nn.Linear(D_in, D_out).cuda() 
开发者ID:ayush1997,项目名称:Robust-Lane-Detection-and-Tracking,代码行数:23,代码来源:run_py_node.py

示例3: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def __init__(self,feature,hidden_unit, D_in, D_out):
        """
        In the constructor we instantiate two nn.Linear modules and assign them as
        member variables.
        """
        super(cnn_lstm, self).__init__()
        self.model_ft = models.alexnet(pretrained=True)
        # print (model_ft)

        self.num_ftrs = self.model_ft.classifier[6].in_features
        self.feature_model = list(self.model_ft.classifier.children())
        self.feature_model.pop()
        self.feature_model.pop()
        # feature_model.append(nn.Linear(num_ftrs, 3))
        self.feature_model.append(nn.Linear(self.num_ftrs, 1046))
        # self.feature_model.append(nn.Linear(self.num_ftrs, 524))
        self.feature_model.append(nn.Linear(1046, 100))
        # self.feature_model.append(nn.Linear(524, 100))

        self.model_ft.classifier = nn.Sequential(*self.feature_model)

        self.rnn = nn.LSTM(feature,hidden_unit,batch_first=True).cuda()
        self.linear = torch.nn.Linear(D_in, D_out).cuda() 
开发者ID:ayush1997,项目名称:Robust-Lane-Detection-and-Tracking,代码行数:25,代码来源:evaluate.py

示例4: getNetwork

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def getNetwork(args):
    if (args.net_type == 'alexnet'):
        net = models.alexnet(pretrained=args.finetune)
        file_name = 'alexnet'
    elif (args.net_type == 'vggnet'):
        if(args.depth == 16):
            net = models.vgg16(pretrained=args.finetune)
        file_name = 'vgg-%s' %(args.depth)
    elif (args.net_type == 'inception'):
        net = models.inception(pretrained=args.finetune)
        file_name = 'inceptino-v3'
    elif (args.net_type == 'resnet'):
        net = resnet(args.finetune, args.depth)
        file_name = 'resnet-%s' %(args.depth)
    else:
        print('Error : Network should be either [VGGNet / ResNet]')
        sys.exit(1)

    return net, file_name 
开发者ID:meliketoy,项目名称:fine-tuning.pytorch,代码行数:21,代码来源:inference.py

示例5: test_dissection

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def test_dissection():
    verbose_progress(True)
    from torchvision.models import alexnet
    from torchvision import transforms
    model = InstrumentedModel(alexnet(pretrained=True))
    model.eval()
    # Load an alexnet
    model.retain_layers([
        ('features.0', 'conv1'),
        ('features.3', 'conv2'),
        ('features.6', 'conv3'),
        ('features.8', 'conv4'),
        ('features.10', 'conv5') ])
    # load broden dataset
    bds = BrodenDataset('dataset/broden',
            transform=transforms.Compose([
                transforms.ToTensor(),
                transforms.Normalize(IMAGE_MEAN, IMAGE_STDEV)]),
            size=100)
    # run dissect
    dissect('dissect/test', model, bds,
            examples_per_unit=10) 
开发者ID:CSAILVision,项目名称:gandissect,代码行数:24,代码来源:__main__.py

示例6: select

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def select(self, model_name=None):
        """select models to be run"""
        logging.info("Run details")
        logging.info("=" * 71)
        models = [
            self.alexnet,
            self.resnet18,
            self.resnet50,
            self.vgg16,
            self.squeezenet,
        ]
        if model_name:
            self.models = [
                model for model in models for name in model_name if name == model.name
            ]
        logging.info("Selected model(s) :: ")
        for m in self.models:
            logging.info("%s ------------- Batchsize :: %s " % (m.name, m.batch))
        logging.info("=" * 71) 
开发者ID:intel,项目名称:stacks-usecase,代码行数:21,代码来源:cnn_benchmarks.py

示例7: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def __init__(self, requires_grad=False, pretrained=True):
        super(alexnet, self).__init__()
        alexnet_pretrained_features = tv.alexnet(pretrained=pretrained).features
        self.slice1 = torch.nn.Sequential()
        self.slice2 = torch.nn.Sequential()
        self.slice3 = torch.nn.Sequential()
        self.slice4 = torch.nn.Sequential()
        self.slice5 = torch.nn.Sequential()
        self.N_slices = 5
        for x in range(2):
            self.slice1.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(2, 5):
            self.slice2.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(5, 8):
            self.slice3.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(8, 10):
            self.slice4.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(10, 12):
            self.slice5.add_module(str(x), alexnet_pretrained_features[x])
        if not requires_grad:
            for param in self.parameters():
                param.requires_grad = False 
开发者ID:richzhang,项目名称:PerceptualSimilarity,代码行数:24,代码来源:pretrained_networks.py

示例8: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def __init__(self, requires_grad=False, pretrained=True):
        super(alexnet, self).__init__()
        alexnet_pretrained_features = models.alexnet(pretrained=pretrained).features
        self.slice1 = torch.nn.Sequential()
        self.slice2 = torch.nn.Sequential()
        self.slice3 = torch.nn.Sequential()
        self.slice4 = torch.nn.Sequential()
        self.slice5 = torch.nn.Sequential()
        self.N_slices = 5
        for x in range(2):
            self.slice1.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(2, 5):
            self.slice2.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(5, 8):
            self.slice3.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(8, 10):
            self.slice4.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(10, 12):
            self.slice5.add_module(str(x), alexnet_pretrained_features[x])
        if not requires_grad:
            for param in self.parameters():
                param.requires_grad = False 
开发者ID:thunil,项目名称:TecoGAN,代码行数:24,代码来源:pretrained_networks.py

示例9: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def __init__(self, requires_grad=False, pretrained=True):
        super(alexnet, self).__init__()
        alexnet_pretrained_features = models.alexnet(
            pretrained=pretrained).features
        self.slice1 = torch.nn.Sequential()
        self.slice2 = torch.nn.Sequential()
        self.slice3 = torch.nn.Sequential()
        self.slice4 = torch.nn.Sequential()
        self.slice5 = torch.nn.Sequential()
        self.N_slices = 5
        for x in range(2):
            self.slice1.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(2, 5):
            self.slice2.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(5, 8):
            self.slice3.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(8, 10):
            self.slice4.add_module(str(x), alexnet_pretrained_features[x])
        for x in range(10, 12):
            self.slice5.add_module(str(x), alexnet_pretrained_features[x])
        if not requires_grad:
            for param in self.parameters():
                param.requires_grad = False 
开发者ID:BCV-Uniandes,项目名称:SMIT,代码行数:25,代码来源:pretrained_networks.py

示例10: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def __init__(self, images, model_key, layer, batch_size=256):
        super().__init__(images, batch_size)
        self.models = {
            "alexnet": models.alexnet,
            "squeezenet": models.squeezenet1_1,
            "googlenet": models.googlenet
        }
        self.preprocessors = {
            "alexnet": self.__preprocess_alexnet,
            "squeezenet": self.__preprocess_squeezenet,
            "googlenet": self.__preprocess_googlenet
        }
        self.batch_size = batch_size
        self.layer = layer
        self.model_key = model_key

        self.model, self.feature_layer, self.output_size = self.__build_model(
            layer) 
开发者ID:DeepSpectrum,项目名称:DeepSpectrum,代码行数:20,代码来源:extractor.py

示例11: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def __init__(self):
        super(AlexNetFc, self).__init__()
        model_alexnet = models.alexnet(pretrained=True)
        self.features = model_alexnet.features
        self.classifier = nn.Sequential()
        for i in range(6):
            self.classifier.add_module(
                "classifier"+str(i), model_alexnet.classifier[i])
        self.__in_features = model_alexnet.classifier[6].in_features 
开发者ID:jindongwang,项目名称:transferlearning,代码行数:11,代码来源:backbone.py

示例12: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def __init__(self):
        super(AlexNetFc, self).__init__()
        model_alexnet = models.alexnet(pretrained=True)
        self.features = model_alexnet.features
        self.classifier = nn.Sequential()
        for i in range(6):
            self.classifier.add_module("classifier"+str(i), model_alexnet.classifier[i]) 
开发者ID:jindongwang,项目名称:transferlearning,代码行数:9,代码来源:backbone.py

示例13: get_example_params

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def get_example_params(example_index):
    """
        Gets used variables for almost all visualizations, like the image, model etc.

    Args:
        example_index (int): Image id to use from examples

    returns:
        original_image (numpy arr): Original image read from the file
        prep_img (numpy_arr): Processed image
        target_class (int): Target class for the image
        file_name_to_export (string): File name to export the visualizations
        pretrained_model(Pytorch model): Model to use for the operations
    """
    # Pick one of the examples
    example_list = (('../input_images/snake.jpg', 56),
                    ('../input_images/cat_dog.png', 243),
                    ('../input_images/spider.png', 72))
    img_path = example_list[example_index][0]
    target_class = example_list[example_index][1]
    file_name_to_export = img_path[img_path.rfind('/')+1:img_path.rfind('.')]
    # Read image
    original_image = Image.open(img_path).convert('RGB')
    # Process image
    prep_img = preprocess_image(original_image)
    # Define model
    pretrained_model = models.alexnet(pretrained=True)
    return (original_image,
            prep_img,
            target_class,
            file_name_to_export,
            pretrained_model) 
开发者ID:CMU-CREATE-Lab,项目名称:deep-smoke-machine,代码行数:34,代码来源:viz_functional.py

示例14: get_params

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def get_params(example_index):
    """
        Gets used variables for almost all visualizations, like the image, model etc.

    Args:
        example_index (int): Image id to use from examples

    returns:
        original_image (numpy arr): Original image read from the file
        prep_img (numpy_arr): Processed image
        target_class (int): Target class for the image
        file_name_to_export (string): File name to export the visualizations
        pretrained_model(Pytorch model): Model to use for the operations
    """
    # Pick one of the examples
    example_list = [['../input_images/apple.JPEG', 948],
                    ['../input_images/eel.JPEG', 390],
                    ['../input_images/bird.JPEG', 13]]
    selected_example = example_index
    img_path = example_list[selected_example][0]
    target_class = example_list[selected_example][1]
    file_name_to_export = img_path[img_path.rfind('/')+1:img_path.rfind('.')]
    # Read image
    original_image = cv2.imread(img_path, 1)
    # Process image
    prep_img = preprocess_image(original_image)
    # Define model
    pretrained_model = models.alexnet(pretrained=True)
    return (original_image,
            prep_img,
            target_class,
            file_name_to_export,
            pretrained_model) 
开发者ID:utkuozbulak,项目名称:pytorch-cnn-adversarial-attacks,代码行数:35,代码来源:misc_functions.py

示例15: __init__

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import alexnet [as 别名]
def __init__(self, opt):
        super(AlexGaze, self).__init__()
        self.features = nn.Sequential(
            *list(models.alexnet(pretrained=True).features.children())
        )
        self.relu = nn.ReLU()
        self.sigmoid = nn.Sigmoid()

        self.fc1 = nn.Linear(9216, 500)
        self.fc2 = nn.Linear(669, 400)
        self.fc3 = nn.Linear(400, 200)
        self.fc4 = nn.Linear(200, 169)

        self.finalconv = nn.Conv2d(1, 1, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) 
开发者ID:rohitgajawada,项目名称:Where-are-they-looking-PyTorch,代码行数:16,代码来源:gazenet.py


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