一直做人臉識別,所以幾乎沒怎麼再使用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"