Run your own data with Caffe, Windows-based Caffe

Source: Internet
Author: User

This article describes in detail how to use Caffe to run their own image data for classification.

1 first need to install the process see http://www.cnblogs.com/love6tao/p/5706830.html at the same time, according to the above tutorial, generated Caffe.exe

2 Build your own data set. Divided into train and Val two datasets, this experiment for 2 classification tasks, one is to include the image of the car, one is not included in the car image, where train for training data set, The image naming format in this folder is Trainpos0000.jpg and trainneg0000.jpg, the image is continuously encoded by this naming method, andVal is a validation data set or test data, The image naming format in this folder is Test0000.jpg, and testneg0000.jpg. As shown

The image can be scaled to 256*256 using the Cvresize function in OpenCV.

Then you need to prepare the label data, set by the new Train.txt Val.txt and Test.txt. Automatic generation via Windows command line, first input cmd in run, DOS window, input d: switch to D drive,

Then enter the CD D:\caffe\caffe-master\caffe-master\mydata\train switch to the train folder, enter the command "Dir/s/on/b>d:/train.txt", A text file named train is generated on the D drive, which holds the path to all images. By finding replacements, the resulting train.txt val.txt and test.txt are generated. Where Val.txt and test.txt are compared, test has no label

3 The data type of the data set converted to Caffe

Caffe's data types are Lmdb and Leveldb,caffe do not process raw data, but instead convert to Lmdb or LEVELDB format, which can maintain high IO efficiency.

How to convert it? In the Caffe project has the Convert_imageset project, compiles it, forms the convert_imageset.exe to be able.

Then use create_imagenet.sh to make the dataset generate Leveldb formatted files. Create_imagenet.sh is placed in the examples/imagenet and copied to the path of the dataset, the data set in this document

The key is to modify the path in the create_imagenet.sh to make it possible to convert the data

Example set as the path to the dataset data is also set to the path of the dataset path tools to Convert_imageset.exe

Train_data_root Training Data Set path val_data_root test Data set path

The back resize is false and it does not need to be converted to 256*256

Because this article is to convert the Leveldb file type to add this code "--backend=leveldb\" note that the path to Train.txt Val.txt is the data path,

Run the program, generate two Leveldb folders, Ilsvrc12_train_leveldb and Ilsvrc12_val_leveldb

4 Calculating the mean value of an image

First generate the Compute_image_mean.exe file, the file in the Caffe project also has a corresponding program, compile it, form compute_image_mean.exe can.

Then, under Examples/imagenet, there is an sh file make_imagenet_mean.sh, copy it to the Personal Data folder MyData, and then open the file for editing.

Example is the data set path for data set path tools for Compute_image_mean.exe path

The 9th behavior uses EXE to generate Imagenet_mean.binaryproto for TRAIN_LEVELDB data

After running make_imagenet_mean.sh, Imagenet_mean.binaryproto is generated.

5 Starting Network Design

5.1 setting up the Train_val.prototxt file

Copy the Train_val.prototxt from the caffe-root\models\bvlc_reference_caffenet to modify it.

Set Mean_file: and data Source:

5.2 Setting the Solver.prototxt file

Copy the Solver.prototxt from the caffe-root\models\bvlc_reference_caffenet to modify it. NET path is the path set above, and the parameters of the following iteration are modified according to the actual situation.

5-3 Training Network, running train_caffenet.sh file

Copy the train_caffenet.sh from the caffe-root\\examples\imagenet to modify it.

Set the Caffe.exe path and the Solver.prototxt file path above

Training result: Run train_caffenet.sh file effect

The native configuration is win7+cude8.0+1080 graphics card, you can see the loss in constant decline. This is in case of setting the solve parameter.

The resulting model is Mydata_iter_100.caffemodel

5-4 Test Network

Create a new text file under the data directory and change the suffix name to sh. Fill in the following statement:

First set the path of the Caffe.exe and then set the path of the network, and finally set the load training parameter path. Run the sh file and get the final classification correct rate is: 95%

Everywhere, the entire training and testing process has gone through, followed by the adjustment of the parameters of the problem.

Run your own data with Caffe, Windows-based Caffe

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.