Windows Caffe (iii) Conversion of image data to Caffe data that can be run

Source: Internet
Author: User
Tags shuffle

When running the two examples of Caffe, our data comes from the Internet, which is a binary file that is downloaded directly.

But most of us use raw picture data (such as. jpg. PNG, etc.), and then we'll look at how to convert the original image data into data that Caffe can run.

1. Prepare picture data Caffe after the installation is complete, there will be four. jpg images, cat.jpg, cat gray,jpg, Cat_gray.jpg, FISH-BACK.JPG2, example/images files. To generate a picture list we write an SH script that calls the Linux command to generate a list of images. How to run shell scripts under Windows, the first experiment has to say. The reason for scripting is that we have a lot of training data and test data, and the handwriting list isn't realistic. To do this, create a example/images folder under thecreate_filelist.shFile, the contents of the file are as follows:
#/usr/bin/env Shdata=d:/caffe/caffe_bvlc/examples/imagesecho "Create train.txt ..." exec 2>>log.txtrm-rf $DATA/ Train.txtfind $DATA-name *cat.jpg | Cut-d '/'-f6 | Sed "s/$/1/" >> $DATA/train.txtfind $DATA-name *bike.jpg | Cut-d '/'-f6 | Sed "s/$/2/" >> $DATA/tmp.txtcat $DATA/tmp.txt>> $DATA/train.txtrm-rf $DATA/tmp.txtecho "Done ..."
Here's a rough explanation of the script. Data=d:/caffe/caffe_bvlc/examples/images Picture Location
EXEC 2>>log.txt writes errors that are encountered during execution to the Log.txt folder Rm-rf recursively forcibly delete find $DATA-name *cat.jpg | Cut-d '/'-f6 | Sed "s/$/1/" >> $DATA/train.txt in $data directory, find *cat.jpg file, cut represents the Intercept path,-f6 represents the sixth level directory (modified according to your own situation)。 SED indicates that labels are appended to each line.
Cat $DATA/tmp.txt>> $DATA/train.txt writes the contents of the Temp.txt file to a train.txt file, which is equivalent to two file merges.
When you run the file, a train.txt file is generated. 3, generate Lmdb format files to convert picture data to Lmdb format files need to use the Convert_imageset file provided by Caffe the file directory: D:\Caffe\Caffe_BVLC\Build\x64\Release
Use format for this file:Convert_imageset [FLAGS] rootfolder/listfile db_nameAnalyze the four parameters of Convert_imageset

FLAGS

-gray:whether to open the picture as a grayscale image. Program callsOpenCVin the libraryImread ()function to open the picture, the default isfalse
-shuffle:whether to randomly shuffle the picture order. Default isfalse
-backend: convert to db file format, optional leveldb or lmdb, default to Lmdb
-resize_width/resize_height:change the size of the picture. In operation, all pictures are required to be of the same size, so the image size needs to be changed. Ride
Sequential invocationOpenCVLibrary'sResize() function to zoom in on the image by default0, does not change
-check_size:Check that all data has the same size. Default isfalse,Do not check
-encoded:if the original image encoding is placed in the final data, the default isfalse
-encode_type:in relation to the previous parameter, encode the picture into which format:' png ', ' jpg ' ...
RootFolder

Path of picture storage

ListFile

List of documents

Db_name

The path that the resulting lmdb or LEVELDB will hold

Specific operation

Create a create_lmdb.sh script under the Example/images folder with the following script:

DATA=D:/CAFFE/CAFFE_BVLC/EXAMPLES/IMAGESRM-RF $DATA/img_train_lmdbd:/caffe/caffe_bvlc/build/x64/release/convert _imageset.exe--shuffle--resize_height=256--resize_width=256 $DATA $DATA/train.txt $DATA/img_train_lmdb
Executing the script, a new file is generated in the directory, as shown in:

At this point, the original image data into Caffe can perform the Lmdb data experiment completed.

If in doubt, welcome to explore together!



Windows Caffe (iii) Conversion of image data to Caffe data that can be run

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.