神经网络----现有网络的下载和使用(vgg16)

 以下两种方法已经用不了

vgg16_false = torchvision.models.vgg16(pretrained=False)
vgg16_true = torchvision.models.vgg16(pretrained=True)

改为

vgg16_model0 = vgg16(weights=None)  #vgg16_false
vgg16_model1 = vgg16(weights=VGG16_Weights.DEFAULT)  # pretrained vgg16_true
import torchvision
from torch import nn
from torchvision.models import vgg16, VGG16_Weights

# 以下注释的两行用不了,现在更新了新方法
# vgg16_false = torchvision.models.vgg16(pretrained=False) 
# vgg16_true = torchvision.models.vgg16(pretrained=True)

vgg16_model0 = vgg16(weights=None)  #vgg16_false
vgg16_model1 = vgg16(weights=VGG16_Weights.DEFAULT)  # pretrained vgg16_true
# vgg16_model2 = vgg16(weights=VGG16_Weights.IMAGENET1K_V1)  # 代表使用IMAGENET1K_V1方法训练
# print(vgg16_model1)
train_data = torchvision.datasets.CIFAR10(root='./dataset', train=False, transform=torchvision.transforms.ToTensor(),
                                       download=True)

print('---------------增加一层--------------------------------------------------    ----')
# vgg16_model1.add_module('add_liner', nn.Linear(1000, 10))
# print(vgg16_model1)
print('--------------在classifier里-增加一层--------------------------------- -----------')
vgg16_model1.classifier.add_module('add_liner', nn.Linear(1000, 10))
print(vgg16_model1)

print('-------------------未修改的vgg16--------------------------------------------------')
print(vgg16_model0)
print('-------------------将vgg16的classifier的第6层进行修改-------------------------------')
vgg16_model0.classifier[6] = nn.Linear(4096, 10)
print(vgg16_model0)

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-10 09:16:07       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-10 09:16:07       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-10 09:16:07       82 阅读
  4. Python语言-面向对象

    2024-06-10 09:16:07       91 阅读

热门阅读

  1. 1数据库网课笔记

    2024-06-10 09:16:07       28 阅读
  2. 华为策略流控

    2024-06-10 09:16:07       32 阅读
  3. 设计模式-原型模式

    2024-06-10 09:16:07       27 阅读
  4. (20)DAC接口--->(005)FPGA实现AD5601接口(五)

    2024-06-10 09:16:07       30 阅读
  5. Set up a WordPress blog with Nginx

    2024-06-10 09:16:07       29 阅读
  6. 为什么选择Python作为AI开发语言

    2024-06-10 09:16:07       29 阅读
  7. 数字化那点事:一文读懂智慧城市

    2024-06-10 09:16:07       32 阅读
  8. unity中常见的角色控制方法

    2024-06-10 09:16:07       36 阅读