Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Models update 2 #924

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@ cython_debug/

# pt files produced by ultralytics examples
*.pt

# OS X
.DS_Store
46 changes: 46 additions & 0 deletions docs/references/data-types/yolo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# YOLO (Ultralytics) models

YOLO (You Only Look Once) by Ultralytics is a state-of-the-art object detection framework
that provides fast and accurate real-time predictions. Developed by Ultralytics,
it supports tasks like object detection, instance segmentation, and pose estimation.
The framework is easy to use, highly optimized, and supports training and inference
with PyTorch.

For more details, visit [Ultralytics YOLO](https://github.com/ultralytics/ultralytics).

### Example

See more use cases in the datachain repo [examples](https://github.com/iterative/datachain/tree/main/examples).

```python
from ultralytics import YOLO

from datachain import DataChain, ImageFile
from datachain.model.yolo import YoloBox


def process_boxes(yolo: YOLO, file: ImageFile) -> YoloBox:
results = yolo(file.read(), verbose=False)
return YoloBox.from_yolo_results(results)


(
DataChain.from_storage("gs://datachain-demo/coco2017/images", type="image")
.limit(20)
.setup(yolo=lambda: YOLO("yolo11n.pt"))
.map(boxes=process_boxes)
.show()
)
```

::: datachain.model.yolo.YoloBox

::: datachain.model.yolo.YoloObb

::: datachain.model.yolo.YoloSeg

::: datachain.model.yolo.YoloPose

::: datachain.model.yolo.YoloPoseBodyPart

::: datachain.model.yolo.YoloCls
1 change: 1 addition & 0 deletions docs/references/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DataChain's API is organized into several modules:
- [BBox](./data-types/bbox.md) - Bounding box data type
- [Pose](./data-types/pose.md) - Pose data type
- [Segment](./data-types/segment.md) - Segment data type
- [Yolo](./data-types/yolo.md) - YOLO (Ultralytics) models
- [UDF](./udf.md) - User-defined functions and transformations
- [Functions](./func.md) - Built-in functions for data manipulation and analysis
- [Torch](./torch.md) - PyTorch data loading utilities
Expand Down
27 changes: 0 additions & 27 deletions examples/computer_vision/ultralytics-bbox.py

This file was deleted.

27 changes: 0 additions & 27 deletions examples/computer_vision/ultralytics-pose.py

This file was deleted.

27 changes: 0 additions & 27 deletions examples/computer_vision/ultralytics-segment.py

This file was deleted.

18 changes: 18 additions & 0 deletions examples/computer_vision/yolo-bbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from ultralytics import YOLO

from datachain import DataChain, ImageFile
from datachain.model.yolo import YoloBox


def process_boxes(yolo: YOLO, file: ImageFile) -> YoloBox:
results = yolo(file.read(), verbose=False)
return YoloBox.from_yolo_results(results)


(
DataChain.from_storage("gs://datachain-demo/coco2017/images", type="image")
.limit(20)
.setup(yolo=lambda: YOLO("yolo11n.pt"))
.map(boxes=process_boxes)
.show()
)
18 changes: 18 additions & 0 deletions examples/computer_vision/yolo-pose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from ultralytics import YOLO

from datachain import DataChain, ImageFile
from datachain.model.yolo import YoloPose


def process_poses(yolo: YOLO, file: ImageFile) -> YoloPose:
results = yolo(file.read(), verbose=False)
return YoloPose.from_yolo_results(results)


(
DataChain.from_storage("gs://datachain-demo/coco2017/images", type="image")
.limit(20)
.setup(yolo=lambda: YOLO("yolo11n-pose.pt"))
.map(poses=process_poses)
.show()
)
18 changes: 18 additions & 0 deletions examples/computer_vision/yolo-segment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from ultralytics import YOLO

from datachain import DataChain, File
from datachain.model.yolo import YoloSeg


def process_segments(yolo: YOLO, file: File) -> YoloSeg:
results = yolo(file.read(), verbose=False)
return YoloSeg.from_yolo_results(results)


(
DataChain.from_storage("gs://datachain-demo/coco2017/images", type="image")
.limit(20)
.setup(yolo=lambda: YOLO("yolo11n-seg.pt"))
.map(segments=process_segments)
.show()
)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ nav:
- BBox: references/data-types/bbox.md
- Pose: references/data-types/pose.md
- Segment: references/data-types/segment.md
- Yolo: references/data-types/yolo.md
- UDF: references/udf.md
- Torch: references/torch.md
- Functions: references/func.md
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ tests = [
"hypothesis",
"aiotools>=1.7.0",
"requests-mock",
"scipy"
"scipy",
"ultralytics"
]
dev = [
"datachain[docs,tests]",
Expand All @@ -118,7 +119,7 @@ examples = [
"defusedxml",
"accelerate",
"huggingface_hub[hf_transfer]",
"ultralytics==8.3.74",
"ultralytics",
"open_clip_torch"
]

Expand Down
16 changes: 14 additions & 2 deletions src/datachain/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from . import ultralytics
from .bbox import BBox, OBBox
from .pose import Pose, Pose3D
from .segment import Segment
from .yolo import YoloBox, YoloCls, YoloObb, YoloPose, YoloPoseBodyPart, YoloSeg

__all__ = ["BBox", "OBBox", "Pose", "Pose3D", "Segment", "ultralytics"]
__all__ = [
"BBox",
"OBBox",
"Pose",
"Pose3D",
"Segment",
"YoloBox",
"YoloCls",
"YoloObb",
"YoloPose",
"YoloPoseBodyPart",
"YoloSeg",
]
Loading