cocoutils-cv-0.0.2
توضیحات
Microsoft COCO data set transformation analysis utils
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | cocoutils-cv-0.0.2 |
| نام | cocoutils-cv |
| نسخه کتابخانه | 0.0.2 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | RaysonShi |
| ایمیل نویسنده | raysonshi@qq.com |
| آدرس صفحه اصلی | https://github.com/Rayson2020-8/cocodataset-utils |
| آدرس اینترنتی | https://pypi.org/project/cocoutils-cv/ |
| مجوز | MIT Licence |
# cocoutils
This tool is mainly for visual analysis of coco datasets, which is divided into three modules: Analyzer, Checker, Transfer, currently only supporting the object detection format;
### Install
```
pip install cocoutils-cv
```
### Usage
```
from cocoutils import Analyzer, Checker, Transfer
```
#### 1、**Analyzer**
For visual analysis of COCO datasets, there are 11 analysis charts;
**Demo:**
```
Analyzer("coco.json")
```
**Paras:**
"""
Analyze coco datasets through charts
:param coco_path (str) : the path of Coco format JSON file
:param save_path (dir) : the dir to save the chart, if None, it will display directly on the desktop
:param map_size (int) : Determine the number of heatmap grids
"""
(1)General information:Count the number of images, targets and categories

(2)Image size number:Number of images per size

(3)Number of targets per picture:Target number of images per image

(4)Number of pictures in each category:The number of each category

(5)Quantity proportion of each category:Proportion of each category

(6)Number of each category:The number of targets contained in each category

(7)Absolute target area:Target size category distribution:(Small <32x32, Big > 96x96, the rest is medium)

(8)Object area distribution:Object absolute area distribution (L x W)

(9)Object relative area distribution:Target relative area distribution, (target area/image area)

(10)Aspect ratio distribution:Target aspect ratio distribution

(11)Object position distribution:The number of target centers distributed on the image

#### 2、**Checker**
Check the data set annotation format, visual analysis and repair, (repair only supports filtering images without annotations and error annotations will be forced to limit the scope of the image)
**Demo:**
```
coco = "coco.json"
repair_coco = "repair_coco.json"
img_dir = "result"
img_id = 2
check = Checker(coco)
check.drawImg(img_id)
check.check()
check.repair(repair_coco)
```
**Paras:**
```
def __init__(self, coco_path):
"""
Check dataset outliers and visualization
:param coco_path (str) : the path of Coco format JSON file
"""
```
```
def drawImg(self, img_dir, img_id, save_dir=None):
"""
Draw annotations through image index
:param img_dir (str) : picture save folder
:param img_id (int) : image id
:param save_dir (int) : save the picture folder after drawing, if None, it will display directly on the desktop
"""
```
```
def check(self, img_dir=None, log="check.txt"):
"""
Check annotations and pictures
:param img_dir (str) : picture save folder, if None, do not check whether the picture exists
:param log (path) : address to save inspection results
"""
```
```::
def repair(self, save_path, img_dir=None):
"""
Repair annotations
:param save_path (str) : save the repaired coco address
:param img_dir (str) : picture save folder, if None, do not check whether the picture exists
"""
```
#### 3、**Transfer**
Data set format conversion, support Custom2COCO, YOLO2COCO, Labelme2Coco, VOC2Coco, merge coco dataset
**Demo:**
```
labelme_dir = r"test"
dst_coco = "coco.json"
transfer = Transfer
transfer.lableme2coco(dst_coco, labelme_dir)
```
**Paras:**
```
def custom(self, dst_coco, img_abs_paths, cats, bboxes):
"""
Custom dataset conversion to coco format
:param dst_coco (str) : the path of Coco format JSON file to save
:param img_abs_pathsh (list) : picture absolute address list, ["path/to/img1.jpg", "path/to/img2.jpg",...]
:param img_abs_pathsh (list) : category name list, [["cat1","cat1","cat2"], ["cat2"],...]
:param bboxes (list) : xywh list, [[xywh1,xywh2,xyw3], [xywh4],...]
The three must match one by one
"""
```
```
def lableme2coco(self, dst_coco, labelme_dir):
"""
Labelme format to coco format
:param dst_coco (str) : the path of Coco format JSON file to save
:param labelme_dir (str) : JSON file folder
"""
```
```
def voc2coco(self, dst_coco, xml_dir):
"""
voc format to coco format
:param dst_coco (str) : the path of Coco format JSON file to save
:param xml_dir (str) : XML file folder
"""
```
```
def yolo2coco(self, dst_coco, txt_dir, img_dir, cat_names=None):
"""
yolo txt format to coco format
:param dst_coco (str) : the path of Coco format JSON file to save
:param txt_dir (str) : txt file folder
:param img_dir (str) : picture folder
:param cat_names (list) : specify category name, if None, use index as name
"""
```
```
def mergeCoco(self, dst_coco, main_coco, second_coco):
"""
Merge two coco datasets
:param dst_coco (str) : the path of Coco format JSON file to save
:param main_coco (str) : the path of Coco, as head
:param second_coco (str) : the path of Coco, as tail
"""
```
نیازمندی
| مقدار | نام |
|---|---|
| - | numpy |
| - | pycocotools |
| - | matplotlib |
| - | tqdm |
| - | opencv-python |
نحوه نصب
نصب پکیج whl cocoutils-cv-0.0.2:
pip install cocoutils-cv-0.0.2.whl
نصب پکیج tar.gz cocoutils-cv-0.0.2:
pip install cocoutils-cv-0.0.2.tar.gz