---
title: CIFAR-10 tutorial
category: example
description: Train and test Caffe on CIFAR-10 data.
include_in_docs: true
priority: 5
---
Alex's CIFAR-10 tutorial, Caffe style
=====================================
Alex Krizhevsky's [cuda-convnet](https://code.google.com/p/cuda-convnet/) details the model definitions, parameters, and training procedure for good performance on CIFAR-10. This example reproduces his results in Caffe.
We will assume that you have Caffe successfully compiled. If not, please refer to the [Installation page](/installation.html). In this tutorial, we will assume that your caffe installation is located at `CAFFE_ROOT`.
We thank @chyojn for the pull request that defined the model schemas and solver configurations.
*This example is a work-in-progress. It would be nice to further explain details of the network and training choices and benchmark the full training.*
Prepare the Dataset
-------------------
You will first need to download and convert the data format from the [CIFAR-10 website](http://www.cs.toronto.edu/~kriz/cifar.html). To do this, simply run the following commands:
cd $CAFFE_ROOT
./data/cifar10/get_cifar10.sh
./examples/cifar10/create_cifar10.sh
If it complains that `wget` or `gunzip` are not installed, you need to install them respectively. After running the script there should be the dataset, `./cifar10-leveldb`, and the data set image mean `./mean.binaryproto`.
The Model
---------
The CIFAR-10 model is a CNN that composes layers of convolution, pooling, rectified linear unit (ReLU) nonlinearities, and local contrast normalization with a linear classifier on top of it all. We have defined the model in the `CAFFE_ROOT/examples/cifar10` directory's `cifar10_quick_train_test.prototxt`.
Training and Testing the "Quick" Model
--------------------------------------
Training the model is simple after you have written the network definition protobuf and solver protobuf files (refer to [MNIST Tutorial](../examples/mnist.html)). Simply run `train_quick.sh`, or the following command directly:
cd $CAFFE_ROOT
./examples/cifar10/train_quick.sh
`train_quick.sh` is a simple script, so have a look inside. The main tool for training is `caffe` with the `train` action, and the solver protobuf text file as its argument.
When you run the code, you will see a lot of messages flying by like this:
I0317 21:52:48.945710 2008298256 net.cpp:74] Creating Layer conv1
I0317 21:52:48.945716 2008298256 net.cpp:84] conv1 <- data
I0317 21:52:48.945725 2008298256 net.cpp:110] conv1 -> conv1
I0317 21:52:49.298691 2008298256 net.cpp:125] Top shape: 100 32 32 32 (3276800)
I0317 21:52:49.298719 2008298256 net.cpp:151] conv1 needs backward computation.
These messages tell you the details about each layer, its connections and its output shape, which may be helpful in debugging. After the initialization, the training will start:
I0317 21:52:49.309370 2008298256 net.cpp:166] Network initialization done.
I0317 21:52:49.309376 2008298256 net.cpp:167] Memory required for Data 23790808
I0317 21:52:49.309422 2008298256 solver.cpp:36] Solver scaffolding done.
I0317 21:52:49.309447 2008298256 solver.cpp:47] Solving CIFAR10_quick_train
Based on the solver setting, we will print the training loss function every 100 iterations, and test the network every 500 iterations. You will see messages like this:
I0317 21:53:12.179772 2008298256 solver.cpp:208] Iteration 100, lr = 0.001
I0317 21:53:12.185698 2008298256 solver.cpp:65] Iteration 100, loss = 1.73643
...
I0317 21:54:41.150030 2008298256 solver.cpp:87] Iteration 500, Testing net
I0317 21:54:47.129461 2008298256 solver.cpp:114] Test score #0: 0.5504
I0317 21:54:47.129500 2008298256 solver.cpp:114] Test score #1: 1.27805
For each training iteration, `lr` is the learning rate of that iteration, and `loss` is the training function. For the output of the testing phase, **score 0 is the accuracy**, and **score 1 is the testing loss function**.
And after making yourself a cup of coffee, you are done!
I0317 22:12:19.666914 2008298256 solver.cpp:87] Iteration 5000, Testing net
I0317 22:12:25.580330 2008298256 solver.cpp:114] Test score #0: 0.7533
I0317 22:12:25.580379 2008298256 solver.cpp:114] Test score #1: 0.739837
I0317 22:12:25.587262 2008298256 solver.cpp:130] Snapshotting to cifar10_quick_iter_5000
I0317 22:12:25.590215 2008298256 solver.cpp:137] Snapshotting solver state to cifar10_quick_iter_5000.solverstate
I0317 22:12:25.592813 2008298256 solver.cpp:81] Optimization Done.
Our model achieved ~75% test accuracy. The model parameters are stored in binary protobuf format in
cifar10_quick_iter_5000
which is ready-to-deploy in CPU or GPU mode! Refer to the `CAFFE_ROOT/examples/cifar10/cifar10_quick.prototxt` for the deployment model definition that can be called on new data.
Why train on a GPU?
-------------------
CIFAR-10, while still small, has enough data to make GPU training attractive.
To compare CPU vs. GPU training speed, simply change one line in all the `cifar*solver.prototxt`:
# solver mode: CPU or GPU
solver_mode: CPU
and you will be using CPU for training.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip 深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip
资源推荐
资源详情
资源评论
收起资源包目录
深度学习之神经网络核心原理与算法-课程学习相关代码合集.zip (110个子文件)
create_cifar10.bat 386B
BUILD 3KB
BUILD 2KB
convert_cifar_data.cpp 4KB
mnist.pkl.gz 16.26MB
keras_cifar10_trained_model.h5 9.59MB
NeuralNetworksGetStarted.iml 780B
readme.md 5KB
README.md 4KB
README.md 624B
cifar10_full_sigmoid_train_test_bn.prototxt 3KB
cifar10_full_train_test.prototxt 3KB
cifar10_quick_train_test.prototxt 3KB
cifar10_full_sigmoid_train_test.prototxt 3KB
cifar10_full.prototxt 2KB
cifar10_quick.prototxt 2KB
cifar10_full_sigmoid_solver_bn.prototxt 959B
cifar10_full_sigmoid_solver.prototxt 953B
cifar10_full_solver_lr2.prototxt 945B
cifar10_full_solver_lr1.prototxt 944B
cifar10_full_solver.prototxt 944B
cifar10_quick_solver_lr1.prototxt 882B
cifar10_quick_solver.prototxt 829B
image_ocr.py 21KB
mnist_net2net.py 16KB
cifar10.py 14KB
cifar10_resnet.py 14KB
neural_doodle.py 13KB
4-11 ConvolutionalNeuralNetwork_mnist(gpu).py 13KB
mnist_acgan.py 13KB
cifar10_multi_gpu_train.py 10KB
neural_style_transfer.py 10KB
cifar10_input.py 10KB
4-10 SoftmaxLayer.py 10KB
fully_connected_feed.py 10KB
mnist_tfrecord.py 9KB
lstm_seq2seq.py 9KB
4-6 ConvPoolLayer.py 9KB
babi_rnn.py 9KB
mnist_with_summaries.py 8KB
babi_memnn.py 8KB
cifar10_cnn_capsule.py 8KB
lstm_stateful.py 8KB
mnist_swwae.py 7KB
3-12 neural_network_mnist_v2.py 7KB
4-2 neural_network_mnist_v3(gpu).py 7KB
cifar10_cnn_tfaugment2d.py 7KB
addition_rnn.py 7KB
variational_autoencoder_deconv.py 7KB
3-11 save_load_model.py 6KB
deep_dream.py 6KB
mnist_deep.py 6KB
3-10 cross_entropy.py 6KB
lstm_seq2seq_restore.py 6KB
reuters_mlp_relu_vs_selu.py 6KB
cifar10_eval.py 5KB
mnist.py 5KB
conv_lstm.py 5KB
mnist_loader.py 5KB
3-7 L2_regularization.py 5KB
2-9 back_propagation.py 5KB
3-5 initialization_parameters.py 5KB
pretrained_word_embeddings.py 5KB
imdb_fasttext.py 5KB
mnist_denoising_autoencoder.py 5KB
2-12 neural_network_mnist.py 4KB
cifar10_train.py 4KB
mnist_siamese.py 4KB
conv_filter_visualization.py 4KB
cifar10_cnn.py 4KB
mnist_dataset_api.py 4KB
mnist_sklearn_wrapper.py 4KB
2-11 stochasticgradient_descent.py 4KB
mnist_softmax_xla.py 4KB
mnist_transfer_cnn.py 4KB
variational_autoencoder.py 3KB
lstm_text_generation.py 3KB
antirectifier.py 3KB
5-7 save_load_model_v2(tf).py 3KB
mnist_hierarchical_rnn.py 3KB
5-4 tf_LinearRegression.py 3KB
mnist_softmax.py 3KB
2-7 forward_propagation.py 3KB
5-6 TensorBoard_Get_Started.py 2KB
mnist_irnn.py 2KB
cifar10_input_test.py 2KB
mnist_cnn.py 2KB
2.1-simple_network.py 2KB
imdb_cnn.py 2KB
imdb_cnn_lstm.py 2KB
reuters_mlp.py 2KB
imdb_lstm.py 2KB
mnist_mlp.py 2KB
imdb_bidirectional_lstm.py 1KB
1-numpy_basic.py 1KB
input_data.py 1KB
__init__.py 979B
5-1 TensorFlow_Get_Started.py 950B
__init__.py 899B
train_full.sh 524B
共 110 条
- 1
- 2
资源评论
土豆片片
- 粉丝: 1838
- 资源: 5654
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功