Skip to main content

A set of easy-to-use utilities that will come in handy in a Computer Vision project

Project description

Overwatch Sayak

Overview

The powers of this library overwatch-sayak package can be used for object detection in images or video, loading datasets, detection tracking, counting, detecting, Slicing Aided Hyper Inferencing for small object detection, etc.

Installation

you need to install the overwatch-sayak package. You can do this using pip:

pip install overwatch-sayak

For importing the library for your code, use the import command with:

import overwatch_sayak

Quickstart

Models

overwatch-sayak was designed to be model-friendly. Just plug in any classification, detection, or segmentation model. We have created connectors for the most popular libraries like Ultralytics, Transformers, or MMDetection for your convenience.

Inference

import cv2
import overwatch_sayak as ov
from inference import get_model

image = cv2.imread("path/to/your/image.jpg")
model = get_model("yolov8s-640")
result = model.infer(image)[0]
detections = ov.Detections.from_inference(result)

len(detections)
# Output: Number of detections

Annotators

overwatch-sayak offers a wide range of highly customizable annotators, allowing you to compose the perfect visualization for your use case.

import cv2
import overwatch_sayak as ov

image = cv2.imread("path/to/your/image.jpg")
detections = ov.Detections(...)

bounding_box_annotator = ov.BoundingBoxAnnotator()
annotated_frame = bounding_box_annotator.annotate(
    scene=image.copy(),
    detections=detections
)

# Display or save the annotated image
cv2.imshow("Annotated Image", annotated_frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Or save the image
cv2.imwrite("annotated_image.jpg", annotated_frame)

Slicing Inference for Small Object Detection

Slicing the image into smaller pieces can improve object detection accuracy for detecting small objects. The following example demonstrates how to use the InferenceSlicer for this purpose.

import overwatch_sayak as ov
from inference import get_model
import cv2
import numpy as np

# Load the image
image = cv2.imread("/path/to/image.jpg")

# Load the model
model = get_model("yolov8s-640")

# Define the callback function for slicing inference
def slicer_callback(slice: np.ndarray) -> ov.Detections:
    result = model.infer(slice)[0]
    detections = ov.Detections.from_inference(result)
    return detections

# Create the slicer
slicer = ov.InferenceSlicer(
    callback=slicer_callback,
    slice_wh=(512, 512),
    overlap_ratio_wh=(0.4, 0.4),
    overlap_filter_strategy=ov.OverlapFilter.NONE
)

# Run the slicer on the image
detections = slicer(image)

# Annotate the image
annotated_frame = ov.BoundingBoxAnnotator().annotate(
    scene=image.copy(),
    detections=detections
)

# Display or save the annotated image
cv2.imshow("Annotated Image", annotated_frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Or save the image
cv2.imwrite("annotated_image.jpg", annotated_frame)

Datasets

overwatch-sayak offers a suite of utilities that enable you to load, split, merge, and save datasets in various supported formats..

import overwatch_sayak as ov

dataset = ov.DetectionDataset.from_yolo(
    images_directory_path="path/to/images",
    annotations_directory_path="path/to/annotations",
    data_yaml_path="path/to/data.yaml"
)

dataset.classes
# Output: ['dog', 'person']

len(dataset)
# Output: Number of images in the dataset

Split

train_dataset, test_dataset = dataset.split(split_ratio=0.7)
test_dataset, valid_dataset = test_dataset.split(split_ratio=0.5)

len(train_dataset), len(test_dataset), len(valid_dataset)
# Output: (Number of training images, Number of test images, Number of validation images)

Merge

ds_1 = ov.DetectionDataset(...)
len(ds_1)
# Output: Number of images in ds_1
ds_1.classes
# Output: ['dog', 'person']

ds_2 = ov.DetectionDataset(...)
len(ds_2)
# Output: Number of images in ds_2
ds_2.classes
# Output: ['cat']

ds_merged = ov.DetectionDataset.merge([ds_1, ds_2])
len(ds_merged)
# Output: Number of images in the merged dataset
ds_merged.classes
# Output: ['cat', 'dog', 'person']

Save

dataset.as_yolo(
    images_directory_path="path/to/save/images",
    annotations_directory_path="path/to/save/annotations",
    data_yaml_path="path/to/save/data.yaml"
)

dataset.as_pascal_voc(
    images_directory_path="path/to/save/images",
    annotations_directory_path="path/to/save/annotations"
)

dataset.as_coco(
    images_directory_path="path/to/save/images",
    annotations_path="path/to/save/annotations"
)

Convert

ov.DetectionDataset.from_yolo(
    images_directory_path="path/to/load/images",
    annotations_directory_path="path/to/load/annotations",
    data_yaml_path="path/to/load/data.yaml"
).as_pascal_voc(
    images_directory_path="path/to/save/images",
    annotations_directory_path="path/to/save/annotations"
)

Contributing

If you want to contribute to this project, feel free to open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License.

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

overwatch_sayak-1.0.3.tar.gz (101.1 kB view details)

Uploaded Source

Built Distribution

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

overwatch_sayak-1.0.3-py3-none-any.whl (121.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: overwatch_sayak-1.0.3.tar.gz
  • Upload date:
  • Size: 101.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for overwatch_sayak-1.0.3.tar.gz
Algorithm Hash digest
SHA256 d1cc5ef1a1169e959321560f86314e89989c4f92e86540d8e12ab952cebf418d
MD5 ba088906432ab52d3189478439c92fde
BLAKE2b-256 282af154196088c3f9b324b10e5e47aac80d1a38e67aabaa4f68b3eccd5d28b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for overwatch_sayak-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9ec7a41a8f1b39e1e161771703be7ab7fa32572529db03f9aa21963cd8efb5d2
MD5 d5ad385698a2623db3b3565e65eccbc5
BLAKE2b-256 0e26f0ab79888aaa39f5be5341318e76874028fc9f1e309aa76c5a99697b1e23

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