当前位置: 首页 > wzjs >正文

网站开发的三个流程深圳网站设计x程序

网站开发的三个流程,深圳网站设计x程序,百度的竞价排名是哪种方式,软件专利怎么申请知识点回顾: 预训练的概念常见的分类预训练模型图像预训练模型的发展史预训练的策略预训练代码实战:resnet18 作业: 尝试在cifar10对比如下其他的预训练模型,观察差异,尽可能和他人选择的不同尝试通过ctrl进入resnet的…

知识点回顾:

  1. 预训练的概念
  2. 常见的分类预训练模型
  3. 图像预训练模型的发展史
  4. 预训练的策略
  5. 预训练代码实战:resnet18

作业:

  1. 尝试在cifar10对比如下其他的预训练模型,观察差异,尽可能和他人选择的不同
  2. 尝试通过ctrl进入resnet的内部,观察残差究竟是什么 

一、在 CIFAR10 上对比如下其他的预训练模型

可以选择不同的预训练模型,如 VGG16、Inception V3 等,对比它们在 CIFAR10 数据集上的训练时间、准确率等指标。以下是使用 VGG16 的示例代码:

import torch
import torch.nn as nn
import torch.optim as optim
import torchvision
import torchvision.transforms as transforms
from torchvision.models import vgg16# 数据预处理
transform = transforms.Compose([transforms.Resize((224, 224)),  # Inception 和 VGG 要求输入图像大小为 224x224transforms.ToTensor(),transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])# 加载 CIFAR10 数据集
trainset = torchvision.datasets.CIFAR10(root='./data', train=True,download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=4,shuffle=True, num_workers=2)testset = torchvision.datasets.CIFAR10(root='./data', train=False,download=True, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=4,shuffle=False, num_workers=2)# 加载预训练的 VGG16 模型
model = vgg16(pretrained=True)
num_ftrs = model.classifier[6].in_features
model.classifier[6] = nn.Linear(num_ftrs, 10)  # 修改最后一层全连接层以适应 CIFAR10 的 10 个类别# 定义损失函数和优化器
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(model.parameters(), lr=0.001, momentum=0.9)# 训练模型
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model.to(device)for epoch in range(2):  # 训练 2 个 epochrunning_loss = 0.0for i, data in enumerate(trainloader, 0):inputs, labels = data[0].to(device), data[1].to(device)optimizer.zero_grad()outputs = model(inputs)loss = criterion(outputs, labels)loss.backward()optimizer.step()running_loss += loss.item()if i % 2000 == 1999:    # 每 2000 个 mini-batches 打印一次print(f'[{epoch + 1}, {i + 1:5d}] loss: {running_loss / 2000:.3f}')running_loss = 0.0print('Finished Training')

 二、尝试通过 ctrl 进入 ResNet 的内部,观察残差究竟是什么

在 PyTorch 中,如果你使用的是 PyCharm 等 IDE,可以按住 Ctrl 键并点击 resnet18 函数,进入 torchvision.models.resnet 模块。在该模块中,可以找到 BasicBlock 类,它实现了 ResNet 的残差块。

class BasicBlock(nn.Module):expansion = 1def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1,base_width=64, dilation=1, norm_layer=None):super(BasicBlock, self).__init__()if norm_layer is None:norm_layer = nn.BatchNorm2dif groups != 1 or base_width != 64:raise ValueError('BasicBlock only supports groups=1 and base_width=64')if dilation > 1:raise NotImplementedError("Dilation > 1 not supported in BasicBlock")# Both self.conv1 and self.downsample layers downsample the input when stride != 1self.conv1 = conv3x3(inplanes, planes, stride)self.bn1 = norm_layer(planes)self.relu = nn.ReLU(inplace=True)self.conv2 = conv3x3(planes, planes)self.bn2 = norm_layer(planes)self.downsample = downsampleself.stride = stridedef forward(self, x):identity = xout = self.conv1(x)out = self.bn1(out)out = self.relu(out)out = self.conv2(out)out = self.bn2(out)if self.downsample is not None:identity = self.downsample(x)out += identity  # 这一行实现了残差连接out = self.relu(out)return out

在 forward 方法中, out += identity 这一行实现了残差连接。 identity 是输入的原始特征图, out 是经过两层卷积和批量归一化处理后的特征图,将它们相加后再通过 ReLU 激活函数,使得模型可以学习到输入和输出之间的残差信息。


文章转载自:

http://nAjxDpe4.ybgdL.cn
http://lp6wTbdu.ybgdL.cn
http://luyHsCod.ybgdL.cn
http://X2mtwjYM.ybgdL.cn
http://HLWVFkYj.ybgdL.cn
http://eZdWGO0B.ybgdL.cn
http://u7NesVix.ybgdL.cn
http://uSWLJUG3.ybgdL.cn
http://kZHT4jeJ.ybgdL.cn
http://qMJNaqta.ybgdL.cn
http://Bdu3YmdK.ybgdL.cn
http://lIvwVyx3.ybgdL.cn
http://22CCv0bE.ybgdL.cn
http://7VwNUAoM.ybgdL.cn
http://ZkjjAUDu.ybgdL.cn
http://rnmEUkZ2.ybgdL.cn
http://NsyuqZxm.ybgdL.cn
http://RxAgQqWz.ybgdL.cn
http://wMIqvxtS.ybgdL.cn
http://CPn0tYjh.ybgdL.cn
http://3i1vJGVe.ybgdL.cn
http://wZJtdROY.ybgdL.cn
http://VlZg3Jw5.ybgdL.cn
http://OKLod4ql.ybgdL.cn
http://dc5TmOfn.ybgdL.cn
http://9BhCkkub.ybgdL.cn
http://2fhPXTq9.ybgdL.cn
http://xxiuBOr3.ybgdL.cn
http://Ddb9pa6q.ybgdL.cn
http://rFlNpYTo.ybgdL.cn
http://www.dtcms.com/wzjs/661099.html

相关文章:

  • 多功能网站建设服务至上办公邮箱最常用的是什么邮箱
  • 建设部网站官网四库一平台自己做的网站可以买东西吗
  • 深圳网站建设服务有限公司苏州建设网站公司
  • 网站制作软件品牌商城网站建设公司
  • 游戏门户网站 织梦学网站建设需要几年
  • 浦项建设中国有限公司网站优就业seo
  • 营销型网站的付费推广渠道搭建网站建设
  • 嘉兴外贸网站建昆山建设局网站查预售
  • 成都新线加做网站建筑模板规格尺寸及价格
  • 织梦网站程序wordpress交流
  • 官方购物网站正品国家建筑工程信息平台
  • 关于电商网站规划方案关于网站建设方案的案例
  • 免费单页网站在线制作自己在家做电商
  • 婚纱网站建设 最开始俄罗斯跨境电商平台ozon
  • 佛山建设公司网站网站布局设计分析特点
  • 设计网站界面工程项目信息网
  • 怎么样查看网站开发语言端点seo博客
  • 北京国贸网站建设公司动画制作软件an
  • 已有域名怎么做网站洛阳网络公司排名
  • 网站推广的途径和要点个人网站制作与设计论文
  • 移动网站技术建设工程公司组织架构图
  • 自助网站开发海外营销公司
  • 网站前台怎么做凡客官网旗舰店
  • 个人博客网站制作流程文件夹里内容做网站的分类
  • 驻马店北京网站建设wordpress 无广告视频
  • 怎样在建设部网站上查公司信息佛山网站建设哪个
  • 网站建设编码公司网站图片传不上去
  • 北京海淀工商局网站阳江人才招聘网官网
  • 在凡科做网站本地网站做不大
  • 自己可以做百度网站吗佛山推广系统