首页 > 代码库 > Chapter 5 Convert Image Set To LevelDB/LMDB

Chapter 5 Convert Image Set To LevelDB/LMDB

Caffe中convert_imageset projrct将图像数据转换成Caffe能读取的数据格式leveldb/lmdb

1.添加命令参数

在main函数中添加命令参数,内容和位置如下:

#ifndef GFLAGS_GFLAGS_H_
    namespace gflags = google;
#endif
 
    //convert imageset By XiaopanLyu====================================================
    argc = 12;
    argv[0] = "convert_imageset";
    argv[1] = "-gray=true";//whether read gray image
    argv[2] = "-shuffle=true";//whether mix order
    argv[3] = "-resize_height=28";
    argv[4] = "-resize_width=28";
    argv[5] = "-backend=lmdb";//leveldb/lmdb
    argv[6] = "-check_size=false";
    argv[7] = "-encoded=true";
    argv[8] = "-encode_type=jpg";
    argv[9] = "E:/MyCode/DL/caffe-master/examples/images/";
    argv[10] = "E:/MyCode/DL/caffe-master/examples/convert_imageset/images_list.txt";
    argv[11] = "E:/MyCode/DL/caffe-master/examples/convert_imageset/img_convert/";
    //after read the [FLAGS] command, the argv & argc would be adjust automatically
    //==================================================================================
 
 
    gflags::SetUsageMessage("Convert a set of images to the leveldb/lmdb\n"
        "format used as input for Caffe.\n"
        "Usage:\n"
        "    convert_imageset [FLAGS] ROOTFOLDER/ LISTFILE DB_NAME\n"
        "The ImageNet dataset for the training demo is at\n"
        "    http://www.image-net.org/download-images\n");
    gflags::ParseCommandLineFlags(&argc, &argv, true);
<style type="text/css">.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }</style>

Attention:

1)argv[10] = "E:/MyCode/DL/caffe-master/examples/convert_imageset/images_list.txt";该文件表示的是图像对应的标签,格式如下:

cat gray.jpg 1
cat.jpg 1
cat_gray.jpg 1
fish-bike.jpg 2

2)argv[11] = "E:/MyCode/DL/caffe-master/examples/convert_imageset/img_convert/";该路径下为生成的文件,若之前已经生成过,再次执行代码时要确保没有重复文件,否则会报错。

2.执行代码,得到结果

技术分享

生成的文件如下:

技术分享

Chapter 5 Convert Image Set To LevelDB/LMDB