深度学习学习笔记
导师博客:https://blog.youkuaiyun.com/qq_37541097/article/details/103482003
导师github:https://github.com/WZMIAOMIAO/deep-learning-for-image-processing
代码用的导师的,自己又加了些备注,就放在自己的github里了:
https://github.com/Petrichor223/Deep_Learning/tree/master
网络结构

网络介绍及结构这一部分导师写的很详细:AlexNet网络结构详解与模型的搭建
数据集介绍
花分类数据集下载:http://download.tensorflow.org/example_images/flower_photos.tgz
训练集和测试集的划分:
参考:https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/tree/master/data_set
下载完成后将压缩包放在data_set文件夹下并解压到新建的flower_data文件夹下,然后再data_set文件夹下按住shift + 右键打开Powershell窗口,在窗口中输入python .\split_data.py去运行脚本,就会按照9:1进行数据集的划分

划分完成后在flower_data文件夹下就会有生成的训练集和验证集

项目文件
AlexNet
├─ model.py
├─ predict.py
├─ train.py
├─ flower_data
1. model.py
Alexnet所有层的参数表:

import torch.nn as nn
import torch
class AlexNet(nn.Module):
def __init__(self, num_classes=1000, init_weights=False): #初始化函数来定义网络在正向传播过程中使用的层结构
super(AlexNet, self).__init__()
# n.Sequential能够将一系列的层结构进行打包组合成新的结构,如果像LeNet那样定义每一层会非常麻烦
self.features = nn.Sequential( #这里对应特征提取
#对照Alexnet所有层参数表进行设配置
nn.Conv2d(3, 48, kernel_size=11, stride=4, padding=2), # input[3, 224, 224] output[48, 55, 55] 由于花分类数据集较小,将卷积核个数减半,为了方便直接将padding设置为2
nn.ReLU(inplace=True), #inplace可以理解为pytorch增加计算量但降低内存使用
nn.MaxPool2d(kernel_size=3, stride=2), # output[48, 27, 27]
nn.Conv2d(48, 128, kernel_size=5, padding=2), # output[128, 27, 27] 这里卷积核个数同样减半,下同
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2), # output[128, 13, 13]
nn.Conv2d(128, 192, kernel_size=3, padding=1), # output[192, 13, 13]
nn.ReLU(inplace=True),
nn.Conv2d(192, 192, kernel_size=3, padding=1), # output[192, 13, 13]
nn.ReLU(inplace=True),
nn.Conv2d(192, 128, kernel_size=3, padding=1), # output[128, 13, 13]
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2), # output[128, 6, 6]
)
self.classifier = nn.Sequential( #将全连接层打包,组合成分类器
nn.Dropout(p=0.5), #一般加载全连接层之间,默认失活比例为0.5
nn.Linear(128 * 6 * 6, 2048),
nn.ReLU(inplace=True),
nn.Dropout(p=0.5),
nn.Linear(2048, 2048),
nn.ReLU(inplace=True),
nn.Linear(2048, num_classes),
)<

本文档详细介绍了使用AlexNet神经网络对花卉图像进行分类的过程,包括数据集划分、网络结构(含参数表)、数据预处理、模型训练和预测。作者基于导师博客和GitHub代码实现了从数据加载到模型评估的完整流程。
最低0.47元/天 解锁文章
986

被折叠的 条评论
为什么被折叠?



