Skip to content

Commit 098bc29

Browse files
committed
chore: add annotation insert
1 parent d38c9ee commit 098bc29

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

action-datatorch.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ inputs:
2222
type: string
2323
default: datatorch/action-dextr
2424
description: Container image to spin up.
25+
annotationId:
26+
type: string
27+
default: null
28+
description: >
29+
Annotation to insert segmentation into. If not provided the segmentation
30+
will not be inserted.
2531
outputs:
2632
segmentation:
2733
type: array

client.py

-19
This file was deleted.

entry.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import datatorch
22
from datatorch import agent, set_output
3+
from datatorch.api.api import ApiClient
4+
from datatorch.api.entity.sources.image import Segmentations
5+
from datatorch.api.entity.sources.image import segmentations
36
import requests
47
import docker
58
import time
@@ -14,11 +17,13 @@
1417

1518

1619
directory = os.path.dirname(os.path.abspath(__file__))
20+
1721
agent_dir = agent.directories().root
1822
points = datatorch.get_input("points")
1923
image_path = datatorch.get_input("imagePath")
2024
address = urlparse(datatorch.get_input("url"))
2125
image = datatorch.get_input("image")
26+
annotation_id = datatorch.get_input("annotationId")
2227

2328
# [[10,20],[30, 40],[50,60],[70,80]]
2429
# points: List[Point] = [(10.0, 20.0), (30.0, 40.0), (50.0, 60.0), (70.0, 80.0)]
@@ -52,7 +57,7 @@ def start_server(port: int):
5257
print(f"Created DEXTR Container: {container.id}")
5358

5459

55-
def call_dextr(path: str, points: List[Point], address: str) -> List[Point]:
60+
def call_dextr(path: str, points: List[Point], address: str) -> List[List[Point]]:
5661
agent_folder = agent.directories().root
5762
container_path = path.replace(agent_folder, "/agent")
5863

@@ -76,6 +81,13 @@ def send_request():
7681
print(f"Attemp {attempts}: Request to DEXTR Server")
7782
seg = call_dextr(image_path, points, address.geturl())
7883
set_output("polygons", seg)
84+
print(annotation_id)
85+
if annotation_id is not None:
86+
print(f"Creating segmentation source for annotation {annotation_id}")
87+
s = Segmentations()
88+
s.annotation_id = annotation_id
89+
s.path_data = seg
90+
s.create(ApiClient())
7991
exit(0)
8092
except Exception as ex:
8193
if attempts > 5:

0 commit comments

Comments
 (0)