The data format used by the Caffe framework is usually lmdb and leveldb, but we often use picture files, such as Jpg,jpeg,png,tif format, and it is possible that the picture is not the same size.
In the conversion process, you need to prepare two parts of the content:
1:train.txt and Test.txt Tagged image address list files,
2: Execute the document.
The first part is shown in the following figure
Note: You must ensure that the path is correct, and that no spaces can appear after the label, or you may find a file error. ()
We can look at the source code, convet_imageset.cpp in this section:
int label;
while (Std::getline (infile, line)) {
pos = line.find_last_of (');
Label = Atoi (Line.substr (pos + 1). C_STR ());
Lines.push_back (Std::make_pair (line.substr (0, POS), label);
}
Part II:
The execution file is written in the main function of the Convet_imageset.cpp file as follows:
rootfolder/: Absolute path of picture storage
ListFile: Picture file list, generally a TXT file, a line of pictures (with labels)
Db_name: The generated DB file storage location
Let's take a look at the contents of the Flags parameter group:
define_bool (gray, False, "when this option was on, treat images as grayscale ones");
Define_bool (Shuffle, false, "randomly shuffle the order of images and their labels");
Define_string (Backend, "Lmdb", "the backend {lmdb, leveldb} for storing");
Define_int32 (resize_width, 0, "width images are resized to");
Define_int32 (resize_height, 0, "Height images are resized to");
Define_bool (Check_size, False, "when this option is in, check that all the datum have the same size");
Define_bool (encoded, false, "when this option is on, the encoded image would be save in Datum"); Define_string (Encode_type, "", "optional:what type should we encode the image as (' png ', ' jpg ',...).");
–gray: Whether to open the picture as a grayscale image. The program calls the Imread () function in the OpenCV library to open the picture, which defaults to False
–shuffle: Randomly disturb picture order. Default to False
–backend: Need to 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 you need to change the size of the picture. The program calls the OpenCV Library's resize () function to enlarge the picture, by default 0, without changing
–check_size: Check to see if all data have the same size. Default is False, do not check
–encoded: The original picture encoding is put into the final data, the default is False
–encode_type: Corresponds to the previous parameter and encodes the picture into which format: ' png ', ' jpg ' ...
Write the execution file and create the. bat script.
. \build\x64\release\convert_imageset.exe–gray=true–backend=leveldb–shuffle=true–resize_height=22–resize_width= Test/test.txt Leveldb
Done.
Adjusted a morning's mistake, finally ran through under the release ... I think I should write a wrong article .... Take a look at the source.