annotate create_yaml.py @ 0:e434d9b9cd13 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
author iuc
date Thu, 09 Oct 2025 07:42:36 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
1 import argparse
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
2
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
3 import requests
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
4 import yaml
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
5
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
6
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
7 def download_yaml_template(workflow, dims, biapy_version=""):
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
8 """
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
9 Download a YAML template for a specific workflow and dimensions.
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
10
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
11 Parameters:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
12 workflow (str): The workflow type.
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
13 dims (str): The dimensions (e.g., 2d, 3d).
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
14 biapy_version (str): The BiaPy version to use.
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
15
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
16 Returns:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
17 dict: The YAML template as a dictionary.
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
18 """
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
19 template_dir_map = {
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
20 "SEMANTIC_SEG": "semantic_segmentation",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
21 "INSTANCE_SEG": "instance_segmentation",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
22 "DETECTION": "detection",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
23 "DENOISING": "denoising",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
24 "SUPER_RESOLUTION": "super-resolution",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
25 "CLASSIFICATION": "classification",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
26 "SELF_SUPERVISED": "self-supervised",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
27 "IMAGE_TO_IMAGE": "image-to-image",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
28 }
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
29 template_name = (
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
30 template_dir_map[workflow]
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
31 + "/"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
32 + dims.lower() + "_" + template_dir_map[workflow] + ".yaml"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
33 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
34
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
35 url = (
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
36 f"https://raw.githubusercontent.com/BiaPyX/BiaPy/"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
37 f"refs/tags/v{biapy_version}/templates/{template_name}"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
38 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
39 print(f"Downloading YAML template from {url}")
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
40 response = requests.get(url)
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
41 if response.status_code != 200:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
42 raise RuntimeError(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
43 f"Failed to download YAML template: {response.status_code}"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
44 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
45 return yaml.safe_load(response.text)
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
46
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
47
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
48 def tuple_to_list(obj):
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
49 """Convert tuples to lists recursively."""
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
50 if isinstance(obj, tuple):
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
51 return list(obj)
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
52 if isinstance(obj, dict):
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
53 return {k: tuple_to_list(v) for k, v in obj.items()}
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
54 if isinstance(obj, list):
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
55 return [tuple_to_list(v) for v in obj]
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
56 return obj
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
57
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
58
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
59 def main():
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
60 parser = argparse.ArgumentParser(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
61 description="Generate a YAML configuration from given arguments."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
62 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
63 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
64 '--input_config_path', default='', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
65 help="Input configuration file to reuse"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
66 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
67 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
68 '--new_config', action='store_true',
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
69 help="Whether to create a new config or reuse an existing one."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
70 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
71 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
72 '--out_config_path', required=True, type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
73 help="Path to save the generated YAML configuration."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
74 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
75 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
76 '--workflow', default='semantic', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
77 choices=['semantic', 'instance', 'detection', 'denoising',
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
78 'sr', 'cls', 'sr2', 'i2i'],
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
79 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
80 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
81 '--dims', default='2d', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
82 choices=['2d_stack', '2d', '3d'],
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
83 help="Number of dimensions for the problem"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
84 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
85 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
86 '--obj_slices', default='', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
87 choices=['', '1-5', '5-10', '10-20', '20-60', '60+'],
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
88 help="Number of slices for the objects in the images"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
89 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
90 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
91 '--obj_size', default='0-25', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
92 choices=['0-25', '25-100', '100-200', '200-500', '500+'],
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
93 help="Size of the objects in the images"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
94 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
95 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
96 '--img_channel', default=1, type=int,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
97 help="Number of channels in the input images"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
98 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
99 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
100 '--model_source', default='biapy',
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
101 choices=['biapy', 'bmz', 'torchvision'],
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
102 help="Source of the model."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
103 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
104 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
105 '--model', default='', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
106 help=("Path to the model file if using a pre-trained model "
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
107 "from BiaPy or name of the model within BioImage "
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
108 "Model Zoo or TorchVision.")
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
109 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
110 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
111 '--raw_train', default='', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
112 help="Path to the training raw data."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
113 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
114 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
115 '--gt_train', default='', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
116 help="Path to the training ground truth data."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
117 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
118 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
119 '--test_raw_path', default='', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
120 help="Path to the testing raw data."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
121 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
122 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
123 '--test_gt_path', default='', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
124 help="Path to the testing ground truth data."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
125 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
126 parser.add_argument(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
127 '--biapy_version', default='', type=str,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
128 help="BiaPy version to use."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
129 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
130
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
131 args = parser.parse_args()
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
132
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
133 if args.new_config:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
134 workflow_map = {
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
135 "semantic": "SEMANTIC_SEG",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
136 "instance": "INSTANCE_SEG",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
137 "detection": "DETECTION",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
138 "denoising": "DENOISING",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
139 "sr": "SUPER_RESOLUTION",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
140 "cls": "CLASSIFICATION",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
141 "sr2": "SELF_SUPERVISED",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
142 "i2i": "IMAGE_TO_IMAGE",
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
143 }
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
144 workflow_type = workflow_map[args.workflow]
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
145
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
146 if args.dims == "2d_stack":
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
147 ndim = "2D"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
148 as_stack = True
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
149 elif args.dims == "2d":
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
150 ndim = "2D"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
151 as_stack = True
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
152 elif args.dims == "3d":
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
153 ndim = "3D"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
154 as_stack = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
155
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
156 config = download_yaml_template(
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
157 workflow_type, ndim, biapy_version=args.biapy_version
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
158 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
159
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
160 config["PROBLEM"]["TYPE"] = workflow_type
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
161 config["PROBLEM"]["NDIM"] = ndim
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
162 config["TEST"]["ANALIZE_2D_IMGS_AS_3D_STACK"] = as_stack
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
163
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
164 if args.model_source == "biapy":
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
165 config["MODEL"]["SOURCE"] = "biapy"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
166 if args.model:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
167 config["MODEL"]["LOAD_CHECKPOINT"] = True
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
168 config["MODEL"]["LOAD_MODEL_FROM_CHECKPOINT"] = True
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
169 config.setdefault("PATHS", {})
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
170 config["PATHS"]["CHECKPOINT_FILE"] = args.model
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
171 else:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
172 config["MODEL"]["LOAD_CHECKPOINT"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
173 config["MODEL"]["LOAD_MODEL_FROM_CHECKPOINT"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
174 elif args.model_source == "bmz":
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
175 config["MODEL"]["SOURCE"] = "bmz"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
176 config["MODEL"]["LOAD_CHECKPOINT"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
177 config["MODEL"]["LOAD_MODEL_FROM_CHECKPOINT"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
178 config.setdefault("MODEL", {}).setdefault("BMZ", {})
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
179 config["MODEL"]["BMZ"]["SOURCE_MODEL_ID"] = args.model
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
180 elif args.model_source == "torchvision":
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
181 config["MODEL"]["SOURCE"] = "torchvision"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
182 config["MODEL"]["LOAD_CHECKPOINT"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
183 config["MODEL"]["LOAD_MODEL_FROM_CHECKPOINT"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
184 config["MODEL"]["TORCHVISION_MODEL_NAME"] = args.model
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
185
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
186 obj_size_map = {
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
187 "0-25": (256, 256),
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
188 "25-100": (256, 256),
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
189 "100-200": (512, 512),
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
190 "200-500": (512, 512),
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
191 "500+": (1024, 1024),
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
192 }
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
193 obj_size = obj_size_map[args.obj_size]
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
194
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
195 obj_slices_map = {
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
196 "": -1,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
197 "1-5": 5,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
198 "5-10": 10,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
199 "10-20": 20,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
200 "20-60": 40,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
201 "60+": 80,
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
202 }
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
203 obj_slices = obj_slices_map[args.obj_slices]
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
204 if config["PROBLEM"]["NDIM"] == "2D":
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
205 config["DATA"]["PATCH_SIZE"] = obj_size + (args.img_channel,)
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
206 else:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
207 assert obj_slices != -1, (
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
208 "For 3D problems, obj_slices must be specified."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
209 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
210 config["DATA"]["PATCH_SIZE"] = (
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
211 (obj_slices,) + obj_size + (args.img_channel,)
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
212 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
213 config["DATA"]["PATCH_SIZE"] = str(config["DATA"]["PATCH_SIZE"])
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
214 else:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
215 assert args.input_config_path, (
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
216 "Input configuration path must be specified when not "
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
217 "creating a new config."
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
218 )
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
219 with open(args.input_config_path, 'r', encoding='utf-8') as f:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
220 config = yaml.safe_load(f)
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
221
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
222 if args.model:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
223 config["MODEL"]["SOURCE"] = "biapy"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
224 config["MODEL"]["LOAD_CHECKPOINT"] = True
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
225 config["MODEL"]["LOAD_MODEL_FROM_CHECKPOINT"] = True
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
226 config.setdefault("PATHS", {})
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
227 config["PATHS"]["CHECKPOINT_FILE"] = args.model
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
228 else:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
229 config["MODEL"]["LOAD_CHECKPOINT"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
230 config["MODEL"]["LOAD_MODEL_FROM_CHECKPOINT"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
231
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
232 if args.raw_train:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
233 config["TRAIN"]["ENABLE"] = True
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
234 config["DATA"]["TRAIN"]["PATH"] = args.raw_train
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
235 config["DATA"]["TRAIN"]["GT_PATH"] = args.gt_train
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
236 else:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
237 config["TRAIN"]["ENABLE"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
238
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
239 if args.test_raw_path:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
240 config["TEST"]["ENABLE"] = True
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
241 config["DATA"]["TEST"]["PATH"] = args.test_raw_path
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
242 if args.test_gt_path:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
243 config["DATA"]["TEST"]["LOAD_GT"] = True
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
244 config["DATA"]["TEST"]["GT_PATH"] = args.test_gt_path
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
245 else:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
246 config["DATA"]["TEST"]["LOAD_GT"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
247 else:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
248 config["TEST"]["ENABLE"] = False
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
249
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
250 # Always use safetensors in Galaxy
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
251 config["MODEL"]["OUT_CHECKPOINT_FORMAT"] = "safetensors"
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
252
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
253 config = tuple_to_list(config)
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
254
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
255 with open(args.out_config_path, 'w', encoding='utf-8') as f:
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
256 yaml.dump(config, f, default_flow_style=False)
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
257
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
258 print(f"YAML configuration written to {args.out_config_path}")
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
259
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
260
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
261 if __name__ == "__main__":
e434d9b9cd13 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/biapy/ commit 66b393a7118c81d86d0fd80780d2bd551c18f3f0
iuc
parents:
diff changeset
262 main()