comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:e59c0e930b1f
1 import argparse
2 import json
3
4 import yaml
5
6
7 # This script genereates the config file required by PlantSeg.
8 # For an overview of the config fields, see:
9 # https://github.com/kreshuklab/plant-seg/blob/master/examples/config.yaml
10
11
12 def listify(d, k, sep=',', dtype=float):
13 if k not in d:
14 return
15 d[k] = [dtype(token.strip()) for token in str(d[k]).split(sep)]
16
17
18 if __name__ == '__main__':
19
20 parser = argparse.ArgumentParser()
21 parser.add_argument('--inputs', type=str, help='Path to the inputs file', required=True)
22 parser.add_argument('--config', type=str, help='Path to the config file', required=True)
23 parser.add_argument('--img_in', type=str, help='Path to the input image', required=True)
24 parser.add_argument('--workers', type=int, default=1)
25 args = parser.parse_args()
26
27 with open(args.inputs, 'r') as fp:
28 inputs = json.load(fp)
29
30 # Set configuration options from the tool wrapper
31 cfg = dict(path=args.img_in)
32 for section_name in (
33 'preprocessing',
34 'cnn_prediction',
35 'cnn_postprocessing',
36 'segmentation',
37 'segmentation_postprocessing',
38 ):
39 cfg[section_name] = inputs[section_name]
40
41 # Set additional required configuration options
42 cfg['preprocessing']['save_directory'] = 'PreProcessing'
43 cfg['preprocessing']['crop_volume'] = '[:,:,:]'
44 cfg['preprocessing']['filter'] = dict(state=False, type='gaussian', filter_param=1.0)
45
46 cfg['cnn_prediction']['device'] = 'cuda'
47 cfg['cnn_prediction']['num_workers'] = args.workers
48 cfg['cnn_prediction']['model_update'] = False
49
50 cfg['segmentation']['name'] = 'MultiCut'
51 cfg['segmentation']['save_directory'] = 'MultiCut'
52
53 # Parse lists of values encoded as strings as actual lists of values
54 listify(cfg['preprocessing'], 'factor')
55 listify(cfg['cnn_prediction'], 'patch')
56
57 with open(args.config, 'w') as fp:
58 fp.write(yaml.dump(cfg))