Browse Source

Uniform code style of tools and fix docs of tools (#138)

huilin 2 years ago
parent
commit
151e72e9ea

+ 110 - 122
docs/data/coco_tools_cn.md

@@ -6,18 +6,16 @@
 
 coco_tools是PaddleRS提供的用于处理COCO格式标注文件的工具集,位于`tools/coco_tools/`目录。由于[pycocotools库](https://pypi.org/project/pycocotools/)在部分环境下无法安装,PaddleRS提供coco_tools作为替代,进行一些简单的文件处理工作。
 
-*请注意,coco_tools目前为一项实验性功能,若您在使用过程中遇到问题,请及时向我们反馈。*
-
 ## 2 文件说明
 
 目前coco_tools共有6个文件,各文件及其功能如下:
 
-- `json_InfoShow.py`:    打印json文件中各个字典的基本信息;
-- `json_ImgSta.py`:      统计json文件中的图像信息,生成统计表、统计图;
-- `json_AnnoSta.py`:     统计json文件中的标注信息,生成统计表、统计图;
-- `json_Img2Json.py`:    统计test集图像,生成json文件;
-- `json_Split.py`:       将json文件中的内容划分为train set和val set;
-- `json_Merge.py`:       将多个json文件合并为1个。
+- `json_info_show.py`:    打印JSON文件中各个字典的基本信息;
+- `json_image_sta.py`:      统计JSON文件中的图像信息,生成统计表、统计图;
+- `json_anno_sta.py`:     统计JSON文件中的标注信息,生成统计表、统计图;
+- `json_image2json.py`:    统计test set图像,生成JSON文件;
+- `json_split.py`:       将JSON文件中的内容划分为train set和val set;
+- `json_merge.py`:       将多个JSON文件合并为1个。
 
 ## 3 使用示例
 
@@ -53,14 +51,14 @@ coco_tools是PaddleRS提供的用于处理COCO格式标注文件的工具集,
 
 ### 3.2 打印json信息
 
-使用`json_InfoShow.py`可以打印json文件中的各个键值对的key, 并输出value中排列靠前的元素,从而帮助您快速了解标注信息。对于COCO格式标注数据而言,您应该特别留意`'image'`和`'annotation'`字段的内容。
+使用`json_info_show.py`可以打印JSON文件中的各个键值对的key, 并输出value中排列靠前的元素,从而帮助您快速了解标注信息。对于COCO格式标注数据而言,您应该特别留意`'image'`和`'annotation'`字段的内容。
 
 #### 3.2.1 命令演示
 
 执行如下命令,打印`instances_val2017.json`中的信息:
 
 ```
-python ./coco_tools/json_InfoShow.py \
+python ./coco_tools/json_info_show.py \
        --json_path=./annotations/instances_val2017.json \
        --show_num 5
 ```
@@ -68,11 +66,10 @@ python ./coco_tools/json_InfoShow.py \
 #### 3.2.2 参数说明
 
 
-| 参数名         | 含义                                 | 默认值    |
-| ------------- | ------------------------------------| -------- |
-| `--json_path` | 需要统计的json文件路径                 |          |
-| `--show_num`  | (可选)输出value中排列靠前的元素的个数   | `5`      |
-| `--Args_show` | (可选)是否打印输入参数信息             | `True`   |
+| 参数名        | 含义                                    | 默认值 |
+| ------------- | --------------------------------------- | ------ |
+| `--json_path` | 需要统计的JSON文件路径                  |        |
+| `--show_num`  | (可选)输出value中排列靠前的元素的个数 | `5`    |
 
 #### 3.2.3 结果展示
 
@@ -82,7 +79,6 @@ python ./coco_tools/json_InfoShow.py \
 ------------------------------------------------Args------------------------------------------------
 json_path = ./annotations/instances_val2017.json
 show_num = 5
-Args_show = True
 
 ------------------------------------------------Info------------------------------------------------
 json read...
@@ -162,6 +158,7 @@ contributor : COCO Consortium
 ```
 'info', 'licenses', 'images', 'annotations', 'categories'
 ```
+
 其中,
 
 - `'info'`键对应的值为字典,共有6个键值对,输出展示了前5对;
@@ -172,30 +169,30 @@ contributor : COCO Consortium
 
 ### 3.3 统计图像信息
 
-使用`json_ImgSta.py`可以从`instances_val2017.json`中快速提取图像信息,生成csv表格,并生成统计图。
+使用`json_image_sta.py`可以从`instances_val2017.json`中快速提取图像信息,生成csv表格,并生成统计图。
 
 #### 3.3.1 命令演示
 
 执行如下命令,打印`instances_val2017.json`信息:
 
 ```
-python ./coco_tools/json_ImgSta.py \
+python ./coco_tools/json_image_sta.py \
     --json_path=./annotations/instances_val2017.json \
-    --csv_path=./img_sta/images.csv \
-    --png_shape_path=./img_sta/images_shape.png \
-    --png_shapeRate_path=./img_sta/images_shapeRate.png
+    --csv_path=./img_sta/img.csv \
+    --img_shape_path=./img_sta/img_shape.png \
+    --img_shape_rate_path=./img_sta/img_shape_rate.png
 ```
 
 #### 3.3.2 参数说明
 
-| 参数名                  | 含义                                                                   | 默认值    |
-| ---------------------- | --------------------------------------------------------------------- | -------- |
-| `--json_path`          | 需要统计的json文件路径                                                   |          |
-| `--csv_path`           | (可选)统计表格保存路径                                                  | `None`   |
-| `--png_shape_path`     | (可选).png图片保存路径,图片内容为所有图像shape的二维分布                     | `5`      |
-| `--png_shapeRate_path` | (可选).png图片保存路径,图片内容为所有图像shape比例(宽/高)的一维分布           | `5`      |
-| `--image_keyname`      | (可选)json文件中,图像所对应的key                                        |`'images'`|
-| `--Args_show`          | (可选)是否打印输入参数信息                                               |`True`    |
+
+| 参数名                     | 含义                                                                   | 默认值     |
+|-------------------------| ---------------------------------------------------------------------- | ---------- |
+| `--json_path`           | 需要统计的JSON文件路径                                                 |            |
+| `--csv_path`            | (可选)统计表格保存路径                                               | `None`     |
+| `--img_shape_path`      | (可选)输出图片保存路径,图片内容为所有图像shape的二维分布            | `5`        |
+| `--img_shape_rate_path` | (可选)输出图片保存路径,图片内容为所有图像shape比例(宽/高)的一维分布 | `5`        |
+| `--img_keyname`         | (可选)JSON文件中,图像所对应的key                                    | `'images'` |
 
 #### 3.3.3 结果展示
 
@@ -204,25 +201,24 @@ python ./coco_tools/json_ImgSta.py \
 ```
 ------------------------------------------------Args------------------------------------------------
 json_path = ./annotations/instances_val2017.json
-csv_path = ./img_sta/images.csv
-png_shape_path = ./img_sta/images_shape.png
-png_shapeRate_path = ./img_sta/images_shapeRate.png
-image_keyname = images
-Args_show = True
+csv_path = ./img_sta/img.csv
+img_shape_path = ./img_sta/img_shape.png
+img_shape_rate_path = ./img_sta/img_shape_rate.png
+img_keyname = images
 
 json read...
 
 make dir: ./img_sta
-png save to ./img_sta/images_shape.png
-png save to ./img_sta/images_shapeRate.png
-csv save to ./img_sta/images.csv
+png save to ./img_sta/img_shape.png
+png save to ./img_sta/img_shape_rate.png
+csv save to ./img_sta/img.csv
 ```
 
 部分表格内容:
 
 
 |   | license | file_name        | coco_url                                               | height | width | date_captured       | flickr_url                                                     | id     | shape_rate |
-| --- | --------- | ------------------ | -------------------------------------------------------- | -------- | ------- | --------------------- | ---------------------------------------------------------------- | -------- | ------------ |
+| - | ------- | ---------------- | ------------------------------------------------------ | ------ | ----- | ------------------- | -------------------------------------------------------------- | ------ | ---------- |
 | 0 | 4       | 000000397133.jpg | http://images.cocodataset.org/val2017/000000397133.jpg | 427    | 640   | 2013-11-14 17:02:52 | http://farm7.staticflickr.com/6116/6255196340_da26cf2c9e_z.jpg | 397133 | 1.5        |
 | 1 | 1       | 000000037777.jpg | http://images.cocodataset.org/val2017/000000037777.jpg | 230    | 352   | 2013-11-14 20:55:31 | http://farm9.staticflickr.com/8429/7839199426_f6d48aa585_z.jpg | 37777  | 1.5        |
 | 2 | 4       | 000000252219.jpg | http://images.cocodataset.org/val2017/000000252219.jpg | 428    | 640   | 2013-11-14 22:32:02 | http://farm4.staticflickr.com/3446/3232237447_13d84bd0a1_z.jpg | 252219 | 1.5        |
@@ -238,41 +234,41 @@ csv save to ./img_sta/images.csv
 
 ### 3.4 统计目标检测标注框信息
 
-使用`json_AnnoSta.py`,可以从`instances_val2017.json`中快速提取标注信息,生成csv表格,并生成统计图。
+使用`json_anno_sta.py`,可以从`instances_val2017.json`中快速提取标注信息,生成csv表格,并生成统计图。
 
 #### 3.4.1 命令演示
 
 执行如下命令,打印`instances_val2017.json`信息:
 
 ```
-python ./coco_tools/json_AnnoSta.py \
+python ./coco_tools/json_anno_sta.py \
     --json_path=./annotations/instances_val2017.json \
-    --csv_path=./anno_sta/annos.csv \
-    --png_shape_path=./anno_sta/annos_shape.png \
-    --png_shapeRate_path=./anno_sta/annos_shapeRate.png \
-    --png_pos_path=./anno_sta/annos_pos.png \
-    --png_posEnd_path=./anno_sta/annos_posEnd.png \
-    --png_cat_path=./anno_sta/annos_cat.png \
-    --png_objNum_path=./anno_sta/annos_objNum.png \
+    --csv_path=./anno_sta/obj.csv \
+    --obj_shape_path=./anno_sta/obj_shape.png \
+    --obj_shape_rate_path=./anno_sta/obj_shape_rate.png \
+    --obj_pos_path=./anno_sta/obj_pos.png \
+    --obj_pos_end_path=./anno_sta/obj_pos_end.png \
+    --obj_cat_path=./anno_sta/obj_cat.png \
+    --obj_obj_num_path=./anno_sta/obj_obj_num.png \
     --get_relative=True
 ```
 
 #### 3.4.2 参数说明
 
-| 参数名                  | 含义                                                                                                                       | 默认值         |
-| ---------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------- |
-| `--json_path`          | (可选)需要统计的json文件路径                                                                                                 |               |
-| `--csv_path`           | (可选)统计表格保存路径                                                                                                       | `None`        |
-| `--png_shape_path`     | (可选).png图片保存路径,图片内容为所有目标检测框shape的二维分布                                                                    | `None`        |
-| `--png_shapeRate_path` | (可选).png图片保存路径,图片内容为所有目标检测框shape比例(宽/高)的一维分布                                                           | `None`        |
-| `--png_pos_path`       | (可选).png图片保存路径,图片内容为所有目标检测框左上角坐标的二维分布                                                                 | `None`        |
-| `--png_posEnd_path`    | (可选).png图片保存路径,图片内容为所有目标检测框右下角坐标的二维分布                                                                 | `None`        |
-| `--png_cat_path`       | (可选).png图片保存路径,图片内容为各个类别的对象数量分布                                                                           | `None`        |
-| `--png_objNum_path`    | (可选).png图片保存路径,图片内容为单个图像中含有标注对象的数量分布                                                                   | `None`        |
-| `--get_relative`       | (可选)是否生成图像目标检测框shape、目标检测框左上角坐标、右下角坐标的相对比例值<br />(横轴坐标/图片长,纵轴坐标/图片宽)                    | `None`        |
-| `--image_keyname`      | (可选)json文件中,图像所对应的key                                                                                             | `'images'`    |
-| `--anno_keyname`       | (可选)json文件中,标注所对应的key                                                                                             | `'annotations'`|
-| `--Args_show`          | (可选)是否打印输入参数信息                                                                                                    | `True`        |
+
+| 参数名                     | 含义                                                                                                                      | 默认值             |
+|-------------------------| ------------------------------------------------------------------------------------------------------------------------- |-----------------|
+| `--json_path`           | 需要统计的JSON文件路径                                                                                            |                 |
+| `--csv_path`            | (可选)统计表格保存路径                                                                                                  | `None`          |
+| `--obj_shape_path`      | (可选)输出图片保存路径,图片内容为所有目标检测框shape的二维分布                                                         | `None`          |
+| `--obj_shape_rate_path` | (可选)输出图片保存路径,图片内容为所有目标检测框shape比例(宽/高)的一维分布                                              | `None`          |
+| `--obj_pos_path`        | (可选)输出图片保存路径,图片内容为所有目标检测框左上角坐标的二维分布                                                    | `None`          |
+| `--obj_pos_end_path`    | (可选)输出图片保存路径,图片内容为所有目标检测框右下角坐标的二维分布                                                    | `None`          |
+| `--obj_cat_path`        | (可选)输出图片保存路径,图片内容为各个类别的对象数量分布                                                                | `None`          |
+| `--obj_obj_num_path`    | (可选)输出图片保存路径,图片内容为单个图像中含有标注对象的数量分布                                                      | `None`          |
+| `--get_relative`        | (可选)是否生成图像目标检测框shape、目标检测框左上角坐标、右下角坐标的相对比例值<br />(横轴坐标/图片长,纵轴坐标/图片宽) | `False`         |
+| `--img_keyname`         | (可选)JSON文件中,图像所对应的key                                                                                       | `'images'`      |
+| `--anno_keyname`        | (可选)JSON文件中,标注所对应的key                                                                                       | `'annotations'` |
 
 #### 3.4.3 结果展示
 
@@ -281,31 +277,30 @@ python ./coco_tools/json_AnnoSta.py \
 ```
 ------------------------------------------------Args------------------------------------------------
 json_path = ./annotations/instances_val2017.json
-csv_path = ./anno_sta/annos.csv
-png_shape_path = ./anno_sta/annos_shape.png
-png_shapeRate_path = ./anno_sta/annos_shapeRate.png
-png_pos_path = ./anno_sta/annos_pos.png
-png_posEnd_path = ./anno_sta/annos_posEnd.png
-png_cat_path = ./anno_sta/annos_cat.png
-png_objNum_path = ./anno_sta/annos_objNum.png
+csv_path = ./anno_sta/obj.csv
+obj_shape_path = ./anno_sta/obj_shape.png
+obj_shape_rate_path = ./anno_sta/obj_shape_rate.png
+obj_pos_path = ./anno_sta/obj_pos.png
+obj_pos_end_path = ./anno_sta/obj_pos_end.png
+obj_cat_path = ./anno_sta/obj_cat.png
+obj_obj_num_path = ./anno_sta/obj_obj_num.png
 get_relative = True
-image_keyname = images
+img_keyname = images
 anno_keyname = annotations
-Args_show = True
 
 json read...
 
 make dir: ./anno_sta
-png save to ./anno_sta/annos_shape.png
-png save to ./anno_sta/annos_shape_Relative.png
-png save to ./anno_sta/annos_shapeRate.png
-png save to ./anno_sta/annos_pos.png
-png save to ./anno_sta/annos_pos_Relative.png
-png save to ./anno_sta/annos_posEnd.png
-png save to ./anno_sta/annos_posEnd_Relative.png
-png save to ./anno_sta/annos_cat.png
-png save to ./anno_sta/annos_objNum.png
-csv save to ./anno_sta/annos.csv
+png save to ./anno_sta/obj_shape.png
+png save to ./anno_sta/obj_shape_relative.png
+png save to ./anno_sta/obj_shape_rate.png
+png save to ./anno_sta/obj_pos.png
+png save to ./anno_sta/obj_pos_relative.png
+png save to ./anno_sta/obj_pos_end.png
+png save to ./anno_sta/obj_pos_end_relative.png
+png save to ./anno_sta/obj_cat.png
+png save to ./anno_sta/obj_num.png
+csv save to ./anno_sta/obj.csv
 ```
 
 部分表格内容:
@@ -350,15 +345,15 @@ csv save to ./anno_sta/annos.csv
 
 ### 3.5 统计图像信息生成json
 
-使用`json_Img2Json.py`,可以根据`test2017`中的文件信息与训练集json文件快速提取图像信息,生成测试集json文件。
+使用`json_image2json.py`,可以根据`test2017`中的文件信息与训练集JSON文件快速提取图像信息,生成测试集JSON文件。
 
 #### 3.5.1 命令演示
 
 执行如下命令,统计并生成`test2017`信息:
 
 ```
-python ./coco_tools/json_Img2Json.py \
-    --test_image_path=./test2017 \
+python ./coco_tools/json_image2json.py \
+    --image_dir=./test2017 \
     --json_train_path=./annotations/instances_val2017.json \
     --json_test_path=./test.json
 ```
@@ -366,14 +361,13 @@ python ./coco_tools/json_Img2Json.py \
 #### 3.5.2 参数说明
 
 
-| 参数名               | 含义                                      | 默认值        |
-| ------------------- | ---------------------------------------- | ------------ |
-| `--test_image_path` | 需要统计的图像目录路径                       |              |
-| `--json_train_path` | 用于参考的训练集json文件路径                 |              |
-| `--json_test_path`  | 生成的测试集json文件路径                    |              |
-| `--image_keyname`   | (可选)json文件中,图像对应的key            | `'images'`    |
-| `--cat_keyname`     | (可选)json文件中,类别对应的key            | `'categories'`|
-| `--Args_show`       | (可选)是否打印输入参数信息                 | `True`        |
+| 参数名                 | 含义                              | 默认值         |
+|---------------------| --------------------------------- | -------------- |
+| `--image_dir`       | 需要统计的图像目录路径            |                |
+| `--json_train_path` | 用于参考的训练集JSON文件路径      |                |
+| `--json_test_path`  | 生成的测试集JSON文件路径          |                |
+| `--img_keyname`     | (可选)JSON文件中,图像对应的key | `'images'`     |
+| `--cat_keyname`     | (可选)JSON文件中,类别对应的key | `'categories'` |
 
 #### 3.5.3 结果展示
 
@@ -381,10 +375,9 @@ python ./coco_tools/json_Img2Json.py \
 
 ```
 ------------------------------------------------Args------------------------------------------------
-test_image_path = ./test2017
+image_dir = ./test2017
 json_train_path = ./annotations/instances_val2017.json
 json_test_path = ./test.json
-Args_show = True
 
 ----------------------------------------------Get Test----------------------------------------------
 
@@ -396,13 +389,12 @@ test image read...
  total test image: 40670
 ```
 
-生成的json文件信息:
+生成的JSON文件信息:
 
 ```
 ------------------------------------------------Args------------------------------------------------
 json_path = ./test.json
 show_num = 5
-Args_show = True
 
 ------------------------------------------------Info------------------------------------------------
 json read...
@@ -435,16 +427,16 @@ json keys: dict_keys(['images', 'categories'])
 ...
 ```
 
-### 3.6 json文件拆分
+### 3.6 JSON文件拆分
 
-使用`json_Split.py`,可以将`instances_val2017.json`文件拆分为2个子集。
+使用`json_split.py`,可以将`instances_val2017.json`文件拆分为2个子集。
 
 #### 3.6.1 命令演示
 
 执行如下命令,拆分`instances_val2017.json`文件:
 
 ```
-python ./coco_tools/json_Split.py \
+python ./coco_tools/json_split.py \
     --json_all_path=./annotations/instances_val2017.json \
     --json_train_path=./instances_val2017_train.json \
     --json_val_path=./instances_val2017_val.json
@@ -453,17 +445,16 @@ python ./coco_tools/json_Split.py \
 #### 3.6.2 参数说明
 
 
-| 参数名                | 含义                                                                                   | 默认值        |
-| -------------------- | ------------------------------------------------------------------------------------- | ------------ |
-| `--json_all_path`    | 需要拆分的json文件路径                                                                   |              |
-| `--json_train_path`  | 生成的train部分json文件                                                                 |              |
-| `--json_val_path`    | 生成的val部分json文件                                                                   |              |
-| `--val_split_rate`   | (可选)拆分过程中,val集文件的比例                                                        | `0.1`        |
-| `--val_split_num`    | (可选)拆分过程中,val集文件的数量,<br />如果设置了该参数,则`--val_split_rate`参数失效       | `None`       |
-| `--keep_val_inTrain` | (可选)拆分过程中,是否在train中仍然保留val部分                                            | `False`      |
-| `--image_keyname`    | (可选)json文件中,图像对应的key                                                         | `'images'`    |
-| `--cat_keyname`      | (可选)json文件中,类别对应的key                                                         | `'categories'`|
-| `--Args_show`        | (可选)是否打印输入参数信息                                                              | `'True'`      |
+| 参数名                   | 含义                                                                                      | 默认值         |
+|-----------------------| ----------------------------------------------------------------------------------------- | -------------- |
+| `--json_all_path`     | 需要拆分的JSON文件路径                                                                    |                |
+| `--json_train_path`   | 生成的train部分JSON文件                                                                   |                |
+| `--json_val_path`     | 生成的val部分JSON文件                                                                     |                |
+| `--val_split_rate`    | (可选)拆分过程中,val集文件的比例                                                       | `0.1`          |
+| `--val_split_num`     | (可选)拆分过程中,val集文件的数量,<br />如果设置了该参数,则`--val_split_rate`参数失效 | `None`         |
+| `--keep_val_in_train` | (可选)拆分过程中,是否在train中仍然保留val部分                                          | `False`        |
+| `--img_keyname`       | (可选)JSON文件中,图像对应的key                                                         | `'images'`     |
+| `--cat_keyname`       | (可选)JSON文件中,类别对应的key                                                         | `'categories'` |
 
 #### 3.6.3 结果展示
 
@@ -476,10 +467,9 @@ json_train_path = ./instances_val2017_train.json
 json_val_path = ./instances_val2017_val.json
 val_split_rate = 0.1
 val_split_num = None
-keep_val_inTrain = False
-image_keyname = images
+keep_val_in_train = False
+img_keyname = images
 anno_keyname = annotations
-Args_show = True
 
 -----------------------------------------------Split------------------------------------------------
 
@@ -489,16 +479,16 @@ image total 5000, train 4500, val 500
 anno total 36781, train 33119, val 3662
 ```
 
-### 3.7 json文件合并
+### 3.7 JSON文件合并
 
-使用`json_Merge.py`,可以合并2个json文件。
+使用`json_merge.py`,可以合并2个JSON文件。
 
 #### 3.7.1 命令演示
 
 执行如下命令,合并`instances_train2017.json`与`instances_val2017.json`:
 
 ```
-python ./coco_tools/json_Merge.py \
+python ./coco_tools/json_merge.py \
     --json1_path=./annotations/instances_train2017.json \
     --json2_path=./annotations/instances_val2017.json \
     --save_path=./instances_trainval2017.json
@@ -507,13 +497,12 @@ python ./coco_tools/json_Merge.py \
 #### 3.7.2 参数说明
 
 
-| 参数名          | 含义                             | 默认值                       |
+| 参数名         | 含义                            | 默认值                      |
 | -------------- | ------------------------------- | --------------------------- |
-| `--json1_path` | 需要合并的json文件1路径            |                             |
-| `--json2_path` | 需要合并的json文件2路径            |                             |
-| `--save_path`  | 生成的json文件                    |                             |
-| `--merge_keys` | (可选)合并过程中需要合并的key      | `['images', 'annotations']` |
-| `--Args_show`  | (可选)是否打印输入参数信息         | `True`                      |
+| `--json1_path` | 需要合并的JSON文件1路径         |                             |
+| `--json2_path` | 需要合并的JSON文件2路径         |                             |
+| `--save_path`  | 生成的JSON文件                  |                             |
+| `--merge_keys` | (可选)合并过程中需要合并的key | `['images', 'annotations']` |
 
 #### 3.7.3 结果展示
 
@@ -525,7 +514,6 @@ json1_path = ./annotations/instances_train2017.json
 json2_path = ./annotations/instances_val2017.json
 save_path = ./instances_trainval2017.json
 merge_keys = ['images', 'annotations']
-Args_show = True
 
 -----------------------------------------------Merge------------------------------------------------
 

+ 108 - 121
docs/data/coco_tools_en.md

@@ -6,18 +6,16 @@
 
 coco_tools is a set of tools provided by PaddleRS for handling COCO annotation files. It is located in the `tools/coco_tools/` directory. Because [pycocotools library] (https://pypi.org/project/pycocotools/) cannot be installed in some environment, PaddleRS provides coco_tools as an alternative.
 
-*Please note that coco_tools is an experimental function at present. If you encounter problems when using coco_tools, please timely feedback to us.*
-
 ## 2 Document Description
 
 At present, coco_tools has 6 files, in the following we show each file and its function:
 
-- `json_InfoShow.py`:    Print basic information about each dictionary in the json file.
-- `json_ImgSta.py`:      Collect image information in json files and generate statistical tables and charts.
-- `json_AnnoSta.py`:     Collect annotation information in json files to generate statistical tables and charts.
-- `json_Img2Json.py`:    Collect images of the test set and generate json file.
-- `json_Split.py`:       Split the json file into train set and val set.
-- `json_Merge.py`:       Merge multiple json files into one.
+- `json_info_show.py`:    Print basic information about each dictionary in the JSON file.
+- `json_image_sta.py`:      Collect image information in JSON files and generate statistical tables and charts.
+- `json_anno_sta.py`:     Collect annotation information in JSON files to generate statistical tables and charts.
+- `json_image2json.py`:    Collect images of the test set and generate JSON file.
+- `json_split.py`:       Split the JSON file into train set and val set.
+- `json_merge.py`:       Merge multiple JSON files into one.
 
 ## 3 Usage Example
 
@@ -53,14 +51,14 @@ After the download is complete, you can copy or link the `coco_tools` directory
 
 ### 3.2 Printing json Information
 
-Using `json_InfoShow.py` allows you to print the keys of each key-value pair in a json file and output the first element in the value to help you quickly understand the annotation information. For COCO format annotations, you should pay special attention to the contents of the `image` and `annotation` fields.
+Using `json_info_show.py` allows you to print the keys of each key-value pair in a JSON file and output the first element in the value to help you quickly understand the annotation information. For COCO format annotations, you should pay special attention to the contents of the `image` and `annotation` fields.
 
 #### 3.2.1 Command Demonstration
 
 Run the following command to print the information in `instances_val2017.json` :
 
 ```
-python ./coco_tools/json_InfoShow.py \
+python ./coco_tools/json_info_show.py \
        --json_path=./annotations/instances_val2017.json \
        --show_num 5
 ```
@@ -68,11 +66,10 @@ python ./coco_tools/json_InfoShow.py \
 #### 3.2.2 Parameter Description
 
 
-| Parameter Name| Description                                                | Default Value |
-| ------------- | -----------------------------------------------------------| ------------- |
-| `--json_path` | Path of the json file whose statistics are to be collected.|               |
-| `--show_num`  | (Optional) Number of elements to show in the output. | `5`           |
-| `--Args_show` | (Optional) Whether to print input parameter information.   | `True`        |
+| Parameter Name | Description                                                 | Default Value |
+| -------------- | ----------------------------------------------------------- | ------------- |
+| `--json_path`  | Path of the JSON file whose statistics are to be collected. |               |
+| `--show_num`   | (Optional) Number of elements to show in the output.        | `5`           |
 
 #### 3.2.3 Result Presentation
 
@@ -82,7 +79,6 @@ After the preceding command is executed, the following information will be displ
 ------------------------------------------------Args------------------------------------------------
 json_path = ./annotations/instances_val2017.json
 show_num = 5
-Args_show = True
 
 ------------------------------------------------Info------------------------------------------------
 json read...
@@ -162,6 +158,7 @@ contributor : COCO Consortium
 ```
 'info', 'licenses', 'images', 'annotations', 'categories'
 ```
+
 Among them,
 
 - `'info'`: A dictionary. There are 6 key-value pairs, and the output shows the first five pairs.
@@ -172,30 +169,30 @@ Among them,
 
 ### 3.3 Statistical Image Information
 
-Using `json_ImgSta.py`, you can quickly extract image information from `instances_val2017.json`, generate csv tables, and generate statistical graphs.
+Using `json_image_sta.py`, you can quickly extract image information from `instances_val2017.json`, generate csv tables, and generate statistical graphs.
 
 #### 3.3.1 Command Demonstration
 
 Run the following command to print the information of `instances_val2017.json`:
 
 ```
-python ./coco_tools/json_ImgSta.py \
+python ./coco_tools/json_image_sta.py \
     --json_path=./annotations/instances_val2017.json \
     --csv_path=./img_sta/images.csv \
-    --png_shape_path=./img_sta/images_shape.png \
-    --png_shapeRate_path=./img_sta/images_shapeRate.png
+    --img_shape_path=./img_sta/img_shape.png \
+    --img_shape_rate_path=./img_sta/img_shape_rate.png
 ```
 
 #### 3.3.2 Parameter Description
 
-| Parameter Name         | Description                                                                | Default Value    |
-| ---------------------- | --------------------------------------------------------------------- | -------- |
-| `--json_path`          | Path of the json file whose statistics are to be collected.|          |
-| `--csv_path`           | (Optional) Path for the statistics table.| `None`   |
-| `--png_shape_path`     | (Optional) .png image saving path. The image visualizes the two-dimensional distribution of all image shapes.                   | `5`      |
-| `--png_shapeRate_path` | (Optional) .png image saving path. The image visualizes the one-dimensional distribution of shape ratio (width/height) of all images.           | `5`      |
-| `--image_keyname`      | (Optional) Image key in the json file.|`'images'`|
-| `--Args_show`          | (Optional) Whether to print input parameter information.       |`True`    |
+
+| Parameter Name          | Description                                                                                                                           | Default Value |
+|-------------------------| ------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
+| `--json_path`           | Path of the JSON file whose statistics are to be collected.                                                                           |               |
+| `--csv_path`            | (Optional) Path for the statistics table.                                                                                             | `None`        |
+| `--img_shape_path`      | (Optional) Output image saving path. The image visualizes the two-dimensional distribution of all image shapes.                         | `5`           |
+| `--img_shape_rate_path` | (Optional) Output image saving path. The image visualizes the one-dimensional distribution of shape ratio (width/height) of all images. | `5`           |
+| `--img_keyname`         | (Optional) Image key in the JSON file.                                                                                                | `'images'`    |
 
 #### 3.3.3 Result Presentation
 
@@ -204,25 +201,24 @@ After the preceding command is executed, the following information will be displ
 ```
 ------------------------------------------------Args------------------------------------------------
 json_path = ./annotations/instances_val2017.json
-csv_path = ./img_sta/images.csv
-png_shape_path = ./img_sta/images_shape.png
-png_shapeRate_path = ./img_sta/images_shapeRate.png
-image_keyname = images
-Args_show = True
+csv_path = ./img_sta/img.csv
+img_shape_path = ./img_sta/img_shape.png
+img_shape_rate_path = ./img_sta/img_shape_rate.png
+img_keyname = images
 
 json read...
 
 make dir: ./img_sta
-png save to ./img_sta/images_shape.png
-png save to ./img_sta/images_shapeRate.png
-csv save to ./img_sta/images.csv
+png save to ./img_sta/img_shape.png
+png save to ./img_sta/img_shape_rate.png
+csv save to ./img_sta/img.csv
 ```
 
 Part of the table:
 
 
 |   | license | file_name        | coco_url                                               | height | width | date_captured       | flickr_url                                                     | id     | shape_rate |
-| --- | --------- | ------------------ | -------------------------------------------------------- | -------- | ------- | --------------------- | ---------------------------------------------------------------- | -------- | ------------ |
+| - | ------- | ---------------- | ------------------------------------------------------ | ------ | ----- | ------------------- | -------------------------------------------------------------- | ------ | ---------- |
 | 0 | 4       | 000000397133.jpg | http://images.cocodataset.org/val2017/000000397133.jpg | 427    | 640   | 2013-11-14 17:02:52 | http://farm7.staticflickr.com/6116/6255196340_da26cf2c9e_z.jpg | 397133 | 1.5        |
 | 1 | 1       | 000000037777.jpg | http://images.cocodataset.org/val2017/000000037777.jpg | 230    | 352   | 2013-11-14 20:55:31 | http://farm9.staticflickr.com/8429/7839199426_f6d48aa585_z.jpg | 37777  | 1.5        |
 | 2 | 4       | 000000252219.jpg | http://images.cocodataset.org/val2017/000000252219.jpg | 428    | 640   | 2013-11-14 22:32:02 | http://farm4.staticflickr.com/3446/3232237447_13d84bd0a1_z.jpg | 252219 | 1.5        |
@@ -238,42 +234,41 @@ One-dimensional distribution of shape ratio (width/height) of all images:
 
 ### 3.4 Collect Statistics about the Object Detection Label Box
 
-Using `json_AnnoSta.py`, you can quickly extract annotation information from `instances_val2017.json`, generate csv tables, and generate statistical graphs.
-
+Using `json_anno_sta.py`, you can quickly extract annotation information from `instances_val2017.json`, generate csv tables, and generate statistical graphs.
 
 #### 3.4.1 Command Demonstration
 
 Run the following command to print the information of `instances_val2017.json`:
 
 ```
-python ./coco_tools/json_AnnoSta.py \
+python ./coco_tools/json_anno_sta.py \
     --json_path=./annotations/instances_val2017.json \
-    --csv_path=./anno_sta/annos.csv \
-    --png_shape_path=./anno_sta/annos_shape.png \
-    --png_shapeRate_path=./anno_sta/annos_shapeRate.png \
-    --png_pos_path=./anno_sta/annos_pos.png \
-    --png_posEnd_path=./anno_sta/annos_posEnd.png \
-    --png_cat_path=./anno_sta/annos_cat.png \
-    --png_objNum_path=./anno_sta/annos_objNum.png \
+    --csv_path=./anno_sta/obj.csv \
+    --obj_shape_path=./anno_sta/obj_shape.png \
+    --obj_shape_rate_path=./anno_sta/obj_shape_rate.png \
+    --obj_pos_path=./anno_sta/obj_pos.png \
+    --obj_pos_end_path=./anno_sta/obj_pos_end.png \
+    --obj_cat_path=./anno_sta/obj_cat.png \
+    --obj_num_path=./anno_sta/obj_num.png \
     --get_relative=True
 ```
 
 #### 3.4.2 Parameter Description
 
-| Parameter Name                 | Description                                                                                                       | Default Value         |
-| ---------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------- |
-| `--json_path`          | (Optional) Path of the json file whose statistics you want to collect.                                                    |               |
-| `--csv_path`           | (Optional) Path to save the statistics table.                                                                            | `None`        |
-| `--png_shape_path`     | (Optional) .png image saving path. The image visualizes the two-dimensional distribution of the shape of all target detection frames.| `None`        |
-| `--png_shapeRate_path` | (Optional) .png image saving path. The image visualizes the one-dimensional distribution of shape ratio (width/height) of all target bounding boxes.| `None`        |
-| `--png_pos_path`       | (Optional) .png image saving path. The image visualizes the two-dimensional distribution of the coordinates at the upper left corner of all bounding boxes. | `None`        |
-| `--png_posEnd_path`    | (Optional) .png image saving path. The image visualizes the two-dimensional distribution of the coordinates at the lower right corner of all bounding boxes.| `None`        |
-| `--png_cat_path`       | (Optional) .png image saving path. The image visualizes the quantity distribution of objects in each category.                                                      | `None`        |
-| `--png_objNum_path`    | (Optional) .png image saving path. The image visualizes the quantity distribution of annotated objects in a single image.                                           | `None`        |
-| `--get_relative`       | (Optional) Whether to generate the shape of the image target detection frame and the relative ratio of the coordinates of the upper left corner and lower right corner of the object detection frame (horizontal axis coordinates/image length, vertical axis coordinates/image width).| `None`        |
-| `--image_keyname`      | (Optional) Image key in the json file.                                                                                                     | `'images'`    |
-| `--anno_keyname`       | (Optional) Annotation key in the json file.                                                                                                         | `'annotations'`|
-| `--Args_show`          | (Optional) Whether to print input parameter information.                                                                                                            | `True`        |
+
+| Parameter Name          | Description                                                                                                                                                                                                                                                                             | Default Value   |
+|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|
+| `--json_path`           | Path of the JSON file whose statistics you want to collect.                                                                                                                                                                                                                             |                 |
+| `--csv_path`            | (Optional) Path to save the statistics table.                                                                                                                                                                                                                                           | `None`          |
+| `--obj_shape_path`      | (Optional) Output image saving path. The image visualizes the two-dimensional distribution of the shape of all object detection boxes.                                                                                                                                                    | `None`          |
+| `--obj_shape_rate_path` | (Optional) Output image saving path. The image visualizes the one-dimensional distribution of shape ratio (width/height) of all target bounding boxes.                                                                                                                                    | `None`          |
+| `--obj_pos_path`        | (Optional) Output image saving path. The image visualizes the two-dimensional distribution of the coordinates at the upper left corner of all bounding boxes.                                                                                                                             | `None`          |
+| `--obj_pos_end_path`    | (Optional) Output image saving path. The image visualizes the two-dimensional distribution of the coordinates at the lower right corner of all bounding boxes.                                                                                                                            | `None`          |
+| `--obj_cat_path`        | (Optional) Output image saving path. The image visualizes the quantity distribution of objects in each category.                                                                                                                                                                          | `None`          |
+| `--obj_obj_num_path`    | (Optional) Output image saving path. The image visualizes the quantity distribution of annotated objects in a single image.                                                                                                                                                               | `None`          |
+| `--get_relative`        | (Optional) Whether to generate the shape of the image target detection frame and the relative ratio of the coordinates of the upper left corner and lower right corner of the object detection frame (horizontal axis coordinates/image length, vertical axis coordinates/image width). | `False`         |
+| `--img_keyname`         | (Optional) Image key in the JSON file.                                                                                                                                                                                                                                                  | `'images'`      |
+| `--anno_keyname`        | (Optional) Annotation key in the JSON file.                                                                                                                                                                                                                                             | `'annotations'` |
 
 #### 3.4.3 Result Presentation
 
@@ -282,31 +277,30 @@ After the preceding command is executed, the following information will be displ
 ```
 ------------------------------------------------Args------------------------------------------------
 json_path = ./annotations/instances_val2017.json
-csv_path = ./anno_sta/annos.csv
-png_shape_path = ./anno_sta/annos_shape.png
-png_shapeRate_path = ./anno_sta/annos_shapeRate.png
-png_pos_path = ./anno_sta/annos_pos.png
-png_posEnd_path = ./anno_sta/annos_posEnd.png
-png_cat_path = ./anno_sta/annos_cat.png
-png_objNum_path = ./anno_sta/annos_objNum.png
+csv_path = ./anno_sta/obj.csv
+obj_shape_path = ./anno_sta/obj_shape.png
+obj_shape_rate_path = ./anno_sta/obj_shape_rate.png
+obj_pos_path = ./anno_sta/obj_pos.png
+obj_pos_end_path = ./anno_sta/obj_pos_end.png
+obj_cat_path = ./anno_sta/obj_cat.png
+obj_obj_num_path = ./anno_sta/obj_obj_num.png
 get_relative = True
-image_keyname = images
+img_keyname = images
 anno_keyname = annotations
-Args_show = True
 
 json read...
 
 make dir: ./anno_sta
-png save to ./anno_sta/annos_shape.png
-png save to ./anno_sta/annos_shape_Relative.png
-png save to ./anno_sta/annos_shapeRate.png
-png save to ./anno_sta/annos_pos.png
-png save to ./anno_sta/annos_pos_Relative.png
-png save to ./anno_sta/annos_posEnd.png
-png save to ./anno_sta/annos_posEnd_Relative.png
-png save to ./anno_sta/annos_cat.png
-png save to ./anno_sta/annos_objNum.png
-csv save to ./anno_sta/annos.csv
+png save to ./anno_sta/obj_shape.png
+png save to ./anno_sta/obj_shape_relative.png
+png save to ./anno_sta/obj_shape_rate.png
+png save to ./anno_sta/obj_pos.png
+png save to ./anno_sta/obj_pos_relative.png
+png save to ./anno_sta/obj_pos_end.png
+png save to ./anno_sta/obj_pos_end_relative.png
+png save to ./anno_sta/obj_cat.png
+png save to ./anno_sta/obj_num.png
+csv save to ./anno_sta/obj.csv
 ```
 
 Part of the table:
@@ -351,15 +345,15 @@ A single image contains the quantity distribution of annotated objects:
 
 ### 3.5 Stat Image Information to Generates json
 
-Using `json_Img2Json.py`, you can quickly extract image information according to the file information in `test2017` and the training set json file, and generate the test set json file.
+Using `json_image2json.py`, you can quickly extract image information according to the file information in `test2017` and the training set JSON file, and generate the test set JSON file.
 
 #### 3.5.1 Command Demonstration
 
 Run the following command to collect and generate `test2017` information:
 
 ```
-python ./coco_tools/json_Img2Json.py \
-    --test_image_path=./test2017 \
+python ./coco_tools/json_image2json.py \
+    --image_dir=./test2017 \
     --json_train_path=./annotations/instances_val2017.json \
     --json_test_path=./test.json
 ```
@@ -367,14 +361,13 @@ python ./coco_tools/json_Img2Json.py \
 #### 3.5.2 Parameter Description
 
 
-| Parameter Name      | Description                                                       | Default Value        |
-| ------------------- | ----------------------------------------------------------------- | ------------ |
-| `--test_image_path` | Directory that contains the test seg images.                   |              |
-| `--json_train_path` | json file path of the training set. Used as reference.                 |              |
-| `--json_test_path`  | Path to the generated test set json file.                   |              |
-| `--image_keyname`   | (Optional) Image key in the json file    | `'images'`    |
-| `--cat_keyname`     | (Optional) Category key in the json file     | `'categories'`|
-| `--Args_show`       | (Optional) Whether to print input parameter information.          | `True`        |
+| Parameter Name      | Description                                            | Default Value  |
+|---------------------|--------------------------------------------------------| -------------- |
+| `--image_dir`       | Directory that contains the test set images.           |                |
+| `--json_train_path` | JSON file path of the training set. Used as reference. |                |
+| `--json_test_path`  | Path to the generated test set JSON file.              |                |
+| `--img_keyname`     | (Optional) Image key in the JSON file.                 | `'images'`     |
+| `--cat_keyname`     | (Optional) Category key in the JSON file.              | `'categories'` |
 
 #### 3.5.3 Result Presentation
 
@@ -382,10 +375,9 @@ After the preceding command is executed, the following information will be displ
 
 ```
 ------------------------------------------------Args------------------------------------------------
-test_image_path = ./test2017
+image_dir = ./test2017
 json_train_path = ./annotations/instances_val2017.json
 json_test_path = ./test.json
-Args_show = True
 
 ----------------------------------------------Get Test----------------------------------------------
 
@@ -397,13 +389,12 @@ test image read...
  total test image: 40670
 ```
 
-The generated json file information:
+The generated JSON file information:
 
 ```
 ------------------------------------------------Args------------------------------------------------
 json_path = ./test.json
 show_num = 5
-Args_show = True
 
 ------------------------------------------------Info------------------------------------------------
 json read...
@@ -438,14 +429,14 @@ json keys: dict_keys(['images', 'categories'])
 
 ### 3.6 json File Splitting
 
-Using `json_Split.py`, you can split the `instances_val2017.json` file into 2 subsets.
+Using `json_split.py`, you can split the `instances_val2017.json` file into 2 subsets.
 
 #### 3.6.1 Command Demonstration
 
 Run the following command to split the `instances_val2017.json` file:
 
 ```
-python ./coco_tools/json_Split.py \
+python ./coco_tools/json_split.py \
     --json_all_path=./annotations/instances_val2017.json \
     --json_train_path=./instances_val2017_train.json \
     --json_val_path=./instances_val2017_val.json
@@ -454,17 +445,16 @@ python ./coco_tools/json_Split.py \
 #### 3.6.2 Parameter Description
 
 
-| Parameter Name       | Description                                                                                                               | Default Value |
-| -------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------  |
-| `--json_all_path`    | Path to the original json file.                                                                                |               |
-| `--json_train_path`  | Generated json file for the train set.                                                                                 |               |
-| `--json_val_path`    | Generated json file for the val set.                                                                                   |               |
-| `--val_split_rate`   | (Optional) Proportion of files in the val set.                                                      | `0.1`         |
-| `--val_split_num`    | (Optional) Number of val set files. If this parameter is set, `--val_split_rate` will be invalidated. | `None`        |
-| `--keep_val_inTrain` | (Optional) Whether to keep the val set samples in the train set.                                                     | `False`       |
-| `--image_keyname`    | (Optional) Image key in the json file.                                                            | `'images'`    |
-| `--cat_keyname`      | (Optional) Category key in the json file.                                                        | `'categories'`|
-| `--Args_show`        | (Optional) Whether to print input parameter information.                                                                   | `'True'`      |
+| Parameter Name        | Description                                                                                          | Default Value  |
+|-----------------------| ---------------------------------------------------------------------------------------------------- | -------------- |
+| `--json_all_path`     | Path to the original JSON file.                                                                      |                |
+| `--json_train_path`   | Generated JSON file for the train set.                                                               |                |
+| `--json_val_path`     | Generated JSON file for the val set.                                                                 |                |
+| `--val_split_rate`    | (Optional) Proportion of files in the val set.                                                       | `0.1`          |
+| `--val_split_num`     | (Optional) Number of val set files. If this parameter is set,`--val_split_rate` will be invalidated. | `None`         |
+| `--keep_val_in_train` | (Optional) Whether to keep the val set samples in the train set.                                     | `False`        |
+| `--img_keyname`       | (Optional) Image key in the JSON file.                                                               | `'images'`     |
+| `--cat_keyname`       | (Optional) Category key in the JSON file.                                                            | `'categories'` |
 
 #### 3.6.3 Result Presentation
 
@@ -477,10 +467,9 @@ json_train_path = ./instances_val2017_train.json
 json_val_path = ./instances_val2017_val.json
 val_split_rate = 0.1
 val_split_num = None
-keep_val_inTrain = False
-image_keyname = images
+keep_val_in_train = False
+img_keyname = images
 anno_keyname = annotations
-Args_show = True
 
 -----------------------------------------------Split------------------------------------------------
 
@@ -492,14 +481,14 @@ anno total 36781, train 33119, val 3662
 
 ### 3.7 json File Merging
 
-Using `json_Merge.py` to merge two json files.
+Using `json_merge.py` to merge two JSON files.
 
 #### 3.7.1 Command Demonstration
 
 Run the following command to merge `instances_train2017.json` and `instances_val2017.json`:
 
 ```
-python ./coco_tools/json_Merge.py \
+python ./coco_tools/json_merge.py \
     --json1_path=./annotations/instances_train2017.json \
     --json2_path=./annotations/instances_val2017.json \
     --save_path=./instances_trainval2017.json
@@ -508,13 +497,12 @@ python ./coco_tools/json_Merge.py \
 #### 3.7.2 Parameter Description
 
 
-| Parameter Name | Description                                                      | Default Value                       |
-| -------------- | ---------------------------------------------------------------- | --------------------------- |
-| `--json1_path` | Path of the first json file to merge.                                        |                             |
-| `--json2_path` | Path of the second json file to merge.                                         |                             |
-| `--save_path`  | Path to save the merged json file.                                              |                             |
-| `--merge_keys` | (Optional) Keys to be merged.      | `['images', 'annotations']` |
-| `--Args_show`  | (Optional) Whether to print input parameter information.          | `True`                      |
+| Parameter Name | Description                                              | Default Value               |
+| -------------- | -------------------------------------------------------- | --------------------------- |
+| `--json1_path` | Path of the first JSON file to merge.                    |                             |
+| `--json2_path` | Path of the second JSON file to merge.                   |                             |
+| `--save_path`  | Path to save the merged JSON file.                       |                             |
+| `--merge_keys` | (Optional) Keys to be merged.                            | `['images', 'annotations']` |
 
 #### 3.7.3 Result Presentation
 
@@ -526,7 +514,6 @@ json1_path = ./annotations/instances_train2017.json
 json2_path = ./annotations/instances_val2017.json
 save_path = ./instances_trainval2017.json
 merge_keys = ['images', 'annotations']
-Args_show = True
 
 -----------------------------------------------Merge------------------------------------------------
 

+ 17 - 17
docs/data/tools_cn.md

@@ -39,12 +39,12 @@ python coco2mask.py --raw_dir {输入目录路径} --save_dir {输出目录路
 `mask2shape.py`的主要功能是将.png格式的分割结果转换为shapefile格式(矢量图)。使用方式如下:
 
 ```shell
-python mask2shape.py --srcimg_path {带有地理信息的原始影像路径} --mask_path {输入分割标签路径} [--save_path {输出矢量图路径}] [--ignore_index {需要忽略的索引值}]
+python mask2shape.py --src_img_path {带有地理信息的原始影像路径} --mask_path {输入分割标签路径} [--save_path {输出矢量图路径}] [--ignore_index {需要忽略的索引值}]
 ```
 
 其中:
 
-- `srcimg_path`:原始影像路径,需要带有地理元信息,以便为生成的shapefile提供地理投影坐标系等信息。
+- `src_img_path`:原始影像路径,需要带有地理元信息,以便为生成的shapefile提供地理投影坐标系等信息。
 - `mask_path`:模型推理得到的.png格式的分割结果。
 - `save_path`:保存shapefile的路径,默认为`output`。
 - `ignore_index`:需要在shapefile中忽略的索引值(例如分割任务中的背景类),默认为`255`。
@@ -54,12 +54,12 @@ python mask2shape.py --srcimg_path {带有地理信息的原始影像路径} --m
 `geojson2mask.py`的主要功能是将GeoJSON格式的标签转换为.tif的栅格格式。使用方式如下:
 
 ```shell
-python geojson2mask.py --srcimg_path {带有地理信息的原始影像路径} --geojson_path {输入分割标签路径} --save_path {输出路径}
+python geojson2mask.py --src_img_path {带有地理信息的原始影像路径} --geojson_path {输入分割标签路径} --save_path {输出路径}
 ```
 
 其中:
 
-- `srcimg_path`:原始影像路径,需要带有地理元信息。
+- `src_img_path`:原始影像路径,需要带有地理元信息。
 - `geojson_path`:GeoJSON格式标签路径。
 - `save_path`:保存转换后的栅格文件的路径。
 
@@ -68,15 +68,15 @@ python geojson2mask.py --srcimg_path {带有地理信息的原始影像路径} -
 `match.py`的主要功能是在对两个时相的遥感影像进行空间配准。使用方式如下:
 
 ```shell
-python match.py --im1_path {时相1影像路径} --im2_path {时相2影像路径} --save_path {配准后时相2影像输出路径} [--im1_bands 1 2 3] [--im2_bands 1 2 3]
+python match.py --image1_path {时相1影像路径} --image2_path {时相2影像路径} --save_path {配准后时相2影像输出路径} [--image1_bands 1 2 3] [--image2_bands 1 2 3]
 ```
 
 其中:
 
-- `im1_path`:时相1影像路径。该影像必须包含地理信息,且配准过程中以该影像为基准影像。
-- `im2_path`:时相2影像路径。该影像的地理信息将不被用到。配准过程中将该影像配准到时相1影像。
-- `im1_bands`:时相1影像用于配准的波段,指定为三通道(分别代表R、G、B)或单通道,默认为`[1, 2, 3]`。
-- `im2_bands`:时相2影像用于配准的波段,指定为三通道(分别代表R、G、B)或单通道,默认为`[1, 2, 3]`。
+- `image1_path`:时相1影像路径。该影像必须包含地理信息,且配准过程中以该影像为基准影像。
+- `image2_path`:时相2影像路径。该影像的地理信息将不被用到。配准过程中将该影像配准到时相1影像。
+- `image1_bands`:时相1影像用于配准的波段,指定为三通道(分别代表R、G、B)或单通道,默认为`[1, 2, 3]`。
+- `image2_bands`:时相2影像用于配准的波段,指定为三通道(分别代表R、G、B)或单通道,默认为`[1, 2, 3]`。
 - `save_path`: 配准后时相2影像输出路径。
 
 ### split
@@ -98,12 +98,12 @@ python split.py --image_path {输入影像路径} [--mask_path {真值标签路
 
 目前`coco_tools`目录中共包含6个工具,各工具功能如下:
 
-- `json_InfoShow.py`:    打印json文件中各个字典的基本信息;
-- `json_ImgSta.py`:      统计json文件中的影像信息,生成统计表、统计图;
-- `json_AnnoSta.py`:     统计json文件中的标注信息,生成统计表、统计图;
-- `json_Img2Json.py`:    统计test集影像,生成json文件;
-- `json_Split.py`:       将json文件中的内容划分为train set和val set;
-- `json_Merge.py`:       将多个json文件合并为一个。
+- `json_info_show.py`:    打印JSON文件中各个字典的基本信息;
+- `json_image_sta.py`:      统计JSON文件中的影像信息,生成统计表、统计图;
+- `json_anno_sta.py`:     统计JSON文件中的标注信息,生成统计表、统计图;
+- `json_image2json.py`:    统计test集影像,生成JSON文件;
+- `json_split.py`:       将JSON文件中的内容划分为train set和val set;
+- `json_merge.py`:       将多个JSON文件合并为一个。
 
 详细使用方法请参见[coco_tools使用说明](coco_tools_cn.md)。
 
@@ -133,12 +133,12 @@ python prepare_dataset/prepare_levircd.py --help
 `extract_ms_patches.py`的主要功能是利用四叉树从整幅遥感影像中提取不同尺度的包含感兴趣目标的影像块,提取的影像块可用作模型训练样本。使用方式如下:
 
 ```shell
-python extract_ms_patches.py --im_paths {一个或多个输入影像路径} --mask_path {真值标签路径} [--save_dir {输出目录}] [--min_patch_size {最小的影像块尺寸}] [--bg_class {背景类类别编号}] [--target_class {目标类类别编号}] [--max_level {检索的最大尺度层级}] [--include_bg] [--nonzero_ratio {影像块中非零像素占比阈值}] [--visualize]
+python extract_ms_patches.py --image_paths {一个或多个输入影像路径} --mask_path {真值标签路径} [--save_dir {输出目录}] [--min_patch_size {最小的影像块尺寸}] [--bg_class {背景类类别编号}] [--target_class {目标类类别编号}] [--max_level {检索的最大尺度层级}] [--include_bg] [--nonzero_ratio {影像块中非零像素占比阈值}] [--visualize]
 ```
 
 其中:
 
-- `im_paths`:源影像路径,可以指定多个路径。
+- `image_paths`:源影像路径,可以指定多个路径。
 - `mask_path`:真值标签路径。
 - `save_dir`:保存切分后结果的文件夹路径,默认为`output`。
 - `min_patch_size`:提取的影像块的最小尺寸(以影像块长/宽的像素个数计),即四叉树的叶子结点在图中覆盖的最小范围,默认为`256`。

+ 17 - 17
docs/data/tools_en.md

@@ -39,12 +39,12 @@ Among them:
 The main function of `mask2shape.py` is to convert the segmentation results in .png format into shapefile format (vector graphics). The usage is as follows:
 
 ```shell
-python mask2shape.py --srcimg_path {path to the original image with geographic information} --mask_path {path to segmentation mask} [--save_path {path to save the output vector graphics}] [--ignore_index {index value to be ignored}]
+python mask2shape.py --src_img_path {path to the original image with geographic information} --mask_path {path to segmentation mask} [--save_path {path to save the output vector graphics}] [--ignore_index {index value to be ignored}]
 ```
 
 Among them:
 
-- `srcimg_path`: Path to the original image with geographic information, which is required to provide the shapefile with geoprojection coordinate system information.
+- `src_img_path`: Path to the original image with geographic information, which is required to provide the shapefile with geoprojection coordinate system information.
 - `mask_path`: Path to the .png format segmentation result obtained by the model inference.
 - `save_path`: Path to save the shapefile. The default value is `output`.
 - `ignore_index`: Index value to be ignored in the shapefile, such as the background class ID in segmentation tasks. The default value is `255`.
@@ -54,12 +54,12 @@ Among them:
 The main function of `geojson2mask.py` is to convert the GeoJSON-formatted labels to a .tif raster format. The usage is as follows:
 
 ```shell
-python geojson2mask.py --srcimg_path {path to the original image with geographic information} --geojson_path {path to segmentation mask} --save_path {output path}
+python geojson2mask.py --src_img_path {path to the original image with geographic information} --geojson_path {path to segmentation mask} --save_path {output path}
 ```
 
 Among them:
 
-- `srcimg_path`: Path to the original image file that contains the geospatial information.
+- `src_img_path`: Path to the original image file that contains the geospatial information.
 - `geojson_path`: Path to the GeoJSON format label file.
 - `save_path`: Path to save the converted raster file.
 
@@ -68,15 +68,15 @@ Among them:
 The main function of `match.py` is to perform spatial registration on two temporal remote sensing images. The usage is as follows:
 
 ```shell
-python match.py --im1_path {path to temporal image 1} --im2_path {path to temporal image 2} --save_path {output path to registered image} [--im1_bands 1 2 3] [--im2_bands 1 2 3]
+python match.py --image1_path {path to temporal image 1} --image2_path {path to temporal image 2} --save_path {output path to registered image} [--image1_bands 1 2 3] [--image2_bands 1 2 3]
 ```
 
 Among them:
 
-- `im1_path`: File path of the first temporal image. This image must contain geospatial information and will be used as the reference image during the registration process.
-- `im2_path`: File path of the second temporal image. The geospatial information of this image will not be used. This image will be registered to the first temporal image.
-- `im1_bands`: Bands of the first temporal image used for registration, specified as three channels (representing R, G, and B) or a single channel. Default is `[1, 2, 3]`.
-- `im2_bands`: Bands of the second temporal image used for registration, specified as three channels (representing R, G, and B) or a single channel. Default is `[1, 2, 3]`.
+- `image1_path`: File path of the first temporal image. This image must contain geospatial information and will be used as the reference image during the registration process.
+- `image2_path`: File path of the second temporal image. The geospatial information of this image will not be used. This image will be registered to the first temporal image.
+- `image1_bands`: Bands of the first temporal image used for registration, specified as three channels (representing R, G, and B) or a single channel. Default is `[1, 2, 3]`.
+- `image2_bands`: Bands of the second temporal image used for registration, specified as three channels (representing R, G, and B) or a single channel. Default is `[1, 2, 3]`.
 - `save_path`: Output file path of the registered image.
 
 ### split
@@ -98,12 +98,12 @@ Among them:
 
 There are six tools included in the `coco_tools` directory, each with the following functions
 
-- `json_InfoShow.py`:    Print basic information about each dictionary in the json file.
-- `json_ImgSta.py`:      Collect image information in json files and generate statistical tables and charts.
-- `json_AnnoSta.py`:     Collect annotation information in json files to generate statistical tables and charts.
-- `json_Img2Json.py`:    Collect images of the test set and generate json file.
-- `json_Split.py`:       Split the json file into train set and val set.
-- `json_Merge.py`:       Merge multiple json files into one.
+- `json_info_show.py`:    Print basic information about each dictionary in the JSON file.
+- `json_image_sta.py`:      Collect image information in JSON files and generate statistical tables and charts.
+- `json_anno_sta.py`:     Collect annotation information in JSON files to generate statistical tables and charts.
+- `json_image2json.py`:    Collect images of the test set and generate JSON file.
+- `json_split.py`:       Split the JSON file into train set and val set.
+- `json_merge.py`:       Merge multiple JSON files into one.
 
 For detailed usage instructions, please refer to [coco_tools Usage Instructions](coco_tools_en.md).
 
@@ -133,12 +133,12 @@ You can refer to [this document](../intro/data_prep_en.md) to see which preproce
 The main function of `extract_ms_patches.py` is to extract image patches containing objects of interest at different scales from the entire remote sensing image using a quadtree. The extracted image patches can be used as training samples for deep learning models. The usage is as follows:
 
 ```shell
-python extract_ms_patches.py --im_paths {one or more input image paths} --mask_path {ground-truth label image path} [--save_dir {output directory}] [--min_patch_size {minimum patch size}] [--bg_class {background category ID}] [--target_class {target category ID}] [--max_level {maximum scale level}] [--include_bg] [--nonzero_ratio {threshold of the ratio of nonzero pixels}] [--visualize]
+python extract_ms_patches.py --image_paths {one or more input image paths} --mask_path {ground-truth label image path} [--save_dir {output directory}] [--min_patch_size {minimum patch size}] [--bg_class {background category ID}] [--target_class {target category ID}] [--max_level {maximum scale level}] [--include_bg] [--nonzero_ratio {threshold of the ratio of nonzero pixels}] [--visualize]
 ```
 
 Among them:
 
-- `im_paths`: Path of the source image(s). Multiple paths can be specified.
+- `image_paths`: Path of the source image(s). Multiple paths can be specified.
 - `mask_path`: Path to the ground-truth label.
 - `save_dir`: Path to the directory to save the split result. Default is `output`.
 - `min_patch_size`: Minimum size of the extracted image block (in terms of the number of pixels in the height/width of the image block). This is the minimum area covered by a leaf node in the quadtree. Default is `256`.

+ 37 - 0
tests/tools/run_coco_tools.py

@@ -0,0 +1,37 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import tempfile
+
+from testing_utils import run_script
+
+if __name__ == '__main__':
+    run_script(
+        f"python coco_tools/json_info_show.py --json_path ../tests/data/instances_val2017.json",
+        wd="../tools")
+    run_script(
+        f"python coco_tools/json_image2json.py --image_dir ../tests/data/img_test --json_train_path ../tests/data/instances_train2017.json --result_path ../tests/data/test.json",
+        wd="../tools")
+    run_script(
+        f"python coco_tools/json_merge.py --json1_path ../tests/data/instances_train2017.json --json2_path ../tests/data/instances_train2017.json --save_path ../tests/data/instances_trainval2017.json",
+        wd="../tools")
+    run_script(
+        f"python coco_tools/json_split.py --json_all_path ../tests/data/instances_train2017.json --json_train_path ../tests/data/instances_train2017_1.json --json_val_path ../tests/data/instances_train2017_2.json",
+        wd="../tools")
+    run_script(
+        f"python coco_tools/json_image_sta.py --json_path ../tests/data/instances_train2017.json --csv_path ../tests/data/instances_val2017_images.csv --pic_shape_path ../tests/data/images_shape.png --pic_shape_rate_path ../tests/data/shape_rate.png",
+        wd="../tools")
+    run_script(
+        f"python coco_tools/json_anno_sta.py --json_path ../tests/data/instances_train2017.json --csv_path ../tests/data/instances_val2017_annos.csv --pic_shape_path ../tests/data/images_shape.png --pic_shape_rate_path ../tests/data/shape_rate.png --pic_pos_path ../tests/data/pos.png --pic_pos_end_path ../tests/data/pos_end.png --pic_cat_path ../tests/data/cat.png --pic_obj_num_path ../tests/data/obj_num.png",
+        wd="../tools")

+ 1 - 1
tests/tools/run_extract_ms_patches.py

@@ -19,5 +19,5 @@ from testing_utils import run_script
 if __name__ == '__main__':
     with tempfile.TemporaryDirectory() as td:
         run_script(
-            f"python extract_ms_patches.py --im_paths ../tests/data/ssst/multispectral.tif --mask_path ../tests/data/ssst/multiclass_gt2.png --min_patch_size 32 --save_dir {td}",
+            f"python extract_ms_patches.py --image_paths ../tests/data/ssst/multispectral.tif --mask_path ../tests/data/ssst/multiclass_gt2.png --min_patch_size 32 --save_dir {td}",
             wd="../tools")

+ 1 - 1
tests/tools/run_match.py

@@ -19,5 +19,5 @@ from testing_utils import run_script
 if __name__ == '__main__':
     with tempfile.TemporaryDirectory() as td:
         run_script(
-            f"python match.py --im1_path ../tests/data/ssmt/multispectral_t1.tif --im2_path ../tests/data/ssmt/multispectral_t1.tif --save_path {td}/out.tiff",
+            f"python match.py --image1_path ../tests/data/ssmt/multispectral_t1.tif --image2_path ../tests/data/ssmt/multispectral_t1.tif --save_path {td}/out.tiff",
             wd="../tools")

+ 1 - 1
tests/tools/run_oif.py

@@ -16,5 +16,5 @@ from testing_utils import run_script
 
 if __name__ == '__main__':
     run_script(
-        f"python oif.py --im_path ../tests/data/ssst/multispectral.tif",
+        f"python oif.py --image_path ../tests/data/ssst/multispectral.tif",
         wd="../tools")

+ 1 - 1
tests/tools/run_pca.py

@@ -19,5 +19,5 @@ from testing_utils import run_script
 if __name__ == '__main__':
     with tempfile.TemporaryDirectory() as td:
         run_script(
-            f"python pca.py --im_path ../tests/data/ssst/multispectral.tif --save_dir {td} --dim 5",
+            f"python pca.py --image_path ../tests/data/ssst/multispectral.tif --save_dir {td} --dim 5",
             wd="../tools")

+ 0 - 257
tools/coco_tools/json_AnnoSta.py

@@ -1,257 +0,0 @@
-# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""
-@File Description:
-# json文件annotations信息,生成统计结果csv,对象框shape、对象看shape比例、对象框起始位置、对象结束位置、对象结束位置、对象类别、单个图像对象数量的分布
-python ./coco_tools/json_AnnoSta.py \
-    --json_path=./annotations/instances_val2017.json \
-    --csv_path=./anno_sta/annos.csv \
-    --png_shape_path=./anno_sta/annos_shape.png \
-    --png_shapeRate_path=./anno_sta/annos_shapeRate.png \
-    --png_pos_path=./anno_sta/annos_pos.png \
-    --png_posEnd_path=./anno_sta/annos_posEnd.png \
-    --png_cat_path=./anno_sta/annos_cat.png \
-    --png_objNum_path=./anno_sta/annos_objNum.png \
-    --get_relative=True
-"""
-
-import os
-import json
-import argparse
-
-import numpy as np
-import pandas as pd
-import seaborn as sns
-import matplotlib.pyplot as plt
-
-shp_rate_bins = [
-    0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5,
-    1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.4, 2.6, 3, 3.5, 4, 5
-]
-
-
-def check_dir(check_path, show=True):
-    if os.path.isdir(check_path):
-        check_directory = check_path
-    else:
-        check_directory = os.path.dirname(check_path)
-    if len(check_directory) > 0 and not os.path.exists(check_directory):
-        os.makedirs(check_directory)
-        if show:
-            print('make dir:', check_directory)
-
-
-def js_anno_sta(js_path, csv_path, png_shape_path, png_shapeRate_path,
-                png_pos_path, png_posEnd_path, png_cat_path, png_objNum_path,
-                get_relative, image_keyname, anno_keyname):
-    print('json read...\n')
-    with open(js_path, 'r') as load_f:
-        data = json.load(load_f)
-
-    df_img = pd.DataFrame(data[image_keyname])
-    sns.jointplot(y='height', x='width', data=df_img, kind='hex')
-    plt.close()
-    df_img = df_img.rename(columns={
-        "id": "image_id",
-        "height": "image_height",
-        "width": "image_width"
-    })
-
-    df_anno = pd.DataFrame(data[anno_keyname])
-    df_anno[['pox_x', 'pox_y', 'width', 'height']] = pd.DataFrame(df_anno[
-        'bbox'].values.tolist())
-    df_anno['width'] = df_anno['width'].astype(int)
-    df_anno['height'] = df_anno['height'].astype(int)
-
-    df_merge = pd.merge(df_img, df_anno, on="image_id")
-
-    if png_shape_path is not None:
-        check_dir(png_shape_path)
-        sns.jointplot(y='height', x='width', data=df_merge, kind='hex')
-        plt.savefig(png_shape_path)
-        plt.close()
-        print('png save to', png_shape_path)
-        if get_relative:
-            png_shapeR_path = png_shape_path.replace('.png', '_Relative.png')
-            df_merge['heightR'] = df_merge['height'] / df_merge['image_height']
-            df_merge['widthR'] = df_merge['width'] / df_merge['image_width']
-            sns.jointplot(y='heightR', x='widthR', data=df_merge, kind='hex')
-            plt.savefig(png_shapeR_path)
-            plt.close()
-            print('png save to', png_shapeR_path)
-    if png_shapeRate_path is not None:
-        check_dir(png_shapeRate_path)
-        plt.figure(figsize=(12, 8))
-        df_merge['shape_rate'] = (df_merge['width'] /
-                                  df_merge['height']).round(1)
-        df_merge['shape_rate'].value_counts(
-            sort=False, bins=shp_rate_bins).plot(
-                kind='bar', title='images shape rate')
-        plt.xticks(rotation=20)
-        plt.savefig(png_shapeRate_path)
-        plt.close()
-        print('png save to', png_shapeRate_path)
-
-    if png_pos_path is not None:
-        check_dir(png_pos_path)
-        sns.jointplot(y='pox_y', x='pox_x', data=df_merge, kind='hex')
-        plt.savefig(png_pos_path)
-        plt.close()
-        print('png save to', png_pos_path)
-        if get_relative:
-            png_posR_path = png_pos_path.replace('.png', '_Relative.png')
-            df_merge['pox_yR'] = df_merge['pox_y'] / df_merge['image_height']
-            df_merge['pox_xR'] = df_merge['pox_x'] / df_merge['image_width']
-            sns.jointplot(y='pox_yR', x='pox_xR', data=df_merge, kind='hex')
-            plt.savefig(png_posR_path)
-            plt.close()
-            print('png save to', png_posR_path)
-    if png_posEnd_path is not None:
-        check_dir(png_posEnd_path)
-        df_merge['pox_y_end'] = df_merge['pox_y'] + df_merge['height']
-        df_merge['pox_x_end'] = df_merge['pox_x'] + df_merge['width']
-        sns.jointplot(y='pox_y_end', x='pox_x_end', data=df_merge, kind='hex')
-        plt.savefig(png_posEnd_path)
-        plt.close()
-        print('png save to', png_posEnd_path)
-        if get_relative:
-            png_posEndR_path = png_posEnd_path.replace('.png', '_Relative.png')
-            df_merge['pox_y_endR'] = df_merge['pox_y_end'] / df_merge[
-                'image_height']
-            df_merge['pox_x_endR'] = df_merge['pox_x_end'] / df_merge[
-                'image_width']
-            sns.jointplot(
-                y='pox_y_endR', x='pox_x_endR', data=df_merge, kind='hex')
-            plt.savefig(png_posEndR_path)
-            plt.close()
-            print('png save to', png_posEndR_path)
-
-    if png_cat_path is not None:
-        check_dir(png_cat_path)
-        plt.figure(figsize=(12, 8))
-        df_merge['category_id'].value_counts().sort_index().plot(
-            kind='bar', title='obj category')
-        plt.savefig(png_cat_path)
-        plt.close()
-        print('png save to', png_cat_path)
-
-    if png_objNum_path is not None:
-        check_dir(png_objNum_path)
-        plt.figure(figsize=(12, 8))
-        df_merge['image_id'].value_counts().value_counts().sort_index().plot(
-            kind='bar', title='obj number per image')
-        # df_merge['image_id'].value_counts().value_counts(bins=np.linspace(1,31,16)).sort_index().plot(kind='bar', title='obj number per image')
-        plt.xticks(rotation=20)
-        plt.savefig(png_objNum_path)
-        plt.close()
-        print('png save to', png_objNum_path)
-
-    if csv_path is not None:
-        check_dir(csv_path)
-        df_merge.to_csv(csv_path)
-        print('csv save to', csv_path)
-
-
-def get_args():
-    parser = argparse.ArgumentParser(
-        description='Json Images Infomation Statistic')
-
-    # Parameters
-    parser.add_argument(
-        '--json_path',
-        type=str,
-        help='json path to statistic images information')
-    parser.add_argument(
-        '--csv_path',
-        type=str,
-        default=None,
-        help='csv path to save statistic images information, default None, do not save'
-    )
-
-    parser.add_argument(
-        '--png_shape_path',
-        type=str,
-        default=None,
-        help='png path to save statistic images shape information, default None, do not save'
-    )
-    parser.add_argument(
-        '--png_shapeRate_path',
-        type=str,
-        default=None,
-        help='png path to save statistic images shape rate information, default None, do not save'
-    )
-
-    parser.add_argument(
-        '--png_pos_path',
-        type=str,
-        default=None,
-        help='png path to save statistic pos information, default None, do not save'
-    )
-    parser.add_argument(
-        '--png_posEnd_path',
-        type=str,
-        default=None,
-        help='png path to save statistic end pos information, default None, do not save'
-    )
-
-    parser.add_argument(
-        '--png_cat_path',
-        type=str,
-        default=None,
-        help='png path to save statistic category information, default None, do not save'
-    )
-    parser.add_argument(
-        '--png_objNum_path',
-        type=str,
-        default=None,
-        help='png path to save statistic images object number information, default None, do not save'
-    )
-
-    parser.add_argument(
-        '--get_relative',
-        type=bool,
-        default=True,
-        help='if True, get relative result')
-    parser.add_argument(
-        '--image_keyname',
-        type=str,
-        default='images',
-        help='image key name in json, default images')
-    parser.add_argument(
-        '--anno_keyname',
-        type=str,
-        default='annotations',
-        help='annotation key name in json, default annotations')
-    parser.add_argument(
-        '--Args_show',
-        type=str,
-        default='True',
-        help='Args_show(default: True), if True, show args info')
-
-    args = parser.parse_args()
-
-    if args.Args_show.lower() == 'true':
-        print('Args'.center(100, '-'))
-        for k, v in vars(args).items():
-            print('%s = %s' % (k, v))
-        print()
-    return args
-
-
-if __name__ == '__main__':
-    args = get_args()
-    js_anno_sta(args.json_path, args.csv_path, args.png_shape_path,
-                args.png_shapeRate_path, args.png_pos_path,
-                args.png_posEnd_path, args.png_cat_path, args.png_objNum_path,
-                args.get_relative, args.image_keyname, args.anno_keyname)

+ 0 - 103
tools/coco_tools/json_Img2Json.py

@@ -1,103 +0,0 @@
-# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""
-@File Description:
-# 根据test影像文件夹生成test.json
-python ./coco_tools/json_Img2Json.py \
-    --test_image_path=./test2017 \
-    --json_train_path=./annotations/instances_val2017.json \
-    --json_test_path=./test.json
-"""
-
-import os, cv2
-import json
-import argparse
-
-from tqdm import tqdm
-
-
-def js_test(test_image_path, js_train_path, js_test_path, image_keyname,
-            cat_keyname):
-    print('Get Test'.center(100, '-'))
-    print()
-
-    print('json read...\n')
-    data = {}
-    with open(js_train_path, 'r') as load_f:
-        data_train = json.load(load_f)
-
-    file_list = os.listdir(test_image_path)
-    # sort method
-    # file_list.sort(key=lambda x: int(x.split('.')[0]))
-    # file_list.sort()
-    print('test image read...')
-    with tqdm(file_list) as pbar:
-        images = []
-        for index, img_name in enumerate(pbar):
-            img_path = os.path.join(test_image_path, img_name)
-            img = cv2.imread(img_path)
-            tmp = {}
-            tmp['id'] = index
-            tmp['width'] = img.shape[1]
-            tmp['height'] = img.shape[0]
-            tmp['file_name'] = img_name
-            images.append(tmp)
-    print('\n total test image:', len(file_list))
-    data[image_keyname] = images
-    data[cat_keyname] = data_train[cat_keyname]
-    with open(js_test_path, 'w') as f:
-        json.dump(data, f)
-
-
-def get_args():
-    parser = argparse.ArgumentParser(description='Get Test Json')
-
-    # Parameters
-    parser.add_argument('--test_image_path', type=str, help='test image path')
-    parser.add_argument(
-        '--json_train_path',
-        type=str,
-        help='train json path, provide categories information')
-    parser.add_argument(
-        '--json_test_path', type=str, help='test json path to save')
-    parser.add_argument(
-        '--image_keyname',
-        type=str,
-        default='images',
-        help='image key name in json, default images')
-    parser.add_argument(
-        '--cat_keyname',
-        type=str,
-        default='categories',
-        help='categories key name in json, default categories')
-    parser.add_argument(
-        '--Args_show',
-        type=str,
-        default='True',
-        help='Args_show(default: True), if True, show args info')
-
-    args = parser.parse_args()
-
-    if args.Args_show.lower() == 'true':
-        print('Args'.center(100, '-'))
-        for k, v in vars(args).items():
-            print('%s = %s' % (k, v))
-        print()
-    return args
-
-
-if __name__ == '__main__':
-    args = get_args()
-    js_test(args.test_image_path, args.json_train_path, args.json_test_path,
-            args.image_keyname, args.cat_keyname)

+ 0 - 124
tools/coco_tools/json_ImgSta.py

@@ -1,124 +0,0 @@
-# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""
-@File Description:
-# 统计json文件images信息,生成统计结果csv,同时生成图像shape、图像shape比例的二维分布图
-python ./coco_tools/json_ImgSta.py \
-    --json_path=./annotations/instances_val2017.json \
-    --csv_path=./img_sta/images.csv \
-    --png_shape_path=./img_sta/images_shape.png \
-    --png_shapeRate_path=./img_sta/images_shapeRate.png
-"""
-
-import json
-import argparse
-import os.path
-
-import pandas as pd
-import seaborn as sns
-import matplotlib.pyplot as plt
-
-
-def check_dir(check_path, show=True):
-    if os.path.isdir(check_path):
-        check_directory = check_path
-    else:
-        check_directory = os.path.dirname(check_path)
-    if len(check_directory) > 0 and not os.path.exists(check_directory):
-        os.makedirs(check_directory)
-        if show:
-            print('make dir:', check_directory)
-
-
-def js_img_sta(js_path, csv_path, png_shape_path, png_shapeRate_path,
-               image_keyname):
-    print('json read...\n')
-    with open(js_path, 'r') as load_f:
-        data = json.load(load_f)
-
-    df_img = pd.DataFrame(data[image_keyname])
-
-    if png_shape_path is not None:
-        check_dir(png_shape_path)
-        sns.jointplot(y='height', x='width', data=df_img, kind='hex')
-        plt.savefig(png_shape_path)
-        plt.close()
-        print('png save to', png_shape_path)
-    if png_shapeRate_path is not None:
-        check_dir(png_shapeRate_path)
-        df_img['shape_rate'] = (df_img['width'] / df_img['height']).round(1)
-        df_img['shape_rate'].value_counts().sort_index().plot(
-            kind='bar', title='images shape rate')
-        plt.savefig(png_shapeRate_path)
-        plt.close()
-        print('png save to', png_shapeRate_path)
-
-    if csv_path is not None:
-        check_dir(csv_path)
-        df_img.to_csv(csv_path)
-        print('csv save to', csv_path)
-
-
-def get_args():
-    parser = argparse.ArgumentParser(
-        description='Json Images Infomation Statistic')
-
-    # Parameters
-    parser.add_argument(
-        '--json_path',
-        type=str,
-        help='json path to statistic images information')
-    parser.add_argument(
-        '--csv_path',
-        type=str,
-        default=None,
-        help='csv path to save statistic images information, default None, do not save'
-    )
-    parser.add_argument(
-        '--png_shape_path',
-        type=str,
-        default=None,
-        help='png path to save statistic images shape information, default None, do not save'
-    )
-    parser.add_argument(
-        '--png_shapeRate_path',
-        type=str,
-        default=None,
-        help='png path to save statistic images shape rate information, default None, do not save'
-    )
-    parser.add_argument(
-        '--image_keyname',
-        type=str,
-        default='images',
-        help='image key name in json, default images')
-    parser.add_argument(
-        '--Args_show',
-        type=str,
-        default='True',
-        help='Args_show(default: True), if True, show args info')
-
-    args = parser.parse_args()
-
-    if args.Args_show.lower() == 'true':
-        print('Args'.center(100, '-'))
-        for k, v in vars(args).items():
-            print('%s = %s' % (k, v))
-        print()
-    return args
-
-
-if __name__ == '__main__':
-    args = get_args()
-    js_img_sta(args.json_path, args.csv_path, args.png_shape_path,
-               args.png_shapeRate_path, args.image_keyname)

+ 0 - 80
tools/coco_tools/json_InfoShow.py

@@ -1,80 +0,0 @@
-# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""
-@File Description:
-# 输出json文件基本信息
-python ./coco_tools/json_InfoShow.py \
-       --json_path=./annotations/instances_val2017.json \
-       --show_num 5
-"""
-
-import json
-import argparse
-
-
-def js_show(js_path, show_num):
-    print('Info'.center(100, '-'))
-    print('json read...')
-    with open(js_path, 'r') as load_f:
-        data = json.load(load_f)
-
-    print('json keys:', data.keys(), '\n')
-    for k, v in data.items():
-        print(k.center(50, '*'))
-        show_num_t = show_num if len(v) > show_num else len(v)
-        if isinstance(v, list):
-            print(' Content Type: list\n Total Length: %d\n First %d record:\n'
-                  % (len(v), show_num_t))
-
-            for i in range(show_num_t):
-                print(v[i])
-        elif isinstance(v, dict):
-            print(' Content Type: dict\n Total Length: %d\n First %d record:\n'
-                  % (len(v), show_num_t))
-            for i, (kv, vv) in enumerate(v.items()):
-                if i < show_num_t:
-                    print(kv, ':', vv)
-        print('...\n...\n')
-
-
-def get_args():
-    parser = argparse.ArgumentParser(description='Json Infomation Show')
-
-    # Parameters
-    parser.add_argument(
-        '--json_path', type=str, help='json path to show information')
-    parser.add_argument(
-        '--show_num',
-        type=int,
-        default=5,
-        help='show number of each sub record')
-    parser.add_argument(
-        '--Args_show',
-        type=str,
-        default='True',
-        help='Args_show(default: True), if True, show args info')
-
-    args = parser.parse_args()
-
-    if args.Args_show.lower() == 'true':
-        print('Args'.center(100, '-'))
-        for k, v in vars(args).items():
-            print('%s = %s' % (k, v))
-        print()
-    return args
-
-
-if __name__ == '__main__':
-    args = get_args()
-    js_show(args.json_path, args.show_num)

+ 0 - 87
tools/coco_tools/json_Merge.py

@@ -1,87 +0,0 @@
-# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""
-@File Description:
-# 合并json文件,可以通过merge_keys控制合并的字段, 默认合并'images', 'annotations'字段
-python ./coco_tools/json_Merge.py \
-    --json1_path=./annotations/instances_train2017.json \
-    --json2_path=./annotations/instances_val2017.json \
-    --save_path=./instances_trainval2017.json
-"""
-
-import json
-import argparse
-
-
-def js_merge(js1_path, js2_path, js_merge_path, merge_keys):
-    print('Merge'.center(100, '-'))
-    print()
-
-    print('json read...\n')
-    with open(js1_path, 'r') as load_f:
-        data1 = json.load(load_f)
-    with open(js2_path, 'r') as load_f:
-        data2 = json.load(load_f)
-
-    print('json merge...')
-    data = {}
-    for k, v in data1.items():
-        if k not in merge_keys:
-            data[k] = v
-            print(k)
-        else:
-            data[k] = data1[k] + data2[k]
-            print(k, 'merge!')
-    print()
-
-    print('json save...\n')
-    data_str = json.dumps(data, ensure_ascii=False)
-    with open(js_merge_path, 'w', encoding='utf-8') as save_f:
-        save_f.write(data_str)
-
-    print('finish!')
-
-
-def get_args():
-    parser = argparse.ArgumentParser(description='Json Merge')
-
-    # Parameters
-    parser.add_argument('--json1_path', type=str, help='json path1 to merge')
-    parser.add_argument('--json2_path', type=str, help='json path2 to merge')
-    parser.add_argument(
-        '--save_path', type=str, help='json path to save the merge result')
-    parser.add_argument(
-        '--merge_keys',
-        type=list,
-        default=['images', 'annotations'],
-        help='json keys that need to merge')
-    parser.add_argument(
-        '--Args_show',
-        type=str,
-        default='True',
-        help='Args_show(default: True), if True, show args info')
-
-    args = parser.parse_args()
-
-    if args.Args_show.lower() == 'true':
-        print('Args'.center(100, '-'))
-        for k, v in vars(args).items():
-            print('%s = %s' % (k, v))
-        print()
-    return args
-
-
-if __name__ == '__main__':
-    args = get_args()
-    js_merge(args.json1_path, args.json2_path, args.save_path, args.merge_keys)

+ 0 - 150
tools/coco_tools/json_Split.py

@@ -1,150 +0,0 @@
-# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""
-@File Description:
-# json数据集划分,可以通过val_split_rate、val_split_num控制划分比例或个数, keep_val_inTrain可以设定是否在train中保留val相关信息
-python ./coco_tools/json_Split.py \
-    --json_all_path=./annotations/instances_val2017.json \
-    --json_train_path=./instances_val2017_train.json \
-    --json_val_path=./instances_val2017_val.json
-"""
-
-import json
-import argparse
-
-import pandas as pd
-
-
-def get_annno(df_img_split, df_anno):
-    df_merge = pd.merge(
-        df_img_split, df_anno, on="image_id", suffixes=(None, '_r'))
-    df_merge = df_merge[[c for c in df_merge.columns if not c.endswith('_r')]]
-    df_anno_split = df_merge[df_anno.columns.to_list()]
-    df_anno_split = df_anno_split.sort_values(by='id')
-    return df_anno_split
-
-
-def js_split(js_all_path, js_train_path, js_val_path, val_split_rate,
-             val_split_num, keep_val_inTrain, image_keyname, anno_keyname):
-    print('Split'.center(100, '-'))
-    print()
-
-    print('json read...\n')
-
-    with open(js_all_path, 'r') as load_f:
-        data = json.load(load_f)
-    df_anno = pd.DataFrame(data[anno_keyname])
-    df_img = pd.DataFrame(data[image_keyname])
-    df_img = df_img.rename(columns={"id": "image_id"})
-    df_img = df_img.sample(frac=1, random_state=0)
-
-    if val_split_num is None:
-        val_split_num = int(val_split_rate * len(df_img))
-
-    if keep_val_inTrain:
-        df_img_train = df_img
-        df_img_val = df_img[:val_split_num]
-        df_anno_train = df_anno
-        df_anno_val = get_annno(df_img_val, df_anno)
-    else:
-        df_img_train = df_img[val_split_num:]
-        df_img_val = df_img[:val_split_num]
-        df_anno_train = get_annno(df_img_train, df_anno)
-        df_anno_val = get_annno(df_img_val, df_anno)
-    df_img_train = df_img_train.rename(columns={"image_id": "id"}).sort_values(
-        by='id')
-    df_img_val = df_img_val.rename(columns={"image_id": "id"}).sort_values(
-        by='id')
-
-    data[image_keyname] = json.loads(df_img_train.to_json(orient='records'))
-    data[anno_keyname] = json.loads(df_anno_train.to_json(orient='records'))
-    str_json = json.dumps(data, ensure_ascii=False)
-    with open(js_train_path, 'w', encoding='utf-8') as file_obj:
-        file_obj.write(str_json)
-
-    data[image_keyname] = json.loads(df_img_val.to_json(orient='records'))
-    data[anno_keyname] = json.loads(df_anno_val.to_json(orient='records'))
-    str_json = json.dumps(data, ensure_ascii=False)
-    with open(js_val_path, 'w', encoding='utf-8') as file_obj:
-        file_obj.write(str_json)
-
-    print('image total %d, train %d, val %d' %
-          (len(df_img), len(df_img_train), len(df_img_val)))
-    print('anno total %d, train %d, val %d' %
-          (len(df_anno), len(df_anno_train), len(df_anno_val)))
-    return df_img
-
-
-def get_args():
-    parser = argparse.ArgumentParser(description='Json Merge')
-
-    # Parameters
-    parser.add_argument('--json_all_path', type=str, help='json path to split')
-    parser.add_argument(
-        '--json_train_path',
-        type=str,
-        help='json path to save the split result -- train part')
-    parser.add_argument(
-        '--json_val_path',
-        type=str,
-        help='json path to save the split result -- val part')
-    parser.add_argument(
-        '--val_split_rate',
-        type=float,
-        default=0.1,
-        help='val image number rate in total image, default is 0.1; if val_split_num is set, val_split_rate will not work'
-    )
-    parser.add_argument(
-        '--val_split_num',
-        type=int,
-        default=None,
-        help='val image number in total image, default is None; if val_split_num is set, val_split_rate will not work'
-    )
-    parser.add_argument(
-        '--keep_val_inTrain',
-        type=bool,
-        default=False,
-        help='if true, val part will be in train as well; which means that the content of json_train_path is the same as the content of json_all_path'
-    )
-    parser.add_argument(
-        '--image_keyname',
-        type=str,
-        default='images',
-        help='image key name in json, default images')
-    parser.add_argument(
-        '--anno_keyname',
-        type=str,
-        default='annotations',
-        help='annotation key name in json, default annotations')
-    parser.add_argument(
-        '--Args_show',
-        type=str,
-        default='True',
-        help='Args_show(default: True), if True, show args info')
-
-    args = parser.parse_args()
-
-    if args.Args_show.lower() == 'true':
-        print('Args'.center(100, '-'))
-        for k, v in vars(args).items():
-            print('%s = %s' % (k, v))
-        print()
-    return args
-
-
-if __name__ == '__main__':
-    args = get_args()
-    js_split(args.json_all_path, args.json_train_path, args.json_val_path,
-             args.val_split_rate, args.val_split_num, args.keep_val_inTrain,
-             args.image_keyname, args.anno_keyname)

+ 171 - 0
tools/coco_tools/json_anno_sta.py

@@ -0,0 +1,171 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import json
+import argparse
+
+import pandas as pd
+import seaborn as sns
+import matplotlib.pyplot as plt
+
+SHP_RATE_BINS = [
+    0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5,
+    1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.4, 2.6, 3, 3.5, 4, 5
+]
+
+
+def _check_dir(check_path, show=True):
+    if os.path.isdir(check_path):
+        check_directory = check_path
+    else:
+        check_directory = os.path.dirname(check_path)
+    if len(check_directory) > 0 and not os.path.exists(check_directory):
+        os.makedirs(check_directory)
+        if show:
+            print("make dir:", check_directory)
+
+
+def json_anno_sta(json_path, csv_path, obj_shape_path, obj_shape_rate_path,
+                  obj_pos_path, obj_pos_end_path, obj_cat_path, obj_num_path,
+                  get_relative, img_keyname, anno_keyname):
+    print("json read...\n")
+    with open(json_path, "r") as load_f:
+        data = json.load(load_f)
+    df_image = pd.DataFrame(data[img_keyname])
+    sns.jointplot(y="height", x="width", data=df_image, kind="hex")
+    plt.close()
+    df_image = df_image.rename(columns={
+        "id": "image_id",
+        "height": "image_height",
+        "width": "image_width"
+    })
+    df_anno = pd.DataFrame(data[anno_keyname])
+    df_anno[["pox_x", "pox_y", "width", "height"]] = pd.DataFrame(df_anno[
+        "bbox"].values.tolist())
+    df_anno["width"] = df_anno["width"].astype(int)
+    df_anno["height"] = df_anno["height"].astype(int)
+    df_merge = pd.merge(df_image, df_anno, on="image_id")
+    if obj_shape_path is not None:
+        _check_dir(obj_shape_path)
+        sns.jointplot(y="height", x="width", data=df_merge, kind="hex")
+        plt.savefig(obj_shape_path)
+        plt.close()
+        print("png save to", obj_shape_path)
+        if get_relative:
+            png_shapeR_path = obj_shape_path.replace(".png", "_relative.png")
+            df_merge["heightR"] = df_merge["height"] / df_merge["image_height"]
+            df_merge["widthR"] = df_merge["width"] / df_merge["image_width"]
+            sns.jointplot(y="heightR", x="widthR", data=df_merge, kind="hex")
+            plt.savefig(png_shapeR_path)
+            plt.close()
+            print("png save to", png_shapeR_path)
+    if obj_shape_rate_path is not None:
+        _check_dir(obj_shape_rate_path)
+        plt.figure(figsize=(12, 8))
+        df_merge["shape_rate"] = (df_merge["width"] /
+                                  df_merge["height"]).round(1)
+        df_merge["shape_rate"].value_counts(
+            sort=False, bins=SHP_RATE_BINS).plot(
+                kind="bar", title="images shape rate")
+        plt.xticks(rotation=20)
+        plt.savefig(obj_shape_rate_path)
+        plt.close()
+        print("png save to", obj_shape_rate_path)
+    if obj_pos_path is not None:
+        _check_dir(obj_pos_path)
+        sns.jointplot(y="pox_y", x="pox_x", data=df_merge, kind="hex")
+        plt.savefig(obj_pos_path)
+        plt.close()
+        print("png save to", obj_pos_path)
+        if get_relative:
+            png_posR_path = obj_pos_path.replace(".png", "_relative.png")
+            df_merge["pox_yR"] = df_merge["pox_y"] / df_merge["image_height"]
+            df_merge["pox_xR"] = df_merge["pox_x"] / df_merge["image_width"]
+            sns.jointplot(y="pox_yR", x="pox_xR", data=df_merge, kind="hex")
+            plt.savefig(png_posR_path)
+            plt.close()
+            print("png save to", png_posR_path)
+    if obj_pos_end_path is not None:
+        _check_dir(obj_pos_end_path)
+        df_merge["pox_y_end"] = df_merge["pox_y"] + df_merge["height"]
+        df_merge["pox_x_end"] = df_merge["pox_x"] + df_merge["width"]
+        sns.jointplot(y="pox_y_end", x="pox_x_end", data=df_merge, kind="hex")
+        plt.savefig(obj_pos_end_path)
+        plt.close()
+        print("png save to", obj_pos_end_path)
+        if get_relative:
+            png_posEndR_path = obj_pos_end_path.replace(".png", "_relative.png")
+            df_merge["pox_y_endR"] = df_merge["pox_y_end"] / df_merge[
+                "image_height"]
+            df_merge["pox_x_endR"] = df_merge["pox_x_end"] / df_merge[
+                "image_width"]
+            sns.jointplot(
+                y="pox_y_endR", x="pox_x_endR", data=df_merge, kind="hex")
+            plt.savefig(png_posEndR_path)
+            plt.close()
+            print("png save to", png_posEndR_path)
+    if obj_cat_path is not None:
+        _check_dir(obj_cat_path)
+        plt.figure(figsize=(12, 8))
+        df_merge["category_id"].value_counts().sort_index().plot(
+            kind="bar", title="obj category")
+        plt.savefig(obj_cat_path)
+        plt.close()
+        print("png save to", obj_cat_path)
+    if obj_num_path is not None:
+        _check_dir(obj_num_path)
+        plt.figure(figsize=(12, 8))
+        df_merge["image_id"].value_counts().value_counts().sort_index().plot(
+            kind="bar", title="obj number per image")
+        plt.xticks(rotation=20)
+        plt.savefig(obj_num_path)
+        plt.close()
+        print("png save to", obj_num_path)
+    if csv_path is not None:
+        _check_dir(csv_path)
+        df_merge.to_csv(csv_path)
+        print("csv save to", csv_path)
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(
+        description="Get annotation infomation statistics")
+    parser.add_argument("--json_path", type=str, required=True, \
+                        help="Path of the JSON file whose statistics you want to collect.")
+    parser.add_argument("--csv_path", type=str, default=None, \
+                        help="Path to save the statistics table.")
+    parser.add_argument("--obj_shape_path", type=str, default=None, \
+                        help="Output image saving path. The image visualizes the two-dimensional distribution of the shape of all object detection boxes.")
+    parser.add_argument("--obj_shape_rate_path", type=str, default=None, \
+                        help="Output image saving path. The image visualizes the one-dimensional distribution of shape ratio (width/height) of all target bounding boxes.")
+    parser.add_argument("--obj_pos_path", type=str, default=None, \
+                        help="Output image saving path. The image visualizes the two-dimensional distribution of the coordinates at the upper left corner of all bounding boxes.")
+    parser.add_argument("--obj_pos_end_path", type=str, default=None, \
+                        help="Output image saving path. The image visualizes the two-dimensional distribution of the coordinates at the lower right corner of all bounding boxes.")
+    parser.add_argument("--obj_cat_path", type=str, default=None, \
+                        help="Output image saving path. The image visualizes the quantity distribution of objects in each category.")
+    parser.add_argument("--obj_num_path", type=str, default=None, \
+                        help="Output image saving path. The image visualizes the quantity distribution of annotated objects in a single image.")
+    parser.add_argument("--get_relative", action="store_true", \
+                        help="Whether to generate the shape of the image target detection frame and the relative ratio of the coordinates of the upper left corner and lower right corner of the object detection frame (horizontal axis coordinates/image length, vertical axis coordinates/image width).")
+    parser.add_argument("--img_keyname", type=str, default="images", \
+                        help="Image key in the JSON file.")
+    parser.add_argument("--anno_keyname", type=str, default="annotations", \
+                        help="Annotation key in the JSON file.")
+    args = parser.parse_args()
+    json_anno_sta(args.json_path, args.csv_path, args.obj_shape_path,
+                  args.obj_shape_rate_path, args.obj_pos_path,
+                  args.obj_pos_end_path, args.obj_cat_path, args.obj_num_path,
+                  args.get_relative, args.img_keyname, args.anno_keyname)

+ 65 - 0
tools/coco_tools/json_image2json.py

@@ -0,0 +1,65 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import json
+import argparse
+
+import cv2
+from tqdm import tqdm
+
+
+def json_image2json(image_dir, json_train_path, json_test_path, img_keyname,
+                    cat_keyname):
+    print("Image to Json".center(100, "-"))
+    print("json read...\n")
+    data = {}
+    with open(json_train_path, "r") as load_f:
+        data_train = json.load(load_f)
+    file_list = os.listdir(image_dir)
+    print("test image read...")
+    with tqdm(file_list) as pbar:
+        images = []
+        for index, image_name in enumerate(pbar):
+            image_path = os.path.join(image_dir, image_name)
+            image = cv2.imread(image_path)
+            tmp = {}
+            tmp["id"] = index
+            tmp["width"] = image.shape[1]
+            tmp["height"] = image.shape[0]
+            tmp["file_name"] = image_name
+            images.append(tmp)
+    print("\n total test image:", len(file_list))
+    data[img_keyname] = images
+    data[cat_keyname] = data_train[cat_keyname]
+    with open(json_test_path, "w") as f:
+        json.dump(data, f)
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(
+        description="Generate JSON file from image directory")
+    parser.add_argument("--image_dir", type=str, required=True, \
+                        help="Directory that contains the test set images.")
+    parser.add_argument("--json_train_path", type=str, required=True, \
+                        help="JSON file path of the training set. Used as reference.")
+    parser.add_argument("--result_path", type=str, required=True, \
+                        help="Path to the generated test set JSON file.")
+    parser.add_argument("--img_keyname", type=str, default="images", \
+                        help="Image key in the JSON file.")
+    parser.add_argument("--cat_keyname", type=str, default="categories", \
+                        help="Category key in the JSON file.")
+    args = parser.parse_args()
+    json_image2json(args.image_dir, args.json_train_path, args.result_path,
+                    args.img_keyname, args.cat_keyname)

+ 77 - 0
tools/coco_tools/json_image_sta.py

@@ -0,0 +1,77 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json
+import argparse
+import os.path
+
+import pandas as pd
+import seaborn as sns
+import matplotlib.pyplot as plt
+
+
+def _check_dir(check_path, show=False):
+    if os.path.isdir(check_path):
+        check_directory = check_path
+    else:
+        check_directory = os.path.dirname(check_path)
+    if len(check_directory) > 0 and not os.path.exists(check_directory):
+        os.makedirs(check_directory)
+        if show:
+            print("make dir:", check_directory)
+
+
+def json_image_sta(json_path, csv_path, img_shape_path, img_shape_rate_path,
+                   img_keyname):
+    print("json read...\n")
+    with open(json_path, "r") as load_f:
+        data = json.load(load_f)
+    df_image = pd.DataFrame(data[img_keyname])
+    if img_shape_path is not None:
+        _check_dir(img_shape_path)
+        sns.jointplot(y="height", x="width", data=df_image, kind="hex")
+        plt.savefig(img_shape_path)
+        plt.close()
+        print("png save to", img_shape_path)
+    if img_shape_rate_path is not None:
+        _check_dir(img_shape_rate_path)
+        df_image["shape_rate"] = (df_image["width"] /
+                                  df_image["height"]).round(1)
+        df_image["shape_rate"].value_counts().sort_index().plot(
+            kind="bar", title="images shape rate")
+        plt.savefig(img_shape_rate_path)
+        plt.close()
+        print("png save to", img_shape_rate_path)
+    if csv_path is not None:
+        _check_dir(csv_path)
+        df_image.to_csv(csv_path)
+        print("csv save to", csv_path)
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(
+        description="Get image infomation statistics")
+    parser.add_argument("--json_path", type=str, \
+                        help="Path of the JSON file whose statistics are to be collected.")
+    parser.add_argument("--csv_path", type=str, default=None, \
+                        help="Path for the statistics table.")
+    parser.add_argument("--img_shape_path", type=str, default=None, \
+                        help="Output image saving path. The image visualizes the two-dimensional distribution of all image shapes.")
+    parser.add_argument("--img_shape_rate_path", type=str, default=None, \
+                        help="Output image saving path. The image visualizes the one-dimensional distribution of shape ratio (width/height) of all images.")
+    parser.add_argument("--img_keyname", type=str, default="images", \
+                        help="Image key in the JSON file.")
+    args = parser.parse_args()
+    json_image_sta(args.json_path, args.csv_path, args.img_shape_path,
+                   args.img_shape_rate_path, args.img_keyname)

+ 52 - 0
tools/coco_tools/json_info_show.py

@@ -0,0 +1,52 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json
+import argparse
+
+
+def json_info_show(json_path, show_num):
+    print("Info".center(100, "-"))
+    print("json read...")
+    with open(json_path, "r") as load_f:
+        data = json.load(load_f)
+    print("json keys:", data.keys(), "\n")
+    for k, v in data.items():
+        print(k.center(50, "*"))
+        show_num_used = show_num if len(v) > show_num else len(v)
+        if isinstance(v, list):
+            print(" Content Type: list\n Total Length: %d\n First %d record:\n"
+                  % (len(v), show_num_used))
+            for i in range(show_num_used):
+                print(v[i])
+        elif isinstance(v, dict):
+            print(" Content Type: dict\n Total Length: %d\n First %d record:\n"
+                  % (len(v), show_num_used))
+            for i, (kv, vv) in enumerate(v.items()):
+                if i < show_num_used:
+                    print(kv, ":", vv)
+        else:
+            print(v)
+        print("...\n...\n")
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(
+        description="Show information in JSON file")
+    parser.add_argument("--json_path", type=str, required=True, \
+                        help="Path of the JSON file whose statistics are to be collected.")
+    parser.add_argument("--show_num", type=int, default=5, \
+                        help="Number of elements to show in the output.")
+    args = parser.parse_args()
+    json_info_show(args.json_path, args.show_num)

+ 54 - 0
tools/coco_tools/json_merge.py

@@ -0,0 +1,54 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json
+import argparse
+
+
+def json_merge(json1_path, json2_path, save_path, merge_keys):
+    print("Merge".center(100, "-"))
+    print("json read...\n")
+    with open(json1_path, "r") as load_f:
+        data1 = json.load(load_f)
+    with open(json2_path, "r") as load_f:
+        data2 = json.load(load_f)
+    print("json merge...")
+    data = {}
+    for k, v in data1.items():
+        if k not in merge_keys:
+            data[k] = v
+            print(k)
+        else:
+            data[k] = data1[k] + data2[k]
+            print(k, "merge!")
+    print()
+    print("json save...\n")
+    data_str = json.dumps(data, ensure_ascii=False)
+    with open(save_path, "w", encoding="utf-8") as save_f:
+        save_f.write(data_str)
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Merge JSON files")
+    parser.add_argument("--json1_path", type=str, required=True, \
+                        help="Path of the first JSON file to merge.")
+    parser.add_argument("--json2_path", type=str, required=True, \
+                        help="Path of the second JSON file to merge.")
+    parser.add_argument("--save_path", type=str, required=True, \
+                        help="Path to save the merged JSON file.")
+    parser.add_argument("--merge_keys", type=list, default=["images", "annotations"], \
+                        help="Keys to be merged.")
+    args = parser.parse_args()
+    json_merge(args.json1_path, args.json2_path, args.save_path,
+               args.merge_keys)

+ 94 - 0
tools/coco_tools/json_split.py

@@ -0,0 +1,94 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json
+import argparse
+
+import pandas as pd
+
+
+def _get_annno(df_image_split, df_anno):
+    df_merge = pd.merge(
+        df_image_split, df_anno, on="image_id", suffixes=(None, "_r"))
+    df_merge = df_merge[[c for c in df_merge.columns if not c.endswith("_r")]]
+    df_anno_split = df_merge[df_anno.columns.to_list()]
+    df_anno_split = df_anno_split.sort_values(by="id")
+    return df_anno_split
+
+
+def json_split(json_all_path, json_train_path, json_val_path, val_split_rate,
+               val_split_num, keep_val_in_train, img_keyname, anno_keyname):
+    print("Split".center(100, "-"))
+    print("json read...\n")
+    with open(json_all_path, "r") as load_f:
+        data = json.load(load_f)
+    df_anno = pd.DataFrame(data[anno_keyname])
+    df_image = pd.DataFrame(data[img_keyname])
+    df_image = df_image.rename(columns={"id": "image_id"})
+    df_image = df_image.sample(frac=1, random_state=0)
+    if val_split_num is None:
+        val_split_num = int(val_split_rate * len(df_image))
+    if keep_val_in_train:
+        df_image_train = df_image
+        df_image_val = df_image[:val_split_num]
+        df_anno_train = df_anno
+        df_anno_val = _get_annno(df_image_val, df_anno)
+    else:
+        df_image_train = df_image[val_split_num:]
+        df_image_val = df_image[:val_split_num]
+        df_anno_train = _get_annno(df_image_train, df_anno)
+        df_anno_val = _get_annno(df_image_val, df_anno)
+    df_image_train = df_image_train.rename(
+        columns={"image_id": "id"}).sort_values(by="id")
+    df_image_val = df_image_val.rename(columns={"image_id": "id"}).sort_values(
+        by="id")
+    data[img_keyname] = json.loads(df_image_train.to_json(orient="records"))
+    data[anno_keyname] = json.loads(df_anno_train.to_json(orient="records"))
+    str_json = json.dumps(data, ensure_ascii=False)
+    with open(json_train_path, "w", encoding="utf-8") as file_obj:
+        file_obj.write(str_json)
+    data[img_keyname] = json.loads(df_image_val.to_json(orient="records"))
+    data[anno_keyname] = json.loads(df_anno_val.to_json(orient="records"))
+    str_json = json.dumps(data, ensure_ascii=False)
+    with open(json_val_path, "w", encoding="utf-8") as file_obj:
+        file_obj.write(str_json)
+    print("image total %d, train %d, val %d" %
+          (len(df_image), len(df_image_train), len(df_image_val)))
+    print("anno total %d, train %d, val %d" %
+          (len(df_anno), len(df_anno_train), len(df_anno_val)))
+    return df_image
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Split JSON file")
+    parser.add_argument("--json_all_path", type=str,  required=True, \
+                        help="Path to the original JSON file.")
+    parser.add_argument("--json_train_path", type=str, required=True, \
+                        help="Generated JSON file for the train set.")
+    parser.add_argument( "--json_val_path", type=str, required=True, \
+                        help="Generated JSON file for the val set.")
+    parser.add_argument("--val_split_rate", type=float, default=0.1, \
+                        help="Proportion of files in the val set.")
+    parser.add_argument("--val_split_num", type=int, default=None, \
+                        help="Number of val set files. If this parameter is set,`--val_split_rate` will be invalidated.")
+    parser.add_argument("--keep_val_in_train", action="store_true", \
+                        help="Whether to keep the val set samples in the train set.")
+    parser.add_argument("--img_keyname", type=str, default="images", \
+                        help="Image key in the JSON file.")
+    parser.add_argument("--anno_keyname", type=str, default="annotations", \
+                        help="Category key in the JSON file.")
+    args = parser.parse_args()
+    json_split(args.json_all_path, args.json_train_path, args.json_val_path,
+               args.val_split_rate, args.val_split_num, args.keep_val_in_train,
+               args.img_keyname, args.anno_keyname)

+ 6 - 6
tools/extract_ms_patches.py

@@ -216,7 +216,7 @@ def merge_bins(bins1, bins2):
 
 
 @time_it
-def extract_ms_patches(im_paths,
+def extract_ms_patches(image_paths,
                        mask_path,
                        save_dir,
                        min_patch_size=256,
@@ -251,7 +251,7 @@ def extract_ms_patches(im_paths,
     quad_tree.build_tree(mask_ds, bg_class)
     if visualize:
         print("Start drawing rectangles...")
-        save_path = quad_tree.visualize_regions(im_paths[0])
+        save_path = quad_tree.visualize_regions(image_paths[0])
         print(f"The visualization result is saved in {save_path} .")
     print("Quad tree has been built. Now start collecting nodes...")
     nodes = quad_tree.get_nodes(
@@ -266,21 +266,21 @@ def extract_ms_patches(im_paths,
             continue
         is_valid = True
         if nonzero_ratio is not None:
-            for src_path in im_paths:
+            for src_path in image_paths:
                 im_ds = gdal.Open(src_path)
                 arr = im_ds.ReadAsArray(j, i, real_w, real_h)
                 if np.count_nonzero(arr) / arr.size < nonzero_ratio:
                     is_valid = False
                     break
         if is_valid:
-            for src_path in im_paths:
+            for src_path in image_paths:
                 _save_patch(src_path, i, j, real_h, real_w)
             _save_patch(mask_path, i, j, real_h, real_w, 'mask')
 
 
 if __name__ == '__main__':
     parser = argparse.ArgumentParser()
-    parser.add_argument("--im_paths", type=str, required=True, nargs='+', \
+    parser.add_argument("--image_paths", type=str, required=True, nargs='+', \
                         help="Path of images. Different images must have unique file names.")
     parser.add_argument("--mask_path", type=str, required=True, \
                         help="Path of mask.")
@@ -302,7 +302,7 @@ if __name__ == '__main__':
                         help="Visualize the quadtree.")
     args = parser.parse_args()
 
-    extract_ms_patches(args.im_paths, args.mask_path, args.save_dir,
+    extract_ms_patches(args.image_paths, args.mask_path, args.save_dir,
                        args.min_patch_size, args.bg_class, args.target_class,
                        args.max_level, args.include_bg, args.nonzero_ratio,
                        args.visualize)

+ 4 - 4
tools/geojson2mask.py

@@ -34,8 +34,8 @@ def _gt_convert(x_geo, y_geo, geotf):
 
 @time_it
 # TODO: update for vector2raster
-def convert_data(image_path, geojson_path, save_path):
-    raster = Raster(image_path)
+def convert_data(src_img_path, geojson_path, save_path):
+    raster = Raster(src_img_path)
     tmp_img = np.zeros((raster.height, raster.width), dtype=np.int32)
     # vector to EPSG from raster
     temp_geojson_path = translate_vector(geojson_path, raster.proj)
@@ -63,11 +63,11 @@ def convert_data(image_path, geojson_path, save_path):
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
-    parser.add_argument("--srcimg_path", type=str, required=True, \
+    parser.add_argument("--src_img_path", type=str, required=True, \
                         help="Path of the original image.")
     parser.add_argument("--geojson_path", type=str, required=True, \
                         help="Path of the GeoJSON file (the coordinate system is WGS84).")
     parser.add_argument("--save_path", type=str, required=True, \
                         help="Path to store the mask data.")
     args = parser.parse_args()
-    convert_data(args.srcimg_path, args.geojson_path, args.save_path)
+    convert_data(args.src_img_path, args.geojson_path, args.save_path)

+ 7 - 6
tools/mask2shape.py

@@ -73,15 +73,16 @@ def _polygonize_raster(mask_path, vec_save_path, proj, geot, ignore_index, ext):
 
 
 @time_it
-def mask2shape(srcimg_path, mask_path, save_path, ignore_index=255):
+def mask2shape(src_img_path, mask_path, save_path, ignore_index=255):
     vec_ext = save_path.split(".")[-1].lower()
     if vec_ext not in ["json", "geojson", "shp"]:
         raise ValueError(
             "The extension of `save_path` must be 'json/geojson' or 'shp', not {}.".
             format(vec_ext))
-    ras_ext = srcimg_path.split(".")[-1].lower()
-    if osp.exists(srcimg_path) and ras_ext in ["tif", "tiff", "geotiff", "img"]:
-        src = Raster(srcimg_path)
+    ras_ext = src_img_path.split(".")[-1].lower()
+    if osp.exists(
+            src_img_path) and ras_ext in ["tif", "tiff", "geotiff", "img"]:
+        src = Raster(src_img_path)
         _polygonize_raster(mask_path, save_path, src.proj, src.geot,
                            ignore_index, vec_ext)
         src = None
@@ -96,10 +97,10 @@ if __name__ == "__main__":
                         help="Path of mask data.")
     parser.add_argument("--save_path", type=str, required=True, \
                         help="Path to save the shape file (the extension is .json/geojson or .shp).")
-    parser.add_argument("--srcimg_path", type=str, default="", \
+    parser.add_argument("--src_img_path", type=str, default="", \
                         help="Path of original data with geoinfo. Default to empty.")
     parser.add_argument("--ignore_index", type=int, default=255, \
                         help="The ignored index will not be converted to a value in the shape file. Default value is 255.")
     args = parser.parse_args()
-    mask2shape(args.srcimg_path, args.mask_path, args.save_path,
+    mask2shape(args.src_img_path, args.mask_path, args.save_path,
                args.ignore_index)

+ 19 - 19
tools/match.py

@@ -26,10 +26,10 @@ class MatchError(Exception):
         return "Cannot match the two images."
 
 
-def _calcu_tf(im1, im2):
+def _calcu_tf(image1, image2):
     orb = cv2.AKAZE_create()
-    kp1, des1 = orb.detectAndCompute(im1, None)
-    kp2, des2 = orb.detectAndCompute(im2, None)
+    kp1, des1 = orb.detectAndCompute(image1, None)
+    kp2, des2 = orb.detectAndCompute(image2, None)
     bf = cv2.BFMatcher()
     mathces = bf.knnMatch(des2, des1, k=2)
     good_matches = []
@@ -63,15 +63,15 @@ def _get_match_img(raster, bands):
 
 
 @time_it
-def match(im1_path,
-          im2_path,
+def match(image1_path,
+          image2_path,
           save_path,
-          im1_bands=[1, 2, 3],
-          im2_bands=[1, 2, 3]):
-    im1_ras = Raster(im1_path)
-    im2_ras = Raster(im2_path)
-    im1 = _get_match_img(im1_ras._src_data, im1_bands)
-    im2 = _get_match_img(im2_ras._src_data, im2_bands)
+          image1_bands=[1, 2, 3],
+          image2_bands=[1, 2, 3]):
+    im1_ras = Raster(image1_path)
+    im2_ras = Raster(image2_path)
+    im1 = _get_match_img(im1_ras._src_data, image1_bands)
+    im2 = _get_match_img(im2_ras._src_data, image2_bands)
     H = _calcu_tf(im1, im2)
     im2_arr_t = cv2.warpPerspective(im2_ras.getArray(), H,
                                     (im1_ras.width, im1_ras.height))
@@ -81,16 +81,16 @@ def match(im1_path,
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser(description="input parameters")
-    parser.add_argument('--im1_path', type=str, required=True, \
+    parser.add_argument('--image1_path', type=str, required=True, \
                         help="Path of time1 image (with geoinfo).")
-    parser.add_argument('--im2_path', type=str, required=True, \
+    parser.add_argument('--image2_path', type=str, required=True, \
                         help="Path of time2 image.")
     parser.add_argument('--save_path', type=str, required=True, \
                         help="Path to save matching result.")
-    parser.add_argument('--im1_bands', type=int, nargs="+", default=[1, 2, 3], \
-                        help="Bands of im1 to be used for matching, RGB or monochrome. The default value is [1, 2, 3].")
-    parser.add_argument('--im2_bands', type=int, nargs="+", default=[1, 2, 3], \
-                        help="Bands of im2 to be used for matching, RGB or monochrome. The default value is [1, 2, 3].")
+    parser.add_argument('--image1_bands', type=int, nargs="+", default=[1, 2, 3], \
+                        help="Bands of image1 to be used for matching, RGB or monochrome. The default value is [1, 2, 3].")
+    parser.add_argument('--image2_bands', type=int, nargs="+", default=[1, 2, 3], \
+                        help="Bands of image2 to be used for matching, RGB or monochrome. The default value is [1, 2, 3].")
     args = parser.parse_args()
-    match(args.im1_path, args.im2_path, args.save_path, args.im1_bands,
-          args.im2_bands)
+    match(args.image1_path, args.image2_path, args.save_path, args.image1_bands,
+          args.image2_bands)

+ 4 - 4
tools/oif.py

@@ -35,8 +35,8 @@ def _calcOIF(rgb, stds, rho):
 
 
 @time_it
-def oif(img_path, topk=5):
-    raster = Raster(img_path)
+def oif(image_path, topk=5):
+    raster = Raster(image_path)
     img = raster.getArray()
     img_flatten = img.reshape([-1, raster.bands])
     stds = np.std(img_flatten, axis=0)
@@ -58,9 +58,9 @@ def oif(img_path, topk=5):
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
-    parser.add_argument("--im_path", type=str, required=True, \
+    parser.add_argument("--image_path", type=str, required=True, \
                         help="Path of HSIs image.")
     parser.add_argument("--topk", type=int, default=5, \
                         help="Number of top results. The default value is 5.")
     args = parser.parse_args()
-    oif(args.im_path, args.topk)
+    oif(args.image_path, args.topk)

+ 5 - 5
tools/pca.py

@@ -25,15 +25,15 @@ from utils import Raster, save_geotiff, time_it
 
 
 @time_it
-def pca_train(img_path, save_dir="output", dim=3):
-    raster = Raster(img_path)
+def pca_train(image_path, save_dir="output", dim=3):
+    raster = Raster(image_path)
     im = raster.getArray()
     n_im = np.reshape(im, (-1, raster.bands))
     pca = PCA(n_components=dim, whiten=True)
     pca_model = pca.fit(n_im)
     if not osp.exists(save_dir):
         os.makedirs(save_dir)
-    name = osp.splitext(osp.normpath(img_path).split(os.sep)[-1])[0]
+    name = osp.splitext(osp.normpath(image_path).split(os.sep)[-1])[0]
     model_save_path = osp.join(save_dir, (name + "_pca.joblib"))
     image_save_path = osp.join(save_dir, (name + "_pca.tif"))
     dump(pca_model, model_save_path)  # Save model
@@ -46,11 +46,11 @@ def pca_train(img_path, save_dir="output", dim=3):
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
-    parser.add_argument("--im_path", type=str, required=True, \
+    parser.add_argument("--image_path", type=str, required=True, \
                         help="Path of HSIs image.")
     parser.add_argument("--save_dir", type=str, default="output", \
                         help="Directory to save PCA params(*.joblib). Default: output.")
     parser.add_argument("--dim", type=int, default=3, \
                         help="Dimension to reduce to. Default: 3.")
     args = parser.parse_args()
-    pca_train(args.im_path, args.save_dir, args.dim)
+    pca_train(args.image_path, args.save_dir, args.dim)