用于深度学习的图像准备工具
imageprep的Python项目详细描述
ImagePrep是一个用于准备不同格式的图像标签的工具,主要用于对象检测任务。在
深度学习框架希望数据集的结构、风格或格式能够 适合他们的工作流程。使用ImagePrep,您可以根据这些信息轻松地组织标签 要求。目前,该工具简化了使用COCO准备标签的过程, Pascal VOC和YOLO风格的格式。也支持从另一个到另一个的转换。在
安装
稳定版本
pip install imageprep
最新版本:
^{pr2}$用法
示例1:以COCO样式组织图像和标签
fromimageprepimportcoco"""Folder Structure of a moc datasetdata├── images│ ├── 145_28.jpg│ ├── 79_38.jpg│ ├── 79_45.jpg│ └── 80_7.jpg└── labels ├── 145_28.txt ├── 79_38.txt ├── 79_45.txt └── 80_7.txt"""# folder containing imagesimage_path="data/images/"label_path="data/labels/"# run taskcoco_dict=coco.coco_format_folder(image_path,label_path)print(coco_dict)
输出:
[{"image":[{"file_name":"data/images/145_28.jpg","height":416,"width":416}],"annotations":[{"bbox":[336,398,416,416],"id":1,"segmentation":[],"area":1440,"category_id":0},{"bbox":[3,91,105,163],"id":2,"segmentation":[],"area":7344,"category_id":0},{"bbox":[134,31,196,95],"id":3,"segmentation":[],"area":3968,"category_id":0}],"image_id":0},{"image":[{"file_name":"data/images/79_38.jpg","height":416,"width":416}],"annotations":[{"bbox":[257,306,325,370],"id":1,"segmentation":[],"area":4352,"category_id":0}],"image_id":1}]
示例2:将绝对边界框值转换为YOLO样式格式
XminYminXmaxYmax----->;xCenter中心宽度高度
fromimageprepimportyolo"""# Input BBOX in absolute format (Xmin, Ymin, Xmax, Ymax)├── labels ├── 145_28.txt │ ├── 336 398 416 416 │ ├── 3 91 105 163 │ ├── 134 31 196 95 ├── 79_38.txt │ ├── 257 306 325 370 ├── 79_45.txt │ ├── 0 399 133 416 │ ├── 161 255 239 343 │ ├── 336 32 416 108 └── 80_7.txt ├── 267 223 391 319"""# folder containing imagesimage_path="data/images/"label_path="data/labels/"output_path="data/yolo_labels/"# run task and save text yolo.convert_to_yolo(image_path,label_path,output_path)
输出:
# Output BBOX in relative format (Xcenter, Ycenter, Width, Height)├──yolo_labels├──145_28.txt│├──0.90384615384615390.97836538461538470.192307692307692320.04326923076923077│├──0.129807692307692320.305288461538461560.24519230769230770.17307692307692307│├──0.39663461538461540.15144230769230770.149038461538461540.15384615384615385├──79_38.txt│├──0.69951923076923080.81250.163461538461538460.15384615384615385├──79_45.txt│├──0.159855769230769250.97956730769230770.31971153846153850.040865384615384616│├──0.48076923076923080.718750.18750.21153846153846156│├──0.90384615384615390.168269230769230780.192307692307692320.1826923076923077└──80_7.txt├──0.79086538461538470.65144230769230770.29807692307692310.23076923076923078
命令行
Usage: imageprep [OPTIONS] COMMAND [ARGS]... Dataset Preparation Helper Options: -h, --help Show this message and exit. Commands: convert-to-yolo Converts absolute bbox values to relative ones create-path-file Writes out the path to images in a folder as a list get-image-name Prints out the names of images in a folder resize-images Resizes Image dimension to a size provided by user
CLI仍处于开发的早期阶段。在
用例:
上述输出可以很容易地与数据注册步骤集成 需要使用Detectron2训练一个掩模RCNN模型。 查看示例here。在
库中包含的其他功能:
- 创建所有边界框的列表
- 将图像堆叠并保存为numpy数组
- 将标签作为JSON对象转储到文件中
- 在单个或多个文件夹中调整图像大小
- 将相对(YOLO样式)值转换为绝对值
- 将标签的python字典定制为Detectron2格式 还有更多。。。在
TODO:当前和未来的工作
- 改进CLI
- 添加VOC样式的工作流
- 针对RCNN家族的测试
- 创建文档
- 改进Detectron2和YOLO的集成
- 项目
标签: