Mercurial > repos > imgteam > plantseg
annotate create-config.py @ 0:e59c0e930b1f draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
author | imgteam |
---|---|
date | Wed, 26 Jun 2024 08:03:08 +0000 |
parents | |
children |
rev | line source |
---|---|
0
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
1 import argparse |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
2 import json |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
3 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
4 import yaml |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
5 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
6 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
7 # This script genereates the config file required by PlantSeg. |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
8 # For an overview of the config fields, see: |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
9 # https://github.com/kreshuklab/plant-seg/blob/master/examples/config.yaml |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
10 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
11 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
12 def listify(d, k, sep=',', dtype=float): |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
13 if k not in d: |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
14 return |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
15 d[k] = [dtype(token.strip()) for token in str(d[k]).split(sep)] |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
16 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
17 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
18 if __name__ == '__main__': |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
19 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
20 parser = argparse.ArgumentParser() |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
21 parser.add_argument('--inputs', type=str, help='Path to the inputs file', required=True) |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
22 parser.add_argument('--config', type=str, help='Path to the config file', required=True) |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
23 parser.add_argument('--img_in', type=str, help='Path to the input image', required=True) |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
24 parser.add_argument('--workers', type=int, default=1) |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
25 args = parser.parse_args() |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
26 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
27 with open(args.inputs, 'r') as fp: |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
28 inputs = json.load(fp) |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
29 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
30 # Set configuration options from the tool wrapper |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
31 cfg = dict(path=args.img_in) |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
32 for section_name in ( |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
33 'preprocessing', |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
34 'cnn_prediction', |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
35 'cnn_postprocessing', |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
36 'segmentation', |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
37 'segmentation_postprocessing', |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
38 ): |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
39 cfg[section_name] = inputs[section_name] |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
40 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
41 # Set additional required configuration options |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
42 cfg['preprocessing']['save_directory'] = 'PreProcessing' |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
43 cfg['preprocessing']['crop_volume'] = '[:,:,:]' |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
44 cfg['preprocessing']['filter'] = dict(state=False, type='gaussian', filter_param=1.0) |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
45 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
46 cfg['cnn_prediction']['device'] = 'cuda' |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
47 cfg['cnn_prediction']['num_workers'] = args.workers |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
48 cfg['cnn_prediction']['model_update'] = False |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
49 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
50 cfg['segmentation']['name'] = 'MultiCut' |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
51 cfg['segmentation']['save_directory'] = 'MultiCut' |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
52 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
53 # Parse lists of values encoded as strings as actual lists of values |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
54 listify(cfg['preprocessing'], 'factor') |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
55 listify(cfg['cnn_prediction'], 'patch') |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
56 |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
57 with open(args.config, 'w') as fp: |
e59c0e930b1f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff
changeset
|
58 fp.write(yaml.dump(cfg)) |