1
1
import datatorch
2
2
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
3
6
import requests
4
7
import docker
5
8
import time
14
17
15
18
16
19
directory = os .path .dirname (os .path .abspath (__file__ ))
20
+
17
21
agent_dir = agent .directories ().root
18
22
points = datatorch .get_input ("points" )
19
23
image_path = datatorch .get_input ("imagePath" )
20
24
address = urlparse (datatorch .get_input ("url" ))
21
25
image = datatorch .get_input ("image" )
26
+ annotation_id = datatorch .get_input ("annotationId" )
22
27
23
28
# [[10,20],[30, 40],[50,60],[70,80]]
24
29
# 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):
52
57
print (f"Created DEXTR Container: { container .id } " )
53
58
54
59
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 ] ]:
56
61
agent_folder = agent .directories ().root
57
62
container_path = path .replace (agent_folder , "/agent" )
58
63
@@ -76,6 +81,13 @@ def send_request():
76
81
print (f"Attemp { attempts } : Request to DEXTR Server" )
77
82
seg = call_dextr (image_path , points , address .geturl ())
78
83
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 ())
79
91
exit (0 )
80
92
except Exception as ex :
81
93
if attempts > 5 :
0 commit comments