ModeYOLO is a versatile Python package designed for efficient color space transformations and simplified dataset modification for deep learning applications. Seamlessly integrating into your workflow, this package empowers users to effortlessly perform diverse color operations and streamline the creation of modified datasets, enhancing the flexibility and convenience of machine learning model training processes.
Project description
ModeYOLO Python Package
Introduction
ModeYOLO is a versatile Python package designed for efficient color space transformations, dataset modification, and YOLO model training. It seamlessly integrates into your workflow, providing solutions for diverse machine learning applications in computer vision.
Dependencies
ModeYOLO depends on the following libraries:
- Ultralytics (
ultralytics
) - PyTorch (
torch
) - os (
os
) - opencv-python (
cv2
)
Folder Structure
Before using the package, ensure that your source dataset follows the following folder structure:
dataset/
|-- train/
| |-- images/
| |-- labels/
|-- test/
| |-- images/
| |-- labels/
|-- val/
| |-- images/
| |-- labels/
|-- data.yaml
ColorOperation Module (ColorOperation.py
)
Class: colorcng
Color Spaces:
Currently we accepting this ['RGB', 'BGR', 'GRAY', 'CrCb', 'LAB', 'HSV']
Color Spaces. Each element in the list corresponds to a specific color space. Here's an explanation of each color space:
-
RGB (Red, Green, Blue): The standard color model used in most digital cameras and displays, where each pixel is represented by three values indicating the intensity of red, green, and blue.
-
BGR (Blue, Green, Red): Similar to RGB but with the order of color channels reversed. OpenCV, a popular computer vision library, uses BGR as its default color order.
-
GRAY (Grayscale): A single-channel color space where each pixel is represented by a single intensity value, typically ranging from black to white.
-
CrCb: A component of the YCbCr color space often used in image and video compression. It separates chrominance (color information) from luminance (brightness information).
-
LAB: The LAB color space represents colors independently of device-specific characteristics. It consists of three components: L* (luminance), a* (green to red), and b* (blue to yellow).
-
HSV (Hue, Saturation, Value): A color space that separates color information into three components: hue (the type of color), saturation (the intensity or vividness of the color), and value (brightness).
Constructor
def __init__(self, path: str, mode: str = 'all') -> None:
"""
Initializes the colorcng object.
Parameters:
- path: str, path to the target directory.
- mode: str, mode of operation ('all', 'rgb', 'bgr', 'gray', 'hsv', 'crcb', 'lab').
"""
Methods
-
cng_rgb
def cng_rgb(self, opt: str, img: np.ndarray, idx: int | str = 0) -> None: """ Converts the image to RGB color space. Parameters: - opt: str, operation type ('train', 'test', 'val'). - img: np.ndarray, input image. - idx: int | str, index for the output file name. """
-
cng_bgr
def cng_bgr(self, opt: str, img: np.ndarray, idx: int | str = 0) -> None: """ Saves the image in BGR color space. Parameters: - opt: str, operation type ('train', 'test', 'val'). - img: np.ndarray, input image. - idx: int | str, index for the output file name. """
-
cng_gray
def cng_gray(self, opt: str, img: np.ndarray, idx: int | str = 0) -> None: """ Converts the image to grayscale. Parameters: - opt: str, operation type ('train', 'test', 'val'). - img: np.ndarray, input image. - idx: int | str, index for the output file name. """
-
cng_hsv
def cng_hsv(self, opt: str, img: np.ndarray, idx: int | str = 0) -> None: """ Converts the image to HSV color space. Parameters: - opt: str, operation type ('train', 'test', 'val'). - img: np.ndarray, input image. - idx: int | str, index for the output file name. """
-
cng_crcb
def cng_crcb(self, opt: str, img: np.ndarray, idx: int | str = 0) -> None: """ Converts the image to YCrCb color space. Parameters: - opt: str, operation type ('train', 'test', 'val'). - img: np.ndarray, input image. - idx: int | str, index for the output file name. """
-
cng_lab
def cng_lab(self, opt: str, img: np.ndarray, idx: int | str = 0) -> None: """ Converts the image to LAB color space. Parameters: - opt: str, operation type ('train', 'test', 'val'). - img: np.ndarray, input image. - idx: int | str, index for the output file name. """
-
execute
def execute(self, opt: str, file: str, idx: int | str = 0) -> None: """ Executes the specified color space transformation. Parameters: - opt: str, operation type ('train', 'test', 'val'). - file: str, path to the input image. - idx: int | str, index for the output file name. """
Dataset Modifier Module (DatasetModifier.py
)
Class: InitModifier
Constructor
def __init__(self, target_directory: str = 'modified_dataset', src_directory: str = 'dataset', mode: str = 'all') -> None:
"""
Initializes the InitModifier object.
Parameters:
- target_directory: str, path to the target directory.
- src_directory: str, path to the source dataset directory.
- mode: str, mode of operation ('all', 'rgb', 'bgr', 'gray', 'hsv', 'crcb', 'lab').
"""
Methods
-
start_train
def start_train(self) -> None: """ Creates the modified training dataset. """
-
start_test
def start_test(self) -> None: """ Creates the modified testing dataset. """
-
start_val
def start_val(self) -> None: """ Creates the modified validation dataset. """
-
reform_dataset
def reform_dataset(self) -> None: """ Reformats the entire dataset. """
Example Usage
# Import the InitModifier class
from ModeYOLO.DatasetModifier import InitModifier
# Create an InitModifier object
init_op = InitModifier(target_directory='modified_dataset', src_directory='dataset', mode='all')
# Create the modified dataset
init_op.reform_dataset()
ModelTrain Module (ModelTrain.py
)
Class: trainYOLO
This submodule facilitates YOLO model training with various pre-trained models. Users can choose from a selection of YOLO models, specify training parameters, and seamlessly integrate it into their workflows.
Pre-trained Models
The trainYOLO
submodule supports training with various pre-trained YOLO models. Choose a model by entering the corresponding index when prompted. Here are the available models:
yolov3u.pt
: YOLOv3 with upsamplingyolov5nu.pt
: YOLOv5 with narrow channelsyolov5su.pt
: YOLOv5 with small modelyolov5mu.pt
: YOLOv5 with medium modelyolov5lu.pt
: YOLOv5 with large modelyolov5xu.pt
: YOLOv5 with extra-large modelyolov5n6u.pt
: YOLOv5 with narrow channels and 6x sizeyolov5s6u.pt
: YOLOv5 with small model and 6x sizeyolov5m6u.pt
: YOLOv5 with medium model and 6x sizeyolov5l6u.pt
: YOLOv5 with large model and 6x sizeyolov5x6u.pt
: YOLOv5 with extra-large model and 6x sizeyolov6n.pt
: YOLOv6 with narrow channelsyolov6s.pt
: YOLOv6 with small modelyolov6m.pt
: YOLOv6 with medium modelyolov6l.pt
: YOLOv6 with large modelyolov6l6.pt
: YOLOv6 with large model and 6x sizeyolov8n.pt
: YOLOv8 with narrow channelsyolov8s.pt
: YOLOv8 with small modelyolov8m.pt
: YOLOv8 with medium modelyolov8l.pt
: YOLOv8 with large modelyolov8x.pt
: YOLOv8 with extra-large modelyolov9s.pt
: YOLOv9 with small modelyolov9m.pt
: YOLOv9 with medium modelyolov9c.pt
: YOLOv9 with complex modelyolov9e.pt
: YOLOv9 with extra-large model
Choose a model based on your specific requirements and follow the on-screen instructions during training for optimal results.
Example Usage
# Import the trainYOLO class
from ModeYOLO.ModelTrain import trainYOLO
# Create a trainYOLO object
yolo_trainer = trainYOLO(target_directory='modified_dataset', src_directory='dataset', mode='all', data_path='./modified_dataset/data.yaml', epochs=1, imgsz=224)
# Train the YOLO model
yolo_trainer.train()
# Validate the trained model
yolo_trainer.val()
Note: Follow the on-screen instructions to choose a YOLO model for training.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
-
Mention any contributors or external libraries that inspired or helped with the development of ModeYOLO.
-
Feel free to adjust the content as needed and let me know if you have further requirements!
-
This example assumes that the source dataset is structured according to the specified folder structure. Adjust the paths and parameters accordingly based on your dataset structure.
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
File details
Details for the file modeyolo-0.2.3.tar.gz
.
File metadata
- Download URL: modeyolo-0.2.3.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.11 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 110e72799a43009d67834e0533ca845c5463587353b1ee85de6ab013a4e3f6f9 |
|
MD5 | 500daad43e4154519ba529fc7930348a |
|
BLAKE2b-256 | 6c0057d1615089618d370338919abc4cae97c00ca66f0eff20aa5f68c2081b9c |
File details
Details for the file modeyolo-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: modeyolo-0.2.3-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.11 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68d6a71b1a8f622a20f4c662c936a6aff583bacebb12a5c60e2ed4429a630716 |
|
MD5 | c212b5bc6050b4ca2a439e06922b2546 |
|
BLAKE2b-256 | be01f698b742cf4ce2de936e8e90c70f83bc588b0aa6aafbf6066944112a804f |