Skip to content

Commit

Permalink
Updated wrapper for new Biaflows utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
lopaavol committed Nov 27, 2020
1 parent 82602d7 commit 42425a8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import skimage.segmentation
from subprocess import call
from cytomine.models import Job
from neubiaswg5 import CLASS_OBJSEG
from neubiaswg5.helpers import NeubiasJob, prepare_data, upload_data, upload_metrics
from biaflows import CLASS_OBJSEG
from biaflows.helpers import BiaflowsJob, prepare_data, upload_data, upload_metrics


def label_objects(img, threshold=0.9, min_size=25):
Expand Down Expand Up @@ -49,10 +49,10 @@ def main(argv):
base_path = "{}".format(os.getenv("HOME")) # Mandatory for Singularity
problem_cls = CLASS_OBJSEG

with NeubiasJob.from_cli(argv) as nj:
nj.job.update(status=Job.RUNNING, progress=0, statusComment="Initialisation...")
with BiaflowsJob.from_cli(argv) as bj:
bj.job.update(status=Job.RUNNING, progress=0, statusComment="Initialisation...")
# 1. Prepare data for workflow
in_imgs, gt_imgs, in_path, gt_path, out_path, tmp_path = prepare_data(problem_cls, nj, **nj.flags)
in_imgs, gt_imgs, in_path, gt_path, out_path, tmp_path = prepare_data(problem_cls, bj, **bj.flags)

temp_img = skimage.io.imread(os.path.join(in_path,"{}".format(in_imgs[0].filename)))
if len(temp_img.shape) > 2:
Expand All @@ -62,7 +62,7 @@ def main(argv):
convert2rgb(in_imgs)

# 2. Run ilastik prediction
nj.job.update(progress=25, statusComment="Launching workflow...")
bj.job.update(progress=25, statusComment="Launching workflow...")
shArgs = [
"/app/ilastik/run_ilastik.sh",
"--headless",
Expand All @@ -80,20 +80,20 @@ def main(argv):
fn = os.path.join(tmp_path,"{}".format(image.filename))
outfn = os.path.join(out_path,"{}".format(image.filename))
img = skimage.io.imread(fn)
img = label_objects(img, nj.parameters.probability_threshold, nj.parameters.min_size)
img = label_objects(img, bj.parameters.probability_threshold, bj.parameters.min_size)
skimage.io.imsave(outfn, img)

# 3. Upload data to Cytomine
upload_data(problem_cls, nj, in_imgs, out_path, **nj.flags, monitor_params={
upload_data(problem_cls, bj, in_imgs, out_path, **bj.flags, monitor_params={
"start": 60, "end": 90, "period": 0.1,
"prefix": "Extracting and uploading polygons from masks"})

# 4. Compute and upload metrics
nj.job.update(progress=90, statusComment="Computing and uploading metrics...")
upload_metrics(problem_cls, nj, in_imgs, gt_path, out_path, tmp_path, **nj.flags)
bj.job.update(progress=90, statusComment="Computing and uploading metrics...")
upload_metrics(problem_cls, bj, in_imgs, gt_path, out_path, tmp_path, **bj.flags)

# 5. Pipeline finished
nj.job.update(progress=100, status=Job.TERMINATED, status_comment="Finished.")
bj.job.update(progress=100, status=Job.TERMINATED, status_comment="Finished.")


if __name__ == "__main__":
Expand Down

0 comments on commit 42425a8

Please sign in to comment.