# Implementation of AlexNet
- ! ! ! It needs an evaluation on ImageNet
This project is an unofficial implementation of AlexNet, using C Program Language Without Any 3rd Library, according to the paper "ImageNet Classification with Deep Convolutional Neural Networks" by Alex Krizhevsky,et al.
**Only support CPU now**
## Platform support
+ Linux
+ Windows with MinGW-w64(build pass but can not load images yet)
## Features
- **Effective matrix multiply**, w.r.t L1/L2 cache
- **img2col** implementation of convolutional layer
- **Multi-thread CPU** Apply MT in operator's forward computation and backward computation to boost speed
- **Efficient Memory Usage & Minimal Memory Occupation** Memory is allocated on demand for efficient memory usage. If an array isn't necessary for computations afterward, it's memory will be freed instantly to minimize memory occupation.
- **Modular layer** Define each layer seperately
## Architecture
```
----------------------------------------------------------------
Layer Output Shape Param #
================================================================
Conv2d-1 [N, 64, 55, 55] 23,296
ReLU-2 [N, 64, 55, 55] 0
MaxPool2d-3 [N, 64, 27, 27] 0
Conv2d-4 [N, 192, 27, 27] 307,392
ReLU-5 [N, 192, 27, 27] 0
MaxPool2d-6 [N, 192, 13, 13] 0
Conv2d-7 [N, 384, 13, 13] 663,936
ReLU-8 [N, 384, 13, 13] 0
Conv2d-9 [N, 256, 13, 13] 884,992
ReLU-10 [N, 256, 13, 13] 0
Conv2d-11 [N, 256, 13, 13] 590,080
ReLU-12 [N, 256, 13, 13] 0
MaxPool2d-13 [N, 256, 6, 6] 0
Dropout-14 [N, 9216] 0
Linear-15 [N, 4096] 37,752,832
ReLU-16 [N, 4096] 0
Dropout-17 [N, 4096] 0
Linear-18 [N, 4096] 16,781,312
ReLU-19 [N, 4096] 0
Linear-20 [N, 1000] 4,097,000
================================================================
("N" stands for "batch size")
Total params: 61,100,840
Trainable params: 61,100,840
Non-trainable params: 0
----------------------------------------------------------------
```
## Usage
### Install
```
git clone git@github.com:Dynmi/AlexNet.git
cd AlexNet
mkdir build && cd build
cmake .. & make -j8
```
### Train
( The data loader only supports ```.jpeg``` and ```.png$``` images now. For image dataset, go to [http://www.image-net.org/](http://www.image-net.org/))
1. Create file ```images.list``` in the directory ```./```, each line contains info of one image,
like this: ```class_id image_path``` .
For example:
```
0 /home/haris/Documents/AlexNet/images/0/1.jpeg
1 /home/haris/Documents/AlexNet/images/1/1.jpeg
2 /home/haris/Documents/AlexNet/images/2/1.jpeg
3 /home/haris/Documents/AlexNet/images/3/1.jpeg
4 /home/haris/Documents/AlexNet/images/4/1.jpeg
5 /home/haris/Documents/AlexNet/images/5/1.jpeg
```
or you can generate `images.list` by using `cs gen_list.csc <PATH of your Images>`
2. Run the command for training
```
./alexnet train -batchsize <batch-size> -epochs <epochs> -load_pretrained <weights-path> -save <weights-path>
```
For example:
```
./alexnet train -batchsize 8 -epochs 10 -load_pretrained ./alexnet_pretrained.weights -save ./temp.weights
```
### Inference
```
$./alexnet inference -input <image-path> -load <weights-path>
```
For example:
```
./alexnet inference -input ./0001.jpeg -load ./alexnet_pretrained.weights
```
## Todo List
- [ ] **Try & Compare on ImageNet**
- [ ] **CUDA speed boosting**
## Speed Benchmark for Ops
Experiments were done on a laptop --- Huawei MagicBook14
### Conv2D Forward
| | this | DarkNet |
| ---- | ---- | ---- |
| Scene1 | 0.13s | 0.44s |
| Scene2 | 0.21s | 0.66s |
Scene1: Input shape [4,224,224,3], weight shape [64,3,11,11]
Scene2: Input shape [4,57,57,128], weight shape [256,128,3,3]
### Full-connected Forward
| | this | DarkNet |
| ---- | ---- | ---- |
| Scene1 | 0.07s | 0.24s |
| Scene2 | 0.11s | 0.52s |
Scene1: Input shape [4,2048], weight shape [2048,1024]
Scene2: Input shape [4,4096], weight shape [4096,4096]
## Original AlexNet Details
> divide the learning rate by 10 when the validation error rate stopped improving with the current learning rate.
> The learning rate was initialized at 0.01 and reduced three times prior to termination.
> We trained the network for roughly 90 cycles through the training set of 1.2 million images.
## Reference
- [AlexNet, NIPS2012](https://proceedings.neurips.cc/paper/2012/hash/c399862d3b9d6b76c8436e924a68c45b-Abstract.html)
- [Darknet](https://github.com/AlexeyAB/darknet)
- [PyTorch](https://github.com/pytorch/pytorch)
- https://zhuanlan.zhihu.com/p/131647655
- https://zhuanlan.zhihu.com/p/131647655
- https://github.com/tensorflow/tensorflow/blob/v2.4.0/tensorflow/python/ops/nn_ops.py#L3805-L3865
- https://github.com/pytorch/vision/blob/master/torchvision/models/alexnet.py
没有合适的资源?快使用搜索试试~ 我知道了~
AlexNet:用C卷积神经网络机器学习实现AlexNet计算机视觉
共32个文件
c:11个
h:10个
pdf:4个
需积分: 21 8 下载量 153 浏览量
2021-04-06
07:18:29
上传
评论
收藏 5.4MB ZIP 举报
温馨提示
AlexNet的实现 ! ! ! 需要在ImageNet上进行评估 根据Alex Krizhevsky等人的论文“具有深卷积神经网络的ImageNet分类”,该项目是AlexNet的非官方实现,使用不带任何第3个库的C程序语言。 现在仅支持CPU 平台支援 Linux 带有MinGW-w64的Windows(构建阶段但无法加载图像) 特征 有效矩阵乘法,带L1 / L2高速缓存 img2col卷积层的实现 多线程CPU在操作员的正向计算和反向计算中应用MT来提高速度 高效的内存使用和最少的内存占用可根据需要分配内存,以实现高效的内存使用。 如果此后不需要数组,则将立即释放其内存以最大程度地减少内存占用。 模块化层分别定义每个层 建筑学 ----------------------------------------------------------------
资源详情
资源评论
资源推荐
收起资源包目录
AlexNet-master.zip (32个子文件)
AlexNet-master
others
BatchNorm2014.pdf 311KB
AlexNet_slide_Djordje_Slijepcevic.pdf 1.3MB
NIPS-2012-imagenet-classification-with-deep-convolutional-neural-networks-Paper.pdf 1.35MB
cifar10.py 2KB
Lecture 3 CNN - backpropagation.pdf 2.83MB
torch_alexnet.py 3KB
src
batchnorm_layer.c 4KB
convolution_layer.c 9KB
fc_layer.c 5KB
maxpooling_layer.c 4KB
dropout_layer.c 519B
matrix.c 3KB
activation_layer.c 3KB
inference.c 616B
alexnet.c 24KB
data.c 6KB
train.c 22KB
CMakeLists.txt 465B
LICENSE 1KB
.gitignore 464B
readme.md 5KB
include
dynmi-dnn
stb_image.h 267KB
dropout_layer.h 176B
maxpooling_layer.h 494B
data.h 629B
matrix.h 277B
alexnet.h 2KB
fc_layer.h 652B
convolution_layer.h 845B
activation_layer.h 546B
batchnorm_layer.h 876B
gen_list.csc 271B
共 32 条
- 1
白苏艾
- 粉丝: 33
- 资源: 4608
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C# OpenCvSharp Demo - 最大内接圆.rar
- 基于python和Matlab的爬虫+情感分析+时间序列+长图自动分割项目合集(高分项目).zip
- ME2308-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 使用Java实现的基于最小生成树的旅行商问题.zip
- ME2308D-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 数据并行C++(Data Parallel C++) 英文版
- MongoDB数据库操作和面试专题及答案.zip
- C#实现通用USB摄像头的读取,拍照,视频录制等功能
- 基于Python实现的多目标旅行商问题算法优化.zip
- LN2312LT1G-VB一款SOT23封装N-Channel场效应MOS管
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0