datachain 0.7.0__py3-none-any.whl → 0.7.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of datachain might be problematic. Click here for more details.

Files changed (52) hide show
  1. datachain/__init__.py +0 -3
  2. datachain/catalog/catalog.py +8 -6
  3. datachain/cli.py +1 -1
  4. datachain/client/fsspec.py +9 -9
  5. datachain/data_storage/schema.py +2 -2
  6. datachain/data_storage/sqlite.py +5 -4
  7. datachain/data_storage/warehouse.py +18 -18
  8. datachain/func/__init__.py +49 -0
  9. datachain/{lib/func → func}/aggregate.py +13 -11
  10. datachain/func/array.py +176 -0
  11. datachain/func/base.py +23 -0
  12. datachain/func/conditional.py +81 -0
  13. datachain/func/func.py +384 -0
  14. datachain/func/path.py +110 -0
  15. datachain/func/random.py +23 -0
  16. datachain/func/string.py +154 -0
  17. datachain/func/window.py +49 -0
  18. datachain/lib/arrow.py +24 -12
  19. datachain/lib/data_model.py +25 -9
  20. datachain/lib/dataset_info.py +2 -2
  21. datachain/lib/dc.py +94 -56
  22. datachain/lib/hf.py +1 -1
  23. datachain/lib/signal_schema.py +1 -1
  24. datachain/lib/utils.py +1 -0
  25. datachain/lib/webdataset_laion.py +5 -5
  26. datachain/model/__init__.py +6 -0
  27. datachain/model/bbox.py +102 -0
  28. datachain/model/pose.py +88 -0
  29. datachain/model/segment.py +47 -0
  30. datachain/model/ultralytics/__init__.py +27 -0
  31. datachain/model/ultralytics/bbox.py +147 -0
  32. datachain/model/ultralytics/pose.py +113 -0
  33. datachain/model/ultralytics/segment.py +91 -0
  34. datachain/nodes_fetcher.py +2 -2
  35. datachain/query/dataset.py +57 -34
  36. datachain/sql/__init__.py +0 -2
  37. datachain/sql/functions/__init__.py +0 -26
  38. datachain/sql/selectable.py +11 -5
  39. datachain/sql/sqlite/base.py +11 -2
  40. datachain/toolkit/split.py +6 -2
  41. {datachain-0.7.0.dist-info → datachain-0.7.2.dist-info}/METADATA +72 -71
  42. {datachain-0.7.0.dist-info → datachain-0.7.2.dist-info}/RECORD +46 -35
  43. {datachain-0.7.0.dist-info → datachain-0.7.2.dist-info}/WHEEL +1 -1
  44. datachain/lib/func/__init__.py +0 -32
  45. datachain/lib/func/func.py +0 -152
  46. datachain/lib/models/__init__.py +0 -5
  47. datachain/lib/models/bbox.py +0 -45
  48. datachain/lib/models/pose.py +0 -37
  49. datachain/lib/models/yolo.py +0 -39
  50. {datachain-0.7.0.dist-info → datachain-0.7.2.dist-info}/LICENSE +0 -0
  51. {datachain-0.7.0.dist-info → datachain-0.7.2.dist-info}/entry_points.txt +0 -0
  52. {datachain-0.7.0.dist-info → datachain-0.7.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,88 @@
1
+ from pydantic import Field
2
+
3
+ from datachain.lib.data_model import DataModel
4
+
5
+
6
+ class Pose(DataModel):
7
+ """
8
+ A data model for representing pose keypoints.
9
+
10
+ Attributes:
11
+ x (list[int]): The x-coordinates of the keypoints.
12
+ y (list[int]): The y-coordinates of the keypoints.
13
+
14
+ The keypoints are represented as lists of x and y coordinates, where each index
15
+ corresponds to a specific body part.
16
+ """
17
+
18
+ x: list[int] = Field(default=[])
19
+ y: list[int] = Field(default=[])
20
+
21
+ @staticmethod
22
+ def from_list(points: list[list[float]]) -> "Pose":
23
+ assert len(points) == 2, "Pose must be a list of 2 lists: x and y coordinates."
24
+ points_x, points_y = points
25
+ assert (
26
+ len(points_x) == len(points_y) == 17
27
+ ), "Pose x and y coordinates must have the same length of 17."
28
+ assert all(
29
+ isinstance(value, (int, float)) for value in [*points_x, *points_y]
30
+ ), "Pose coordinates must be floats or integers."
31
+ return Pose(
32
+ x=[round(coord) for coord in points_x],
33
+ y=[round(coord) for coord in points_y],
34
+ )
35
+
36
+ @staticmethod
37
+ def from_dict(points: dict[str, list[float]]) -> "Pose":
38
+ assert isinstance(points, dict) and set(points) == {
39
+ "x",
40
+ "y",
41
+ }, "Pose must be a dict with keys 'x' and 'y'."
42
+ return Pose.from_list([points["x"], points["y"]])
43
+
44
+
45
+ class Pose3D(DataModel):
46
+ """
47
+ A data model for representing 3D pose keypoints.
48
+
49
+ Attributes:
50
+ x (list[int]): The x-coordinates of the keypoints.
51
+ y (list[int]): The y-coordinates of the keypoints.
52
+ visible (list[float]): The visibility of the keypoints.
53
+
54
+ The keypoints are represented as lists of x, y, and visibility values,
55
+ where each index corresponds to a specific body part.
56
+ """
57
+
58
+ x: list[int] = Field(default=[])
59
+ y: list[int] = Field(default=[])
60
+ visible: list[float] = Field(default=[])
61
+
62
+ @staticmethod
63
+ def from_list(points: list[list[float]]) -> "Pose3D":
64
+ assert (
65
+ len(points) == 3
66
+ ), "Pose3D must be a list of 3 lists: x, y coordinates and visible."
67
+ points_x, points_y, points_v = points
68
+ assert (
69
+ len(points_x) == len(points_y) == len(points_v) == 17
70
+ ), "Pose3D x, y coordinates and visible must have the same length of 17."
71
+ assert all(
72
+ isinstance(value, (int, float))
73
+ for value in [*points_x, *points_y, *points_v]
74
+ ), "Pose3D coordinates must be floats or integers."
75
+ return Pose3D(
76
+ x=[round(coord) for coord in points_x],
77
+ y=[round(coord) for coord in points_y],
78
+ visible=points_v,
79
+ )
80
+
81
+ @staticmethod
82
+ def from_dict(points: dict[str, list[float]]) -> "Pose3D":
83
+ assert isinstance(points, dict) and set(points) == {
84
+ "x",
85
+ "y",
86
+ "visible",
87
+ }, "Pose3D must be a dict with keys 'x', 'y' and 'visible'."
88
+ return Pose3D.from_list([points["x"], points["y"], points["visible"]])
@@ -0,0 +1,47 @@
1
+ from pydantic import Field
2
+
3
+ from datachain.lib.data_model import DataModel
4
+
5
+
6
+ class Segment(DataModel):
7
+ """
8
+ A data model for representing segment.
9
+
10
+ Attributes:
11
+ title (str): The title of the segment.
12
+ x (list[int]): The x-coordinates of the segment.
13
+ y (list[int]): The y-coordinates of the segment.
14
+
15
+ The segment is represented as lists of x and y coordinates, where each index
16
+ corresponds to a specific point.
17
+ """
18
+
19
+ title: str = Field(default="")
20
+ x: list[int] = Field(default=[])
21
+ y: list[int] = Field(default=[])
22
+
23
+ @staticmethod
24
+ def from_list(points: list[list[float]], title: str = "") -> "Segment":
25
+ assert (
26
+ len(points) == 2
27
+ ), "Segment must be a list of 2 lists: x and y coordinates."
28
+ points_x, points_y = points
29
+ assert len(points_x) == len(
30
+ points_y
31
+ ), "Segment x and y coordinates must have the same length."
32
+ assert all(
33
+ isinstance(value, (int, float)) for value in [*points_x, *points_y]
34
+ ), "Segment coordinates must be floats or integers."
35
+ return Segment(
36
+ title=title,
37
+ x=[round(coord) for coord in points_x],
38
+ y=[round(coord) for coord in points_y],
39
+ )
40
+
41
+ @staticmethod
42
+ def from_dict(points: dict[str, list[float]], title: str = "") -> "Segment":
43
+ assert isinstance(points, dict) and set(points) == {
44
+ "x",
45
+ "y",
46
+ }, "Segment must be a dict with keys 'x' and 'y'."
47
+ return Segment.from_list([points["x"], points["y"]], title=title)
@@ -0,0 +1,27 @@
1
+ """
2
+ This module contains the YOLO models.
3
+
4
+ YOLO stands for "You Only Look Once", a family of object detection models that
5
+ are designed to be fast and accurate. The models are trained to detect objects
6
+ in images by dividing the image into a grid and predicting the bounding boxes
7
+ and class probabilities for each grid cell.
8
+
9
+ More information about YOLO can be found here:
10
+ - https://pjreddie.com/darknet/yolo/
11
+ - https://docs.ultralytics.com/
12
+ """
13
+
14
+ from .bbox import YoloBBox, YoloBBoxes, YoloOBBox, YoloOBBoxes
15
+ from .pose import YoloPose, YoloPoses
16
+ from .segment import YoloSegment, YoloSegments
17
+
18
+ __all__ = [
19
+ "YoloBBox",
20
+ "YoloBBoxes",
21
+ "YoloOBBox",
22
+ "YoloOBBoxes",
23
+ "YoloPose",
24
+ "YoloPoses",
25
+ "YoloSegment",
26
+ "YoloSegments",
27
+ ]
@@ -0,0 +1,147 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from pydantic import Field
4
+
5
+ from datachain.lib.data_model import DataModel
6
+ from datachain.model.bbox import BBox, OBBox
7
+
8
+ if TYPE_CHECKING:
9
+ from ultralytics.engine.results import Results
10
+
11
+
12
+ class YoloBBox(DataModel):
13
+ """
14
+ A class representing a bounding box detected by a YOLO model.
15
+
16
+ Attributes:
17
+ cls: The class of the detected object.
18
+ name: The name of the detected object.
19
+ confidence: The confidence score of the detection.
20
+ box: The bounding box of the detected object
21
+ """
22
+
23
+ cls: int = Field(default=-1)
24
+ name: str = Field(default="")
25
+ confidence: float = Field(default=0)
26
+ box: BBox
27
+
28
+ @staticmethod
29
+ def from_result(result: "Results") -> "YoloBBox":
30
+ summary = result.summary()
31
+ if not summary:
32
+ return YoloBBox(box=BBox())
33
+ name = summary[0].get("name", "")
34
+ box = (
35
+ BBox.from_dict(summary[0]["box"], title=name)
36
+ if "box" in summary[0]
37
+ else BBox()
38
+ )
39
+ return YoloBBox(
40
+ cls=summary[0]["class"],
41
+ name=name,
42
+ confidence=summary[0]["confidence"],
43
+ box=box,
44
+ )
45
+
46
+
47
+ class YoloBBoxes(DataModel):
48
+ """
49
+ A class representing a list of bounding boxes detected by a YOLO model.
50
+
51
+ Attributes:
52
+ cls: A list of classes of the detected objects.
53
+ name: A list of names of the detected objects.
54
+ confidence: A list of confidence scores of the detections.
55
+ box: A list of bounding boxes of the detected objects
56
+ """
57
+
58
+ cls: list[int]
59
+ name: list[str]
60
+ confidence: list[float]
61
+ box: list[BBox]
62
+
63
+ @staticmethod
64
+ def from_results(results: list["Results"]) -> "YoloBBoxes":
65
+ cls, names, confidence, box = [], [], [], []
66
+ for r in results:
67
+ for s in r.summary():
68
+ name = s.get("name", "")
69
+ cls.append(s["class"])
70
+ names.append(name)
71
+ confidence.append(s["confidence"])
72
+ box.append(BBox.from_dict(s.get("box", {}), title=name))
73
+ return YoloBBoxes(
74
+ cls=cls,
75
+ name=names,
76
+ confidence=confidence,
77
+ box=box,
78
+ )
79
+
80
+
81
+ class YoloOBBox(DataModel):
82
+ """
83
+ A class representing an oriented bounding box detected by a YOLO model.
84
+
85
+ Attributes:
86
+ cls: The class of the detected object.
87
+ name: The name of the detected object.
88
+ confidence: The confidence score of the detection.
89
+ box: The oriented bounding box of the detected object.
90
+ """
91
+
92
+ cls: int = Field(default=-1)
93
+ name: str = Field(default="")
94
+ confidence: float = Field(default=0)
95
+ box: OBBox
96
+
97
+ @staticmethod
98
+ def from_result(result: "Results") -> "YoloOBBox":
99
+ summary = result.summary()
100
+ if not summary:
101
+ return YoloOBBox(box=OBBox())
102
+ name = summary[0].get("name", "")
103
+ box = (
104
+ OBBox.from_dict(summary[0]["box"], title=name)
105
+ if "box" in summary[0]
106
+ else OBBox()
107
+ )
108
+ return YoloOBBox(
109
+ cls=summary[0]["class"],
110
+ name=name,
111
+ confidence=summary[0]["confidence"],
112
+ box=box,
113
+ )
114
+
115
+
116
+ class YoloOBBoxes(DataModel):
117
+ """
118
+ A class representing a list of oriented bounding boxes detected by a YOLO model.
119
+
120
+ Attributes:
121
+ cls: A list of classes of the detected objects.
122
+ name: A list of names of the detected objects.
123
+ confidence: A list of confidence scores of the detections.
124
+ box: A list of oriented bounding boxes of the detected objects.
125
+ """
126
+
127
+ cls: list[int]
128
+ name: list[str]
129
+ confidence: list[float]
130
+ box: list[OBBox]
131
+
132
+ @staticmethod
133
+ def from_results(results: list["Results"]) -> "YoloOBBoxes":
134
+ cls, names, confidence, box = [], [], [], []
135
+ for r in results:
136
+ for s in r.summary():
137
+ name = s.get("name", "")
138
+ cls.append(s["class"])
139
+ names.append(name)
140
+ confidence.append(s["confidence"])
141
+ box.append(OBBox.from_dict(s.get("box", {}), title=name))
142
+ return YoloOBBoxes(
143
+ cls=cls,
144
+ name=names,
145
+ confidence=confidence,
146
+ box=box,
147
+ )
@@ -0,0 +1,113 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from pydantic import Field
4
+
5
+ from datachain.lib.data_model import DataModel
6
+ from datachain.model.bbox import BBox
7
+ from datachain.model.pose import Pose3D
8
+
9
+ if TYPE_CHECKING:
10
+ from ultralytics.engine.results import Results
11
+
12
+
13
+ class YoloPoseBodyPart:
14
+ """An enumeration of body parts for YOLO pose keypoints."""
15
+
16
+ nose = 0
17
+ left_eye = 1
18
+ right_eye = 2
19
+ left_ear = 3
20
+ right_ear = 4
21
+ left_shoulder = 5
22
+ right_shoulder = 6
23
+ left_elbow = 7
24
+ right_elbow = 8
25
+ left_wrist = 9
26
+ right_wrist = 10
27
+ left_hip = 11
28
+ right_hip = 12
29
+ left_knee = 13
30
+ right_knee = 14
31
+ left_ankle = 15
32
+ right_ankle = 16
33
+
34
+
35
+ class YoloPose(DataModel):
36
+ """
37
+ A data model for YOLO pose keypoints.
38
+
39
+ Attributes:
40
+ cls: The class of the pose.
41
+ name: The name of the pose.
42
+ confidence: The confidence score of the pose.
43
+ box: The bounding box of the pose.
44
+ pose: The 3D pose keypoints.
45
+ """
46
+
47
+ cls: int = Field(default=-1)
48
+ name: str = Field(default="")
49
+ confidence: float = Field(default=0)
50
+ box: BBox
51
+ pose: Pose3D
52
+
53
+ @staticmethod
54
+ def from_result(result: "Results") -> "YoloPose":
55
+ summary = result.summary()
56
+ if not summary:
57
+ return YoloPose(box=BBox(), pose=Pose3D())
58
+ name = summary[0].get("name", "")
59
+ box = (
60
+ BBox.from_dict(summary[0]["box"], title=name)
61
+ if "box" in summary[0]
62
+ else BBox()
63
+ )
64
+ pose = (
65
+ Pose3D.from_dict(summary[0]["keypoints"])
66
+ if "keypoints" in summary[0]
67
+ else Pose3D()
68
+ )
69
+ return YoloPose(
70
+ cls=summary[0]["class"],
71
+ name=name,
72
+ confidence=summary[0]["confidence"],
73
+ box=box,
74
+ pose=pose,
75
+ )
76
+
77
+
78
+ class YoloPoses(DataModel):
79
+ """
80
+ A data model for a list of YOLO pose keypoints.
81
+
82
+ Attributes:
83
+ cls: The classes of the poses.
84
+ name: The names of the poses.
85
+ confidence: The confidence scores of the poses.
86
+ box: The bounding boxes of the poses.
87
+ pose: The 3D pose keypoints of the poses.
88
+ """
89
+
90
+ cls: list[int]
91
+ name: list[str]
92
+ confidence: list[float]
93
+ box: list[BBox]
94
+ pose: list[Pose3D]
95
+
96
+ @staticmethod
97
+ def from_results(results: list["Results"]) -> "YoloPoses":
98
+ cls, names, confidence, box, pose = [], [], [], [], []
99
+ for r in results:
100
+ for s in r.summary():
101
+ name = s.get("name", "")
102
+ cls.append(s["class"])
103
+ names.append(name)
104
+ confidence.append(s["confidence"])
105
+ box.append(BBox.from_dict(s.get("box", {}), title=name))
106
+ pose.append(Pose3D.from_dict(s.get("keypoints", {})))
107
+ return YoloPoses(
108
+ cls=cls,
109
+ name=names,
110
+ confidence=confidence,
111
+ box=box,
112
+ pose=pose,
113
+ )
@@ -0,0 +1,91 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from pydantic import Field
4
+
5
+ from datachain.lib.data_model import DataModel
6
+ from datachain.model.bbox import BBox
7
+ from datachain.model.segment import Segment
8
+
9
+ if TYPE_CHECKING:
10
+ from ultralytics.engine.results import Results
11
+
12
+
13
+ class YoloSegment(DataModel):
14
+ """
15
+ A data model for a single YOLO segment.
16
+
17
+ Attributes:
18
+ cls (int): The class of the segment.
19
+ name (str): The name of the segment.
20
+ confidence (float): The confidence of the segment.
21
+ box (BBox): The bounding box of the segment.
22
+ segment (Segments): The segments of the segment.
23
+ """
24
+
25
+ cls: int = Field(default=-1)
26
+ name: str = Field(default="")
27
+ confidence: float = Field(default=0)
28
+ box: BBox
29
+ segment: Segment
30
+
31
+ @staticmethod
32
+ def from_result(result: "Results") -> "YoloSegment":
33
+ summary = result.summary()
34
+ if not summary:
35
+ return YoloSegment(box=BBox(), segment=Segment())
36
+ name = summary[0].get("name", "")
37
+ box = (
38
+ BBox.from_dict(summary[0]["box"], title=name)
39
+ if "box" in summary[0]
40
+ else BBox()
41
+ )
42
+ segment = (
43
+ Segment.from_dict(summary[0]["segments"], title=name)
44
+ if "segments" in summary[0]
45
+ else Segment()
46
+ )
47
+ return YoloSegment(
48
+ cls=summary[0]["class"],
49
+ name=summary[0]["name"],
50
+ confidence=summary[0]["confidence"],
51
+ box=box,
52
+ segment=segment,
53
+ )
54
+
55
+
56
+ class YoloSegments(DataModel):
57
+ """
58
+ A data model for a list of YOLO segments.
59
+
60
+ Attributes:
61
+ cls (list[int]): The classes of the segments.
62
+ name (list[str]): The names of the segments.
63
+ confidence (list[float]): The confidences of the segments.
64
+ box (list[BBox]): The bounding boxes of the segments.
65
+ segment (list[Segments]): The segments of the segments.
66
+ """
67
+
68
+ cls: list[int]
69
+ name: list[str]
70
+ confidence: list[float]
71
+ box: list[BBox]
72
+ segment: list[Segment]
73
+
74
+ @staticmethod
75
+ def from_results(results: list["Results"]) -> "YoloSegments":
76
+ cls, names, confidence, box, segment = [], [], [], [], []
77
+ for r in results:
78
+ for s in r.summary():
79
+ name = s.get("name", "")
80
+ cls.append(s["class"])
81
+ names.append(name)
82
+ confidence.append(s["confidence"])
83
+ box.append(BBox.from_dict(s.get("box", {}), title=name))
84
+ segment.append(Segment.from_dict(s.get("segments", {}), title=name))
85
+ return YoloSegments(
86
+ cls=cls,
87
+ name=names,
88
+ confidence=confidence,
89
+ box=box,
90
+ segment=segment,
91
+ )
@@ -2,12 +2,12 @@ import logging
2
2
  from collections.abc import Iterable
3
3
  from typing import TYPE_CHECKING
4
4
 
5
- from datachain.node import Node
6
5
  from datachain.nodes_thread_pool import NodesThreadPool
7
6
 
8
7
  if TYPE_CHECKING:
9
8
  from datachain.cache import DataChainCache
10
9
  from datachain.client.fsspec import Client
10
+ from datachain.node import Node
11
11
 
12
12
  logger = logging.getLogger("datachain")
13
13
 
@@ -22,7 +22,7 @@ class NodesFetcher(NodesThreadPool):
22
22
  for task in done:
23
23
  task.result()
24
24
 
25
- def do_task(self, chunk: Iterable[Node]) -> None:
25
+ def do_task(self, chunk: Iterable["Node"]) -> None:
26
26
  from fsspec import Callback
27
27
 
28
28
  class _CB(Callback):