Caffe easy to get started Guide (i)--run CIFAR example

Source: Internet
Author: User

Brief introduction

Caffe is a friendly, easy-to-use, open-source deep learning platform, mainly used for image related processing, can support a variety of deep learning networks such as CNN.

Based on Caffe, developers can easily and quickly develop a simple learning network for classification, positioning and other tasks, but also for scientific research, in its source code based on the modification, to achieve their own algorithm.

The main purpose of this paper is to introduce the basic use of Caffe, hoping that through this article, ordinary engineers can use Caffe to train their own simple models.

This article mainly includes the following: the example of running Caffe training Cifar training set, using other people's defined network to train their own data, using a well-trained model fine tune their own data.

Introduction to Background knowledge

Deep learning is a branch of machine learning, and the main goal is to solve the problems that can not be solved by common programming by means of learning, such as image recognition, character recognition and so on.

"Learning" in machine learning means that by inputting empirical data into a program, through several iterations, the algorithm parameters are continuously improved, the model can be obtained, and the desired results are calculated using the new data input model.

Example of a classification task, the empirical data is a picture and the corresponding text, after training the model, the new picture using the model operation, you can know its corresponding category.

This is just a brief introduction, it is recommended to learn the basic knowledge of machine learning, convolutional neural network first.

Installation

This part of the web has a lot of tutorials, this is slightly off, in addition, I am using the Docker image directly installed, online can directly search the Docker image with Caffe. The advantage is the time to save the installation environment, the disadvantage is that the later set up the file will be more trouble, it is recommended to long-time or directly installed on the computer.

Training Cifar Training Set

Cifar is a common image classification training set, including tens of thousands of images and 20 categories, Caffe provides a network for classifying Cifar datasets.

The definition of CIFAR network in the EXAMPLES/CIFAR10 directory, the training process is very simple.

(The following commands are run under the Caffe default root directory, same as below)

1. Get Training data

CD $CAFFE _root. /data/cifar10/get_cifar10. SH . /examples/cifar10/create_cifar10. SH

2. Start training

CD $CAFFE _root. /examples/cifar10/train_quick. SH

3, after the completion of training we will get:

Cifar10_quick_iter_4000.caffemodel.h5

Cifar10_quick_iter_4000.solverstate.h5

At this point, we trained to get the model for the later classification.

4, below we use the model to classify new data

Let's start with someone else's model classification: (Default imagenet model)

Python python/classify.py examples/images/cat. jpg foo

Let's specify our own model to classify:

Python python/classify.py--model_def examples/cifar10/cifar10_quick.prototxt--pretrained_model examples/cifar10/ Cifar10_quick_iter_4000.caffemodel.h5--center_only  examples/images/cat. jpg foo

The above phrase means using the Cifar10_quick.prototxt Network + CIFAR10_QUICK_ITER_4000.CAFFEMODEL.H5 model to classify the examples/images/cat.jpg images.

The default classify script does not directly output the results, but will input the results into the Foo file, not too intuitive, here I found a modified version of the Web, add some parameters, you can output the highest probability classification.

Replace python/classify.py,:http://download.csdn.net/detail/caisenchuan/9513196

This script adds two parameters, you can specify Labels_file, and then you can output the classification results directly:

--print_results --labels_file data/cifar10/cifar10_words.txt  --center_only  examples/images/cat. jpg foo

Output Result:

Loadingfile: examples/images/Cat. jpgclassifying1inputs.predict3inputs. Doneinch 0.02s.predictions: [[0.03903743  0.00722749  0.04582177  0.44352672  0.01203315  0.11832549   0.02335102  0.25013766  0.03541689  0.02512246]]python/classify.py:176: futurewarning:Sort(columns= ...) is deprecated, use sort_values (by=.....) Labels= Labels_df.Sort('synset_id')['name'].values[( 'Cat','0.44353'), ('Horse','0.25014'), ('Dog','0.11833'), ('Bird','0.04582'), ('Airplane','0.03904' )] the order and confidence of each category are indicated above
Saving results into Foo

Caffe easy to get started Guide (i)--run CIFAR example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.