Caffe: How to convert picture data to Lmdb files

Source: Internet
Author: User
Tags shuffle

1 Conversion of picture information

The data types that are often used in Caffe are lmdb or leveldb; not a common format for jpg,jpeg,png,tif, so you need to format the conversion to a Lmdb library file output by entering your own picture directory (a large number of images below). This process is typically done by the Caffe tool Convert_imageset, which is in the compiled Caffe-master/build/tools directory;

2 required conditions for format conversion

Format conversion Preparation conditions are: 1) compile good caffe, and convert_imageset exist; 2) converted pictures and directories, note that these all have format requirements 3) two label file train.txt,val.txt; 4) Use the command to edit the shell script create-lmdb.sh;

3 converted picture files and storage directories

Schedule the conversion directory as shown in the following illustration: Note In this example, the picture is divided into 0 classes and 1 classes of two sets;

4 label files Train.txt and Val.txt

The conversion process, in addition to the above mentioned picture file directory, also need these pictures of the label file, the file is stored in the image file path, and the image of the label (which class); In general, there are two label files, A description of the training set-train.txt, a description of the test set-val.txt, these two file formats are slightly different, the label file format is as follows:

Train.txt file:

1 1 0 0 1 1 1 1 0 0 0 0

Note: This file contains paths/1 and/0, respectively, 0, 12 categories of pictures.

Val.txt file:

10 1 100   0

Note: The label file for this test set does not need to be sorted, compared with the directory structure diagram accompanying train.txt and val.txt; Obviously, the contents of the file and the directory are closely related;

5 How to generate label files Train.txt and Val.txt

When the image scale reaches the tens, the above two files need to be implemented, and a shell script is found online,

#/usr/bin/env SH DATA=examples/Images Echo"Create train.txt ..."RM-RF $DATA/Train.txt Find $DATA-name *cat.jpg | Cut-d'/'-f3 | Sed"s/$/1/">> $DATA/Train.txt Find $DATA-name *bike.jpg | Cut-d'/'-f3 | Sed"s/$/2/">> $DATA/tmp.txt Cat $DATA/tmp.txt>> $DATA/Train.txt RM-RF $DATA/Tmp.txt Echo"Done :"  

Copying the file to the Caffe-master directory will generate the following Train.txt file in the Caffe-master/example/images directory:

    1       Fish2

As long as the above files are slightly modified, it is not difficult to produce the script you need.

6 generating Lmdb with script commands

Write a shell file create_lmdb.sh, which reads as follows:

    #!/usr/bin/en sh      DATA=examples/images      -rf $DATA/img_train_lmdb      build/ Tools/convert_imageset-shuffle \      --resize_height=- --resize_width=  \       /home/my_name/caffe/examples/images/$DATA/train.txt  $DATA/img_train_lmdb  

7 Execute Script

Set the parameter-shuffle to disturb the picture order. Set parameters-resize_height and-resize_width to change all picture sizes to 256*256.

/home/my_name/caffe/examples/images/the absolute path saved for the picture. Finally, run the script file

# sudo sh examples/images/create_lmdb.sh

A folder named Img_train_lmdb is generated in the examples/images/directory, and the file is the db file we need.

 

Caffe: How to convert picture data to Lmdb files

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.