Skip to content

Commit 0472dd6

Browse files
committed
Upload annotations
1 parent 13bdefe commit 0472dd6

File tree

1 file changed

+81
-26
lines changed

1 file changed

+81
-26
lines changed

ascent/ascent/cli.py

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,36 @@ def upload_arguments(func):
7373
return func
7474

7575

76+
_upload_options = [
77+
click.option(
78+
"--parent-folder-id",
79+
type=str,
80+
help="The _id of girder folder that the new folder will be created in. Defaults to user root."
81+
),
82+
click.option(
83+
"--annotations-path",
84+
type=click.Path(exists=True, readable=True, path_type=Path),
85+
help="Local path for corresponding annotations file to be uploaded."
86+
87+
)
88+
89+
]
90+
91+
92+
def upload_options(func):
93+
for option in _upload_options:
94+
func = option(func)
95+
return func
96+
97+
7698
apiURL = "localhost"
7799

78100

79101
def login(api, port):
80-
apiURL = api if api else "localhost"
81-
local_port = port if port else 8010
102+
82103
gc = girder_client.GirderClient(
83-
apiURL,
84-
port=local_port,
104+
api,
105+
port=port,
85106
apiRoot="girder/api/v1"
86107
)
87108
if not os.environ.get('DIVE_USER') or not os.environ.get('DIVE_PW'):
@@ -130,88 +151,122 @@ def upload():
130151
@upload_arguments
131152
@global_options
132153
@click.option(
133-
"--parent-folder",
134-
type=str,
135-
help="The _id of girder folder that the new folder will be created in. Defaults to user root."
136-
)
137-
def image_sequence(parent_folder, folder_name, path: Path, url, port):
154+
"--annotations-included",
155+
is_flag=True,
156+
help="Annotations for the image set are in the same directory and should be uploaded"
157+
)
158+
@upload_options
159+
def image_sequence(
160+
parent_folder_id,
161+
folder_name,
162+
path: Path,
163+
url,
164+
port,
165+
annotations_included,
166+
annotations_path: Path
167+
):
138168
"""
139169
Create folder with FOLDER_NAME in PARENT_FOLDER and upload a set of images from PATH\n
140170
141171
FOLDER_NAME is a unique name for the folder to be created \n
142172
PATH is the the local path for the images to be uploaded
143173
"""
144-
gc = login(url, port)
145-
new_folder = create_folder(parent_folder, folder_name, gc)
174+
apiURL = url if url else "localhost"
175+
local_port = port if port else 8010
176+
gc = login(apiURL, local_port)
177+
new_folder = create_folder(parent_folder_id, folder_name, gc)
146178

147179
if new_folder:
180+
count = 1
181+
images = len(list(path.iterdir()))
148182
for file in path.iterdir():
149183
if file.is_file():
184+
if annotations_included:
185+
if file.suffix == '.json' or file.suffix == '.csv':
186+
images = images - 1
187+
gc.uploadFileToFolder(new_folder["_id"], file)
150188
mimetype = mimetypes.guess_type(file.name)
151189
if mimetype[0] in supportedImageTypes:
152-
gc.uploadFileToFolder(new_folder["_id"], file)
190+
click.echo(f"Uploading image {count} of {images}")
191+
gc.uploadFileToFolder(new_folder["_id"], file)
192+
count = count + 1
193+
194+
if annotations_path:
195+
gc.uploadFileToFolder(new_folder["_id"], annotations_path)
153196
gc.addMetadataToFolder(
154197
new_folder["_id"],
155198
{
156199
"type": "image-sequence",
157200
"fps": 1,
158201
},
159202
)
203+
click.echo("Processing")
160204
gc.sendRestRequest(
161205
"POST",
162206
f"dive_rpc/postprocess/{new_folder['_id']}",
163207
data={"skipTranscoding": True},
164208
)
209+
click.echo(
210+
f"Dataset ready at: http://{apiURL}:{local_port}/#/viewer/{new_folder['_id']}"
211+
)
165212

166213

167214
@upload.command()
168215
@upload_arguments
169-
@click.option(
170-
"--parent-folder",
171-
type=str,
172-
help="The _id of girder folder that the new folder will be created in. Defaults to user root."
173-
)
174-
def video(parent_folder, folder_name, path, url, port):
216+
@upload_options
217+
def video(parent_folder, folder_name, path, url, port, annotations_path: Path):
175218
"""
176219
Create folder with FOLDER_NAME in PARENT_FOLDER and upload a video from PATH\n
177220
178221
FOLDER_NAME is a unique name for the folder to be created \n
179222
PATH is the the local path for the video to be uploaded
180223
"""
181-
gc = login(url, port)
224+
apiURL = url if url else "localhost"
225+
local_port = port if port else 8010
226+
gc = login(apiURL, local_port)
182227
new_folder = create_folder(parent_folder, folder_name, gc)
183228
if new_folder:
229+
click.echo("Uploading video.")
184230
gc.uploadFileToFolder(new_folder["_id"], path)
231+
if annotations_path:
232+
gc.uploadFileToFolder(new_folder["_id"], annotations_path)
185233
gc.addMetadataToFolder(
186234
new_folder["_id"],
187235
{
188236
"type": "video",
189237
"fps": -1,
190238
},
191239
)
240+
click.echo("Processing")
192241
gc.sendRestRequest(
193242
"POST",
194243
f"dive_rpc/postprocess/{new_folder['_id']}",
195244
data={"skipTranscoding": True},
196245
)
246+
click.echo(
247+
f"Dataset ready at: http://{apiURL}:{local_port}/#/viewer/{new_folder['_id']}"
248+
)
197249

198250

199251
@upload.command()
200252
@upload_arguments
201-
@click.option(
202-
"--parent-folder",
203-
type=str,
204-
help="The _id of girder folder that the new folder will be created in. Defaults to user root."
205-
)
206-
def zip(parent_folder, folder_name, path, url, port):
253+
@upload_options
254+
def zip(parent_folder, folder_name, path, url, port, annotations_path: Path):
207255
"""
208256
Create folder with FOLDER_NAME in PARENT_FOLDER and upload a zip file from PATH\n
209257
210258
FOLDER_NAME is a unique name for the folder to be created \n
211259
PATH is the the local path for the zip file to be uploaded
212260
"""
213-
gc = login(url, port)
261+
apiURL = url if url else "localhost"
262+
local_port = port if port else 8010
263+
gc = login(apiURL, local_port)
214264
new_folder = create_folder(parent_folder, folder_name, gc)
215265
if new_folder:
216266
gc.uploadFileToFolder(new_folder["_id"], path)
267+
if annotations_path:
268+
gc.uploadFileToFolder(new_folder["_id"], annotations_path)
269+
click.echo(
270+
f"Dataset ready at: http://{apiURL}:{local_port}/#/viewer/{new_folder['_id']}"
271+
)
217272
# TODO unzip

0 commit comments

Comments
 (0)