Convert COCO dataset to YOLO format in Kaggle environment
Project description
COCO2YOLO Kaggle
A tool for converting COCO dataset to YOLO format in Kaggle environment. This tool is based on ultralytics/JSON2YOLO and optimized for Kaggle environment.
Features
- Automatically convert COCO JSON annotations to YOLO format
- Intelligently handle Kaggle storage space limitations
- Support parallel file operations for faster processing
- Support segment annotations
- Flexible commands for different operations
Installation
pip install coco2yolo-kaggle
Usage
Python API
Label Conversion Only
from coco2yolo_kaggle import convert_coco_labels
# Convert labels only
labels_dir = convert_coco_labels(
json_dir="/kaggle/input/coco-2017-dataset/coco2017/annotations",
output_dir="/kaggle/working/coco_yolo",
use_segments=True,
cls91to80=True
)
File Copy Only
from coco2yolo_kaggle import copy_dataset
# Copy dataset files to final destination
dataset_path = copy_dataset(
json_dir="/kaggle/input/coco-2017-dataset/coco2017/annotations",
output_dir="/kaggle/working/coco_yolo",
final_dest="/kaggle/tmp/COCO2017",
max_workers=8
)
Complete Conversion Process
from coco2yolo_kaggle import convert_coco_dataset
# Complete process (both conversion and copying)
dataset_path = convert_coco_dataset(
json_dir="/kaggle/input/coco-2017-dataset/coco2017/annotations",
output_dir="/kaggle/working/coco_yolo",
final_dest="/kaggle/tmp/COCO2017",
use_segments=True,
cls91to80=True,
max_workers=8,
copy_files=True # Set to False to skip copying files
)
Command Line Usage
Convert Labels Only (Default Mode)
coco2yolo-kaggle --json-dir=/kaggle/input/coco-2017-dataset/coco2017/annotations --output-dir=/kaggle/working/coco_yolo
Copy Files Only
coco2yolo-kaggle --mode=copy --json-dir=/kaggle/input/coco-2017-dataset/coco2017/annotations --output-dir=/kaggle/working/coco_yolo --final-dest=/kaggle/tmp/COCO2017
Complete Process
coco2yolo-kaggle --mode=all --json-dir=/kaggle/input/coco-2017-dataset/coco2017/annotations --output-dir=/kaggle/working/coco_yolo --final-dest=/kaggle/tmp/COCO2017
Kaggle Example Code
# 1. Install the package
!pip install coco2yolo-kaggle
# 2. Convert labels only
!coco2yolo-kaggle --json-dir=/kaggle/input/coco-2017-dataset/coco2017/annotations --output-dir=/kaggle/working/coco_yolo
# 3. Copy dataset files (if needed)
!coco2yolo-kaggle --mode=copy --json-dir=/kaggle/input/coco-2017-dataset/coco2017/annotations --output-dir=/kaggle/working/coco_yolo --final-dest=/kaggle/tmp/COCO2017
# 4. Train a YOLOv8 model
!pip install ultralytics
from ultralytics import YOLO
# Create dataset configuration file
%%writefile coco.yaml
path: /kaggle/tmp/COCO2017
train: images/train2017
val: images/val2017
nc: 80
names: ['person', 'bicycle', 'car', ... ] # Complete 80 class names
# Train the model
model = YOLO('yolov8n.pt') # Use nano model
results = model.train(data='coco.yaml', epochs=3, imgsz=640)
Acknowledgements
This tool is based on ultralytics/JSON2YOLO, thanks to the original authors' contributions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coco2yolo_kaggle-0.1.0.tar.gz.
File metadata
- Download URL: coco2yolo_kaggle-0.1.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c9059db7fa70b23002019ff1d92c4e91f8a6336179f851ed1260778c3dc62ba
|
|
| MD5 |
d389c8b57d43dc5d43700781f27cd611
|
|
| BLAKE2b-256 |
225041cc2c8768b9a1575cd9dc50b663b2bad99895f3d0b4f8cc2dc02b5028cb
|
File details
Details for the file coco2yolo_kaggle-0.1.0-py3-none-any.whl.
File metadata
- Download URL: coco2yolo_kaggle-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c881259eb5c0a2e54500c8f7d69a08c990f2c7233c8aa27efa07afb551c7d16
|
|
| MD5 |
cc5e94f4d60d6db5fd448994171f16b5
|
|
| BLAKE2b-256 |
79971d34e37a26cd156e9db500a7638ff79b0d08b18e85a9b4698b4b07c60991
|