No project description provided
Project description
yoloproc
A Python package for processing YOLO datasets.
Features
yoloproc provides a collection of tools to manage and preprocess YOLO-formatted datasets. The main features include:
-
Extracting Datasets from Archives: Supports extraction of
.zipand.7zarchives. -
Merging YOLO Data: Merges images and labels from multiple subdirectories into unified
imagesandlabelsfolders. -
Removing Irrelevant Data: Cleans datasets by removing images without labels and vice versa.
-
Extracting Ordered Frames: Extracts frames from image sequences at a specified interval.
-
Generating Empty Annotations: Creates empty label files for images without corresponding annotations.
-
Analyzing Label Information: Counts the number of instances for each class in label files.
-
Organizing Labels: Organizes labels and images into class-specific directories.
-
Visualizing Labeled Images: Draws bounding boxes on images according to YOLO annotations.
-
Rewriting Labels: Rewrites label files based on a new class mapping.
-
Cropping Dataset Images and Labels: Crops images and adjusts labels accordingly.
-
Converting YOLO to COCO Format: Converts a YOLO-formatted dataset to COCO format.
Installation
git clone https://github.com/yourusername/yoloproc.git cd yoloproc pip install .
Usage
1. Extracting Datasets from Archives
Extract all supported archives in a directory to a specified output directory.
from yoloproc.archive_extractor import ArchiveExtractor
extractor = ArchiveExtractor()
extractor.extract_all(
source_dir='/path/to/archives',
output_dir='/path/to/output'
)
2. Merging YOLO Data
Merge images and labels scattered across subdirectories into unified images and labels folders.
from yoloproc.script import merge_yolo_data
merge_yolo_data(
root_path='/path/to/dataset',
output_path='/path/to/output',
is_move=False # Set to True to move files instead of copying
)
3. Removing Irrelevant Data
Remove files without corresponding pairs (e.g., images without labels).
from yoloproc.script import remove_irrelevant_data
# Remove label files (*.txt) without corresponding images
remove_irrelevant_data(
root_path='/path/to/dataset',
remove_type='*.txt'
)
# Remove image files (*.jpg) without corresponding labels
remove_irrelevant_data(
root_path='/path/to/dataset',
remove_type='*.jpg'
)
4. Extracting Ordered Frames
Extract frames from a sequence of images at a specified interval.
from yoloproc.script import extract_ordered_frames
extract_ordered_frames(
image_dir='/path/to/images',
output_dir='/path/to/output',
frame_interval=10, # Extract every 10th frame
label_dir='/path/to/labels' # Optional: handle corresponding labels
)
5. Generating Empty Annotations
Create empty label files for images without annotations.
from yoloproc.script import generate_empty_annotations
generate_empty_annotations(
image_dir='/path/to/images',
label_dir='/path/to/labels'
)
6. Analyzing Label Information
Count instances of each class in label files.
from yoloproc.script import labels_info
labels_info(
labels_path='/path/to/labels',
class_path='/path/to/classes.txt' # Optional
)
7. Organizing Labels
Organize labels and images into class-specific directories.
from yoloproc.yolo_visual_cls import LabelOrganizer
organizer = LabelOrganizer(
dataset_root='/path/to/dataset',
class_file='/path/to/classes.txt' # Optional
)
organizer.organize_labels(
is_move=False # Set to True to move files instead of copying
)
8. Visualizing Labeled Images
Draw bounding boxes on images based on YOLO annotations.
from yoloproc.yolo_im_visual import create_visualizer
create_visualizer(
labels_path='/path/to/labels',
images_path='/path/to/images', # Optional
visuals_path='/path/to/visuals', # Optional
class_path='/path/to/classes.txt', # Optional
interval=1, # Process every image
backend='yolo' # 'yolo' or 'mpl' for different visualization styles
)
9. Rewriting Labels
Rewrite label files with a new class mapping.
from yoloproc.label_rewrite import rewrite_yolo_labels
# Define a new class mapping
class_filter = {
0: 0, # Old class 0 mapped to new class 0
1: 1, # Old class 1 mapped to new class 1
2: 2 # Old class 2 mapped to new class 2
}
rewrite_yolo_labels(
labels_path='/path/to/labels',
class_filter=class_filter,
output_dir='labels2',
remove_empty=False,
custom_output_path='/path/to/output/labels' # Optional
)
10. Cropping Dataset Images and Labels
Crop images and adjust corresponding labels.
from yoloproc.dataset_crop import DatasetCropGestures
crop_origin = (480, 284, 1440, 796) # Define crop coordinates
dataset_path = '/path/to/dataset'
output_path = '/path/to/output'
dataset_crop = DatasetCropGestures(
dataset_path=dataset_path,
output_path=output_path,
crop_origin_xyxy=crop_origin
)
dataset_crop.crop_all_thread()
11. Converting YOLO to COCO Format
Convert a YOLO-formatted dataset to the COCO annotation format.
from yoloproc.yolo2coco import convert_yolo_to_coco
convert_yolo_to_coco(
image_dir='/path/to/dataset',
yolo_class_txt='/path/to/classes.txt' # Optional
)
Dependencies
- Python 3.9 or higher
- tqdm for progress bars
- opencv-python for image processing
- numpy for numerical operations
- Pillow for image handling
- matplotlib for visualization (optional)
- rich for enhanced terminal output (optional)
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
- wm - Initial work - Email
Acknowledgments
- Thanks to all contributors and open-source projects that have provided inspiration and code examples.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
TODO
- Add support for additional archive formats.
- Improve error handling and logging.
- Expand test coverage and add more examples.
- Add dataset splitting functionality (train/val/test)
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 yoloproc-0.1.1.tar.gz.
File metadata
- Download URL: yoloproc-0.1.1.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.9.13 Linux/5.14.0-1058-oem
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78ad8744f3d902fa09aa640e29ad90d953c1e5fc0fa792cf74e63f142e378bdf
|
|
| MD5 |
0a65b4aa6684e73b3d9cdb5d29b7e5fa
|
|
| BLAKE2b-256 |
ee0a0d6d3222b486558c3e7f46502af1a410b2e431fe04f426f57e0f2b69ca07
|
File details
Details for the file yoloproc-0.1.1-py3-none-any.whl.
File metadata
- Download URL: yoloproc-0.1.1-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.9.13 Linux/5.14.0-1058-oem
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36609901b213f8f1ff9af01a91b0fec455eb25eccbf1aa71bf88831e646e6f25
|
|
| MD5 |
40d4ee363b787d2ce3d869956749477e
|
|
| BLAKE2b-256 |
1ad1f08986ff06d532c2a32886ebb69a392071ac1443864306bd5b5eb179ad76
|