dora-sam2 0.3.10rc1__tar.gz → 0.3.12rc0__tar.gz

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.
@@ -1,12 +1,12 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: dora-sam2
3
- Version: 0.3.10rc1
3
+ Version: 0.3.12rc0
4
4
  Summary: dora-sam2
5
5
  Author-email: Your Name <email@email.com>
6
6
  License: MIT
7
7
  Requires-Python: >=3.10
8
8
  Description-Content-Type: text/markdown
9
- Requires-Dist: dora-rs>=0.3.10rc1
9
+ Requires-Dist: dora-rs>=0.3.9
10
10
  Requires-Dist: huggingface-hub>=0.29.0
11
11
  Requires-Dist: opencv-python>=4.11.0.86
12
12
  Requires-Dist: sam2>=1.1.0
@@ -1,3 +1,5 @@
1
+ """TODO: Add docstring."""
2
+
1
3
  import os
2
4
 
3
5
  # Define the path to the README file relative to the package directory
@@ -1,3 +1,5 @@
1
+ """TODO: Add docstring."""
2
+
1
3
  from .main import main
2
4
 
3
5
  if __name__ == "__main__":
@@ -1,3 +1,5 @@
1
+ """TODO: Add docstring."""
2
+
1
3
  import cv2
2
4
  import numpy as np
3
5
  import pyarrow as pa
@@ -10,6 +12,7 @@ predictor = SAM2ImagePredictor.from_pretrained("facebook/sam2-hiera-large")
10
12
 
11
13
 
12
14
  def main():
15
+ """TODO: Add docstring."""
13
16
  pa.array([]) # initialize pyarrow array
14
17
  node = Node()
15
18
  frames = {}
@@ -119,8 +122,8 @@ def main():
119
122
  {
120
123
  "masks": masks.ravel(),
121
124
  "labels": event["value"]["labels"],
122
- }
123
- ]
125
+ },
126
+ ],
124
127
  ),
125
128
  metadata={
126
129
  "image_id": image_id,
@@ -129,8 +132,10 @@ def main():
129
132
  },
130
133
  )
131
134
 
132
- elif "boxes2d" in event_id:
133
-
135
+ if "boxes2d" in event_id:
136
+ if len(event["value"]) == 0:
137
+ node.send_output("masks", pa.array([]))
138
+ continue
134
139
  if isinstance(event["value"], pa.StructArray):
135
140
  boxes2d = event["value"][0].get("bbox").values.to_numpy()
136
141
  labels = (
@@ -159,7 +164,59 @@ def main():
159
164
  ):
160
165
  predictor.set_image(frames[image_id])
161
166
  masks, _scores, last_pred = predictor.predict(
162
- box=boxes2d, point_labels=labels, multimask_output=False
167
+ box=boxes2d,
168
+ point_labels=labels,
169
+ multimask_output=False,
170
+ )
171
+
172
+ if len(masks.shape) == 4:
173
+ masks = masks[:, 0, :, :]
174
+ last_pred = last_pred[:, 0, :, :]
175
+ else:
176
+ masks = masks[0, :, :]
177
+ last_pred = last_pred[0, :, :]
178
+
179
+ masks = masks > 0
180
+ metadata["image_id"] = image_id
181
+ metadata["width"] = frames[image_id].width
182
+ metadata["height"] = frames[image_id].height
183
+ ## Mask to 3 channel image
184
+ match return_type:
185
+ case pa.Array:
186
+ node.send_output("masks", pa.array(masks.ravel()), metadata)
187
+ case pa.StructArray:
188
+ node.send_output(
189
+ "masks",
190
+ pa.array(
191
+ [
192
+ {
193
+ "masks": masks.ravel(),
194
+ "labels": event["value"]["labels"],
195
+ },
196
+ ],
197
+ ),
198
+ metadata,
199
+ )
200
+ elif "points" in event_id:
201
+ points = event["value"].to_numpy().reshape((-1, 2))
202
+ return_type = pa.Array
203
+ if len(frames) == 0:
204
+ continue
205
+ first_image = next(iter(frames.keys()))
206
+ image_id = event["metadata"].get("image_id", first_image)
207
+ with (
208
+ torch.inference_mode(),
209
+ torch.autocast(
210
+ "cuda",
211
+ dtype=torch.bfloat16,
212
+ ),
213
+ ):
214
+ predictor.set_image(frames[image_id])
215
+ labels = [i for i in range(len(points))]
216
+ masks, _scores, last_pred = predictor.predict(
217
+ points,
218
+ point_labels=labels,
219
+ multimask_output=False,
163
220
  )
