TextBoxes icon indicating copy to clipboard operation
TextBoxes copied to clipboard

The error when I use creat_data.sh to creat my own lmdb dataset.

Open yingning opened this issue 7 years ago • 7 comments

I hope someone can give me a hand when I run creat_data.sh on pycharm ,I got the following error: WARNING: Logging before InitGoogleLogging() is written to STDERR F0718 22:59:00.647725 16342 convert_annoset.cpp:204] This tool requires OpenCV; compile with USE_OPENCV. *** Check failure stack trace: *** /home/jsj/TextBoxes /home/jsj/TextBoxes/build/tools/convert_annoset --anno_type=detection --label_type=xml --label_map_file=/home/jsj/TextBoxes/data/VOC0712/labelmap_voc.prototxt --check_label=True --min_dim=0 --max_dim=0 --resize_height=0 --resize_width=0 --backend=lmdb --shuffle=False --check_size=False --encode_type=jpg --encoded=True --gray=False /home/jsj/TextBoxes/examples/TextBoxes/ /home/jsj/TextBoxes/examples/TextBoxes/test.txt /home/jsj/TextBoxes/examples/TextBoxes/lmdb/icdar2013_test_lmdb Traceback (most recent call last): File "/home/jsj/TextBoxes/scripts/create_annoset.py", line 169, in os.symlink(out_dir, link_dir) OSError: [Errno 17] File exists

My creat_data.sh 's content is following:

#!/usr/bin/env bash cur_dir=$(cd $( dirname ${BASH_SOURCE[0]} ) && pwd ) root_dir=$cur_dir/../.. #echo 'root_dir :' $root_dir

cd $root_dir #caffe_root ='/home/jsj/TextBoxes/python' #echo 'caffe_root :' $caffe_root

redo=true data_root_dir="/home/jsj/TextBoxes/examples/TextBoxes"

mapfile="/home/jsj/TextBoxes/examples/TextBoxes/labelmap_voc.prototxt"

dataset_name="icdar2013" anno_type="detection" label_type="xml" db="lmdb" min_dim=0 max_dim=0 width=0 height=0

extra_cmd="--encode-type=jpg --encoded" if $redo then extra_cmd="$extra_cmd --redo" fi for subset in train test do python /home/jsj/TextBoxes/scripts/create_annoset.py --anno-type=$anno_type --label-type=$label_type --label-map-file=$mapfile --min-dim=$min_dim --max-dim=$max_dim --resize-width=$width --resize-height=$height --check-label $extra_cmd $data_root_dir $data_root_dir/$subset.txt $data_root_dir/$db/$dataset_name""$subset""$db examples/$dataset_name 2>&1 | tee $root_dir/$dataset_name/$subset.log done

And my creat_annoset.py 's content is following: from future import print_function import argparse import os import shutil import subprocess import sys sys.path.insert(0,'/home/jsj/TextBoxes/python/caffe/proto/') #from caffe.proto import caffe_pb2 import caffe_pb2 from google.protobuf import text_format

if name == "main": 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 = "detection", 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.") args = parser.parse_args() root_dir = args.root list_file = args.listfile out_dir = args.outdir example_dir = args.exampledir

redo = args.redo anno_type = args.anno_type label_type = args.label_type backend = args.backend check_size = args.check_size encode_type = args.encode_type encoded = args.encoded gray = args.gray label_map_file = args.label_map_file min_dim = args.min_dim max_dim = args.max_dim resize_height = args.resize_height resize_width = args.resize_width shuffle = args.shuffle check_label = args.check_label

check if root directory exists

if not os.path.exists(root_dir): print ("root directory: {} does not exist".format(root_dir)) sys.exit()

add "/" to root directory if needed

if root_dir[-1] != "/": root_dir += "/"

check if list file exists

if not os.path.exists(list_file): print ("list file: {} does not exist".format(list_file)) sys.exit()

check list file format is correct

with open(list_file, "r") as lf: for line in lf.readlines(): img_file, anno = line.strip("\n").split(" ") if not os.path.exists(root_dir + img_file): print ("image file: {} does not exist".format(root_dir + img_file)) if anno_type == "classification": if not anno.isdigit(): print ("annotation: {} is not an integer".format(anno)) elif anno_type == "detection": if not os.path.exists(root_dir + anno): print ("annofation file: {} does not exist".format(root_dir + anno)) sys.exit() break

check if label map file exist

if anno_type == "detection": if not os.path.exists(label_map_file): print ("label map file: {} does not exist".format(label_map_file)) sys.exit() label_map = caffe_pb2.LabelMap() lmf = open(label_map_file, "r") try: text_format.Merge(str(lmf.read()), label_map) except: print ("Cannot parse label map file: {}".format(label_map_file)) sys.exit() out_parent_dir = os.path.dirname(out_dir) if not os.path.exists(out_parent_dir): os.makedirs(out_parent_dir) if os.path.exists(out_dir) and not redo: print ("{} already exists and I do not hear redo".format(out_dir)) sys.exit() if os.path.exists(out_dir): shutil.rmtree(out_dir)

get caffe root directory

caffe_root = os.path.dirname(os.path.dirname(os.path.realpath(file))) print(caffe_root) if anno_type == "detection": cmd = "{}/build/tools/convert_annoset"
" --anno_type={}"
" --label_type={}"
" --label_map_file={}"
" --check_label={}"
" --min_dim={}"
" --max_dim={}"
" --resize_height={}"
" --resize_width={}"
" --backend={}"
" --shuffle={}"
" --check_size={}"
" --encode_type={}"
" --encoded={}"
" --gray={}"
" {} {} {}"
.format(caffe_root, anno_type, label_type, label_map_file, check_label, min_dim, max_dim, resize_height, resize_width, backend, shuffle, check_size, encode_type, encoded, gray, root_dir, list_file, out_dir) elif anno_type == "classification": cmd = "{}/build/tools/convert_annoset"
" --anno_type={}"
" --min_dim={}"
" --max_dim={}"
" --resize_height={}"
" --resize_width={}"
" --backend={}"
" --shuffle={}"
" --check_size={}"
" --encode_type={}"
" --encoded={}"
" --gray={}"
" {} {} {}"
.format(caffe_root, anno_type, min_dim, max_dim, resize_height, resize_width, backend, shuffle, check_size, encode_type, encoded, gray, root_dir, list_file, out_dir) print(cmd) process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) output = process.communicate()[0]

if not os.path.exists(example_dir): os.makedirs(example_dir) link_dir = os.path.join(example_dir, os.path.basename(out_dir)) if os.path.exists(link_dir): os.unlink(link_dir) os.symlink(out_dir, link_dir)

yingning avatar Jul 18 '17 15:07 yingning

@pankajkumar

yingning avatar Jul 19 '17 10:07 yingning

Do you have solved the problem? I meet it , and can you tell me the method? Thank you very much!@yingning

19931991 avatar Jan 04 '18 07:01 19931991

@MhLiao

19931991 avatar Jan 04 '18 08:01 19931991

你需要修改make.comfig 文件,注释掉 use opencv =0,重新编译caffe。

yingning avatar Jan 04 '18 10:01 yingning

非常感谢你的回复,我的问题还是没解决,可能是别的原因,可以加个qq吗,方便交流。1323369151。非常感谢!

19931991 avatar Jan 04 '18 11:01 19931991

我已经加你qq

yingning avatar Jan 04 '18 14:01 yingning

@yingning @19931991 Have you solved this? I've encountered the same problem. Thanks!

gaalejandre avatar Jul 26 '18 08:07 gaalejandre