赞
踩
AlexNet网络是 Hinton及其学生Alex Krizhevsky在ImageNet ILSVRC-2012竞赛中在 ILSVRC-2010数据上的的冠军网络,论文 "ImageNet Classifification with Deep Convolutional Neural Networks",该网络在大规模对象识别上取得的成功也掀起了深度学习的热潮。
AlexNet亮点:使用ReLU作为激活函数,提出LRN机制,Dropout随机失活,重叠Pooling,CUDA并行训练及数据增强
原文中使用了3维卷积核,卷积核维度增加
原作者使用双GPU进行并行参数训练,将特征图从通道数层面进行分离,故以下通道数是上图的并行通道数之和
input layer:224*224*3 images
conv1 layer:11*11*3(3维卷积核)* 96, 4 conv kernels 55*55*96 ouput ( (224 + 0 - 11) / 4 +1 = 54.25 )
pool1 layer:3*3, 2 overlap maxpool 27*27*96 output ( (55 - 3) / 2 + 1 = 27 )
conv2 layer:5*5*48* 256 conv kernels(2pad) 27*27*256 output ( 27 + 2*2 - 5 + 1 = 27 )
pool2 layer:3*3, 2 overlap maxpool 13*13*256 output ( (27 - 3) / 2 + 1 =13 )
conv3 layer:3*3*256* 384 conv kernels(1pad) 13*13*384 output ( 13 + 1*2 - 3 + 1 = 13 )
conv4 layer:3*3*192* 384 conv kernels(1pad) 13*13*384 output ( 13 + 1*2 - 3 + 1 = 13 )
conv5 layer:3*3*192* 256 conv kernels(1pad) 13*13*256 output ( 13 + 1*2 - 3 + 1 = 13 )
pool3 layer:3*3, 2 overlap maxpool 6*6*256 output ( (13 - 3) / 2 + 1 =6 )
fc1 layer: 4096 output( 13*13*256 --> 4096 )
fc2 layer: 4096 output( 4096 --> 4096 )
fc3 layer: 1000 output( 4096 --> 1000 )
以上代码在alexnet的基础上,实现了:
1)调用框架api读取数据集
2)进行train、val的流程
3)在train时可以输出各层shape
4)保存最优loss模型,并在结束时输出最优loss及对应epoch
5)在训练结束后查看loss、acc变化曲线
源网络使用224作为输入,这里使用227作为输入;源网络使用3维卷积,这里仍使用2维卷积
源数据:ImageNet LSVRC-2010,1000类,120万张训练图片、5万测试、15万验证
mini-imagenet数据:来自:https://blog.csdn.net/weixin_41803874/article/details/92068250
实验数据:从mini-imagenet随机选取10类,每类随机选取100张图片,共1000张图片作为数据集
(实验数据在resnet18(pretrained=True)条件下进行迁移学习,训练2epoch可以val达到0.9准确率,在resnet18(pretrained=False)条件下训练,100epoch val acc始终处于0.35acc,无法收敛(尝试调整学习率无果),大致说明数据可以收敛但从零训练效果差;在实现的alexnet代码中,pytorch版本在val acc达到0.30左右后开始减小停止收敛,tensorflow、keras版本无法收敛,paddle版本可以收敛到0.60左右)
文件结构:创建my_utils.py文件存放通用函数
从mini-imagenet中提取10*100数据(非必要)
- # -*- coding: utf-8 -*-
- # @Time : 2020/1/21 15:20
- # @Author : Zhao HL
- # @File : data_process.py
- import os,random,shutil
- import numpy as np
- import pandas as pd
-
- #region 类名转换文档
- cls_dict_path = r'D:\__Download\百度\caffe_ilsvrc12\synset_words.txt'
- # endregion
-
- #region mimi 数据集文档及信息
- # csv_path = r'D:\__Download\百度\mini-imagenet\test.csv'
- # csv_path = r'D:\__Download\百度\mini-imagenet\train.csv'
- csv_path = r'D:\__Download\百度\mini-imagenet\val.csv'
- src_data_path = r'D:\__Download\百度\mini-imagenet\images'
- '''
- train.csv contain 38400 records, 64 classes
- test.csv contain 12000 records, 20 classes
- val.csv contain 9600 records, 16 classes
- '''
- # endregion
- # region 目标文件
- dst_data_path = r'D:\__Download\百度\my_imagenet'
- dst_csv_path = r'D:\__Download\百度\my_imagenet.csv'
- # endregion
-
- def get_csvInfo():
- df = pd.read_csv(csv_path)
- total_num = len(df)
- class_num = len(df['label'].unique())
- print('{} contain {} records, {} classes '.format(os.path.basename(csv_path),total_num,class_num))
-
- def Extract_Image():
- # 从val文件中选取10个类,每个类选取100样本
- df = pd.read_csv(csv_path)
- cls = df['label'].unique()
- dst_cls = random.sample(list(cls),10)
- df_list = []
- for cls in dst_cls:
- print('cls {} :'.format(cls))
- df_cls = df[df['label']==cls]
- dst_df_cls = df_cls.sample(100)
- df_list.append(dst_df_cls)
- dst_df = pd.concat(df_list,ignore_index=True)
-
- for i,filename in enumerate(dst_df['filename']):
- src_path = os.path.join(src_data_path,filename)
- dst_path = os.path.join(dst_data_path,filename)
- shutil.copy(src_path,dst_path)
- print(i,filename)
- dst_df.to_csv(dst_csv_path)
-
-
- if __name__ == '__main__':
- pass
- # get_csvInfo()
- Extract_Image()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。