生成lmdb格式的数据包

一直做人脸识别,所以几乎没怎么再使用lmdb格式的数据,但是最近要训练人脸检测,然后不得不使用lmdb格式的数据包,然后悲惨的是我竟然忘记了怎样使用/(ㄒoㄒ)/~~;

所遇到的麻烦列举:

1,python 中的参数解析问题(因为我使用caffe工程中的create_annoset.py)

2,create_annoset.py中提示没有caffe;

首先讲一讲python中的参数解析问题(直接看create_annoset.py中源码):

parser = argparse.ArgumentParser(description="Create AnnotatedDatum database")
  parser.add_argument("root",
      help="The root directory which contains the images and annotations.")
  parser.add_argument("listfile",
      help="The file which contains image paths and annotation info.")
  parser.add_argument("outdir",
      help="The output directory which stores the database file.")
  parser.add_argument("exampledir",
      help="The directory to store the link of the database files.")
  parser.add_argument("--redo", default = False, action = "store_true",
      help="Recreate the database.")
  parser.add_argument("--anno-type", default = "classification",
      help="The type of annotation {classification, detection}.")
  parser.add_argument("--label-type", default = "xml",
      help="The type of label file format for detection {xml, json, txt}.")
  parser.add_argument("--backend", default = "lmdb",
      help="The backend {lmdb, leveldb} for storing the result")
  parser.add_argument("--check-size", default = False, action = "store_true",
      help="Check that all the datum have the same size.")
  parser.add_argument("--encode-type", default = "",
      help="What type should we encode the image as ('png','jpg',...).")
  parser.add_argument("--encoded", default = False, action = "store_true",
      help="The encoded image will be save in datum.")
  parser.add_argument("--gray", default = False, action = "store_true",
      help="Treat images as grayscale ones.")
  parser.add_argument("--label-map-file", default = "",
      help="A file with LabelMap protobuf message.")
  parser.add_argument("--min-dim", default = 0, type = int,
      help="Minimum dimension images are resized to.")
  parser.add_argument("--max-dim", default = 0, type = int,
      help="Maximum dimension images are resized to.")
  parser.add_argument("--resize-height", default = 0, type = int,
      help="Height images are resized to.")
  parser.add_argument("--resize-width", default = 0, type = int,
      help="Width images are resized to.")
  parser.add_argument("--shuffle", default = False, action = "store_true",
      help="Randomly shuffle the order of images and their labels.")
  parser.add_argument("--check-label", default = False, action = "store_true",
      help="Check that there is no duplicated name/label.")

这么长一串参数解析,按道理是按照自己需要的填好就可以了,但是这么多参数是不是多需要填写了?又在哪里填写了,按什么方式填写?

第一个问题:是不是都要填写?经过调试代码,发现没有defalut值的是一定要填写的,然后就是根据自己设置的参数情况来进行填写。

第二个问题:python代码在调试时怎样填写参数?以下是pycharm中填写参数的方式:

可以看到红色的圈圈中有个三角符号,点击这个三角符号,就可以看到“Edit Configurations",然后点选“Edit Configurations",就可以进入以下界面:

在红色框中填写参数就可以了。

第三个问题填写的方式是怎样的?

以下是我填写的前四个参数,分别对应"root","listfile","outdir","exampledir",

然后如果需要修改部分有默认参数的参数,填写如下:

以上是参数解析遇到的问题:

然后是运行create_annoset.py中提示没有caffe的问题

这个处理方法主要有两个:

1)在from caffe.proto import caffe_pb2前链接上caffe,

import sys
sys.path.insert(0,'/home/XXXXX/sdb/Caffe_Project_Train/caffe-ssd/python')

2)将caffe_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

caffe_root = "/home/XXXXX/sdb/Caffe_Project_Train/caffe-ssd"

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章