Skip to main content

Python utilities for archive, config and zero-shot detection

Project description

klygo

Thư viện Python hỗ trợ nén/giải nén file, xử lý bộ dữ liệu YOLO, đọc/ghi file cấu hình và nhận diện vật thể zero-shot.


Tính năng chính

  • klygo.archive: Các thao tác với file nén ZIP (nén, giải nén, tìm kiếm, gộp, chia, thêm, xóa file) hỗ trợ hiển thị thanh tiến trình.
  • klygo.datasets: Các công cụ quản lý và xử lý bộ dữ liệu YOLO (phân chia train/val/test, chia lại tỷ lệ tại chỗ, unpartition phẳng hóa, gộp nhiều dataset có ánh xạ lại class ID, và tách dataset theo class/tỷ lệ con).
  • klygo.io: Đọc và ghi các file cấu hình YAML, JSON, TOML, tự động tạo thư mục, tự động phân giải đường dẫn tương đối và truy cập dạng thuộc tính qua Box.
  • klygo.models: Lớp hỗ trợ nhận diện vật thể zero-shot (dựa trên Grounding DINO) trên ảnh và video, tự động xuất dữ liệu theo định dạng YOLO.
  • klygo.visualize: Trực quan hóa hình ảnh, vẽ bounding box, hiển thị kết quả predict, crop vật thể theo nhãn YOLO ra file nén ZIP và biểu đồ hóa phân bổ dữ liệu.

Cấu trúc thư mục

klygo/
├── archive/        # Các tiện ích nén và giải nén
├── datasets/       # Công cụ quản lý và phân chia bộ dữ liệu YOLO
├── io/             # Bộ đọc/ghi cấu hình YAML, JSON, TOML
├── models/         # Lớp nhận diện vật thể (Kernel)
├── visualize/      # Trực quan hóa hình ảnh & crop bboxes
└── validators/     # Bộ xác thực dữ liệu đầu vào

Hướng dẫn sử dụng nhanh

1. Nén và giải nén (klygo.archive as ar)

import klygo.archive as ar

# Nén thư mục và giải nén
ar.compress("src_directory/", "archive.zip")
ar.extract("archive.zip", output="destination_dir/", overwrite=True)

# Tìm kiếm file trong archive
files = ar.search("archive.zip", "images/*.jpg")

Xem tài liệu đầy đủ tại docs/archive/README.md.


2. Quản lý bộ dữ liệu YOLO (klygo.datasets)

from klygo.datasets import partition, repartition, unpartition, merge, split, remap_classes, get_dataset_info

# 1. Phân chia tập dữ liệu thô thành train/val/test
partition(source="raw_data.zip", output="dataset/", ratios=(0.8,), overwrite=True)

# 2. Phẳng hóa tập dữ liệu đã chia về dạng raw ban đầu
unpartition(source="dataset/", output="raw_flat.zip", overwrite=True)

# 3. Hợp nhất hai bộ dữ liệu khác class tự động đổi class ID
merge(sources=["data1/", "data2.zip"], output="merged.zip", overwrite=True)

# 4. Tách nhỏ bộ dữ liệu theo từng class đối tượng riêng biệt
split(source="merged.zip", output_dir="split_classes/", by_class=True, overwrite=True)

# 5. Ánh xạ và đổi tên lớp dữ liệu
remap_classes(source="merged.zip", output="remapped.zip", class_map={0: 1, "apple": "red_apple"}, overwrite=True)

# 6. Lấy thông tin chi tiết của bộ dữ liệu YOLO
info = get_dataset_info("merged.zip")
print(info)

Xem tài liệu đầy đủ tại docs/datasets/README.md.


3. File cấu hình (klygo.io as io)

import klygo.io as io

# Ghi file cấu hình
config_data = {"learning_rate": 0.01, "epochs": 50}
io.write_file("configs/train_params.toml", config_data, overwrite=True)

# Đọc file cấu hình và truy cập bằng thuộc tính
cfg = io.Config("configs/train_params.toml").read()
print(cfg.learning_rate)  # 0.01

Xem tài liệu đầy đủ tại docs/io/README.md.


4. Mô hình nhận diện (klygo.models.Kernel)

from klygo.models import Kernel

# Khởi tạo mô hình Grounding DINO
kernel = Kernel()

# Chạy nhận diện trên video và xuất ra bộ dữ liệu YOLO
kernel.detect(
    input_path="input_video.mp4",
    prompt="car. traffic light.",
    save_yolo_dir="dataset/"
)

Xem tài liệu đầy đủ tại docs/models/README.md.


5. Trực quan hóa & Cắt vật thể (klygo.visualize)

import klygo.visualize as vis

# Hiển thị ảnh kèm bounding box YOLO chỉ định
vis.visualize_dataset_image(
    image_path="dataset/images/frame_0.jpg",
    label_path="dataset/labels/frame_0.txt",
    classes=["car", "bus"]
)

# Cắt các vật thể trong ảnh và lưu vào file ZIP
vis.crop_objects(
    image_path="dataset/images/frame_0.jpg",
    label_path="dataset/labels/frame_0.txt",
    classes=["car", "bus"],
    output_zip="crops.zip",
    overwrite=True
)

# Đọc ngược lại danh sách ảnh crop từ file ZIP
cropped_dict = vis.read_cropped_objects("crops.zip")

Xem tài liệu đầy đủ tại docs/visualize/README.md.


Cài đặt

git clone https://github.com/your-username/klygo.git
cd klygo
uv sync

Tài liệu chi tiết

Tất cả hướng dẫn đầy đủ đều được lưu tại thư mục docs:

  • Hướng dẫn nén & giải nén: docs/archive/README.md
  • Hướng dẫn xử lý bộ dữ liệu YOLO: docs/datasets/README.md
  • Hướng dẫn cấu hình & IO: docs/io/README.md
  • Hướng dẫn nhận diện vật thể: docs/models/README.md
  • Hướng dẫn trực quan hóa & biểu diễn ảnh: docs/visualize/README.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

klygo-1.0.3.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

klygo-1.0.3-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

Details for the file klygo-1.0.3.tar.gz.

File metadata

  • Download URL: klygo-1.0.3.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for klygo-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b321fdbdf5567a6d1b12501e448ceeda19adc872710abcc26a9cadc8e29606fb
MD5 65d118e2cd7be4f6d034f747471f2ecc
BLAKE2b-256 731a8abe9cd041d01f8a37480c0f56abfe6a22506003258b82fd57a6b7363301

See more details on using hashes here.

File details

Details for the file klygo-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: klygo-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 45.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for klygo-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3f786f967f5a4b82945da73d7e3ac13a4c8b1c7b989ee93252f9155831e85787
MD5 6ffa49d7175620772b35108a020647fc
BLAKE2b-256 38252411d2a573044b4218e32863a9ddf616125a36e16850184a26e7f48b22bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page