164
221
 
165
222
  if len(masks.shape) == 4:
@@ -190,8 +247,8 @@ def main():
190
247
  {
191
248
  "masks": masks.ravel(),
192
249
  "labels": event["value"]["labels"],
193
- }
194
- ]
250
+ },
251
+ ],
195
252
  ),
196
253
  metadata={
197
254
  "image_id": image_id,
@@ -1,12 +1,12 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: dora-sam2
3
- Version: 0.3.10rc1
3
+ Version: 0.3.12rc0
4
4
  Summary: dora-sam2
5
5
  Author-email: Your Name <email@email.com>
6
6
  License: MIT
7
7
  Requires-Python: >=3.10
8
8
  Description-Content-Type: text/markdown
9
- Requires-Dist: dora-rs>=0.3.10rc1
9
+ Requires-Dist: dora-rs>=0.3.9
10
10
  Requires-Dist: huggingface-hub>=0.29.0
11
11
  Requires-Dist: opencv-python>=4.11.0.86
12
12
  Requires-Dist: sam2>=1.1.0
@@ -1,4 +1,4 @@
1
- dora-rs>=0.3.10rc1
1
+ dora-rs>=0.3.9
2
2
  huggingface-hub>=0.29.0
3
3
  opencv-python>=4.11.0.86
4
4
  sam2>=1.1.0
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "dora-sam2"
3
+ version = "0.3.12-rc0"
4
+ authors = [{ name = "Your Name", email = "email@email.com" }]
5
+ description = "dora-sam2"
6
+ license = { text = "MIT" }
7
+ readme = "README.md"
8
+ requires-python = ">=3.10"
9
+
10
+ dependencies = [
11
+ "dora-rs >= 0.3.9",
12
+ "huggingface-hub>=0.29.0",
13
+ "opencv-python>=4.11.0.86",
14
+ "sam2>=1.1.0",
15
+ ]
16
+
17
+ [tool.uv]
18
+ no-build-isolation-package = ['sam2']
19
+
20
+ [dependency-groups]
21
+ dev = ["pytest >=8.1.1", "ruff >=0.9.1"]
22
+
23
+ [project.scripts]
24
+ dora-sam2 = "dora_sam2.main:main"
25
+
26
+ [tool.ruff.lint]
27
+ extend-select = [
28
+ "D", # pydocstyle
29
+ "UP", # Ruff's UP rule
30
+ "PERF", # Ruff's PERF rule
31
+ "RET", # Ruff's RET rule
32
+ "RSE", # Ruff's RSE rule
33
+ "NPY", # Ruff's NPY rule
34
+ "N", # Ruff's N rule
35
+ "I", # Ruff's I rule
36
+ ]
@@ -1,3 +1,5 @@
1
+ """TODO: Add docstring."""
2
+
1
3
  import os
2
4
 
3
5
  import pytest
@@ -6,6 +8,7 @@ CI = os.getenv("CI", "false") in ["True", "true"]
6
8
 
7
9
 
8
10
  def test_import_main():
11
+ """TODO: Add docstring."""
9
12
  if CI:
10
13
  # Skip test as test requires Nvidia GPU
11
14
  return
@@ -1,21 +0,0 @@
1
- [project]
2
- name = "dora-sam2"
3
- version = "0.3.10-rc1"
4
- authors = [{ name = "Your Name", email = "email@email.com" }]
5
- description = "dora-sam2"
6
- license = { text = "MIT" }
7
- readme = "README.md"
8
- requires-python = ">=3.10"
9
-
10
- dependencies = [
11
- "dora-rs >= 0.3.10rc1",
12
- "huggingface-hub>=0.29.0",
13
- "opencv-python>=4.11.0.86",
14
- "sam2>=1.1.0",
15
- ]
16
-
17
- [dependency-groups]
18
- dev = ["pytest >=8.1.1", "ruff >=0.9.1"]
19
-
20
- [project.scripts]
21
- dora-sam2 = "dora_sam2.main:main"
File without changes
File without changes