-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapper.py
executable file
·56 lines (48 loc) · 2.35 KB
/
wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import os
import glob
from subprocess import call
from cytomine.models import Job
from biaflows import CLASS_TRETRC
from biaflows.helpers import BiaflowsJob, prepare_data, upload_data, upload_metrics
from workflow import workflow
def main(argv):
# 0. Initialize Cytomine client and job
with BiaflowsJob.from_cli(argv) as nj:
nj.job.update(status=Job.RUNNING, progress=0, statusComment="Initialisation...")
problem_cls = CLASS_TRETRC
is_2d = False
# 1. Create working directories on the machine
# 2. Download the images
in_images, gt_images, in_path, gt_path, out_path, tmp_path = prepare_data(problem_cls, nj, is_2d=is_2d, **nj.flags)
# 3. Call the image analysis workflow using the run script
nj.job.update(progress=25, statusComment="Launching workflow...")
workflow(in_images, out_path,
nj.parameters.threshold, nj.parameters.seed, nj.parameters.slip)
#if return_code != 0:
# err_desc = "Failed to execute the Vaa3D (return code: {})".format(return_code)
#nj.job.update(progress=50, statusComment=err_desc)
# raise ValueError(err_desc)
print('files in out_path '+ out_path +': ')
for file in glob.glob(out_path+'/*'):
print(file)
#files = (glob.glob(in_path+"/*.tif"))
#print('Removing flipped images...')
#for i in range(0,len(files)):
# files[i] = files[i].replace('/in/','/out/')
# print(files[i])
#for out_file in files:
# os.remove(out_file)
# 4. Upload the annotation and labels to Cytomine (annotations are extracted from the mask using
# the AnnotationExporter module
upload_data(problem_cls, nj, in_images, out_path, **nj.flags, projection=-1, is_2d=is_2d, monitor_params={
"start": 60, "end": 90,
"period": 0.1,
"prefix": "Extracting and uploading polygons from masks"
})
#5. Compute and upload the metrics
nj.job.update(progress=80, statusComment="Computing and uploading metrics (if necessary)...")
upload_metrics(problem_cls, nj, in_images, gt_path, out_path, tmp_path, **nj.flags)
nj.job.update(status=Job.TERMINATED, progress=100, statusComment="Finished.")
if __name__ == "__main__":
main(sys.argv[1:])