diff --git a/docs/tutorials/Custom_DataSet.md b/docs/tutorials/Custom_DataSet.md index 95416e9d1608aa63e52e502b1b7b2349cada8819..349f340685ba360c4dc71b0fc511cb6398047171 100644 --- a/docs/tutorials/Custom_DataSet.md +++ b/docs/tutorials/Custom_DataSet.md @@ -29,6 +29,17 @@ python tools/x2coco.py \ --val_proportion 0.2 \ --test_proportion 0.0 ``` + +**参数说明:** + +- `--dataset_type`:需要转换的数据格式,目前支持:’voc‘、’labelme‘和’cityscape‘ +- `--json_input_dir`:使用labelme标注的json文件所在文件夹 +- `--image_input_dir`:图像文件所在文件夹 +- `--output_dir`:转换后的COCO格式数据集存放位置 +- `--train_proportion`:标注数据中用于train的比例 +- `--val_proportion`:标注数据中用于validation的比例 +- `--test_proportion`:标注数据中用于infer的比例 + (2)voc数据转换为COCO格式: ```bash python tools/x2coco.py \ @@ -41,17 +52,35 @@ python tools/x2coco.py \ **参数说明:** -- `--dataset_type`:需要转换的数据格式,目前支持:’voc‘、’labelme‘和’cityscape‘ -- `--json_input_dir`:使用labelme标注的json文件所在文件夹 -- `--image_input_dir`:图像文件所在文件夹 -- `--output_dir`:转换后的COCO格式数据集存放位置 -- `--train_proportion`:标注数据中用于train的比例 -- `--val_proportion`:标注数据中用于validation的比例 -- `--test_proportion`:标注数据中用于infer的比例 -- `--voc_anno_dir`:VOC数据转换为COCO数据集时的voc数据集标注文件路径 -- `--voc_anno_list`:VOC数据转换为COCO数据集时的标注列表文件,一般是`ImageSets/Main`下trainval.txt和test.txt文件 -- `--voc_label_list`:VOC数据转换为COCO数据集时的类别列表文件,文件中每一行表示一种物体类别 -- `--voc_out_name`:VOC数据转换为COCO数据集时的输出的COCO数据集格式json文件名 +- `--dataset_type`:需要转换的数据格式,当前数据集是voc格式时,指定’voc‘即可。 +- `--voc_anno_dir`:VOC数据转换为COCO数据集时的voc数据集标注文件路径。 +例如: +``` +├──Annotations/ + ├── 009881.xml + ├── 009882.xml + ├── 009886.xml + ... +``` +- `--voc_anno_list`:VOC数据转换为COCO数据集时的标注列表文件,文件中是文件名前缀列表,一般是`ImageSets/Main`下trainval.txt和test.txt文件。 +例如:trainval.txt里的内容如下: +``` +009881 +009882 +009886 +... +``` +- `--voc_label_list`:VOC数据转换为COCO数据集时的类别列表文件,文件中每一行表示一种物体类别。 +例如:label_list.txt里的内容如下: +``` +background +aeroplane +bicycle +... +``` +- `--voc_out_name`:VOC数据转换为COCO数据集时的输出的COCO数据集格式json文件名。 + + ### 方式二:将数据集转换为VOC格式 diff --git a/tools/x2coco.py b/tools/x2coco.py index f4549746c2f1fdc3752105d44792e4316d817b28..12b940a30da51f397242d23f3d5f86c7a5d4ebdc 100644 --- a/tools/x2coco.py +++ b/tools/x2coco.py @@ -216,8 +216,8 @@ def voc_get_image_info(annotation_root, im_id): img_name = os.path.basename(filename) size = annotation_root.find('size') - width = int(size.findtext('width')) - height = int(size.findtext('height')) + width = float(size.findtext('width')) + height = float(size.findtext('height')) image_info = { 'file_name': filename, @@ -233,10 +233,10 @@ def voc_get_coco_annotation(obj, label2id): assert label in label2id, "label is not in label2id." category_id = label2id[label] bndbox = obj.find('bndbox') - xmin = int(bndbox.findtext('xmin')) - 1 - ymin = int(bndbox.findtext('ymin')) - 1 - xmax = int(bndbox.findtext('xmax')) - ymax = int(bndbox.findtext('ymax')) + xmin = float(bndbox.findtext('xmin')) - 1 + ymin = float(bndbox.findtext('ymin')) - 1 + xmax = float(bndbox.findtext('xmax')) + ymax = float(bndbox.findtext('ymax')) assert xmax > xmin and ymax > ymin, "Box size error." o_width = xmax - xmin o_height = ymax - ymin