Mercurial > repos > bgruening > json2yolosegment
comparison preprocessing.py @ 3:97bc82ee2a61 draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 743c8acf1ea4e4b1e718743d3772b7e592646611
author | bgruening |
---|---|
date | Mon, 14 Jul 2025 18:28:46 +0000 |
parents | 252fd085940d |
children |
comparison
equal
deleted
inserted
replaced
2:158e6ce48345 | 3:97bc82ee2a61 |
---|---|
1 import argparse | 1 import argparse |
2 import os | 2 import os |
3 import shutil | |
4 | 3 |
5 from sklearn.model_selection import train_test_split | 4 from sklearn.model_selection import train_test_split |
6 | 5 |
7 | 6 |
8 def get_basename(f): | 7 def get_basename(f): |
20 keys = sorted(set(image_dict) & set(label_dict)) | 19 keys = sorted(set(image_dict) & set(label_dict)) |
21 | 20 |
22 return [(image_dict[k], label_dict[k]) for k in keys] | 21 return [(image_dict[k], label_dict[k]) for k in keys] |
23 | 22 |
24 | 23 |
24 def copy_file(src, dst): | |
25 with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst: | |
26 while True: | |
27 chunk = fsrc.read(8192) | |
28 if not chunk: | |
29 break | |
30 fdst.write(chunk) | |
31 | |
32 | |
25 def copy_pairs(pairs, image_src, label_src, image_dst, label_dst): | 33 def copy_pairs(pairs, image_src, label_src, image_dst, label_dst): |
26 os.makedirs(image_dst, exist_ok=True) | 34 os.makedirs(image_dst, exist_ok=True) |
27 os.makedirs(label_dst, exist_ok=True) | 35 os.makedirs(label_dst, exist_ok=True) |
28 for img, lbl in pairs: | 36 for img, lbl in pairs: |
29 shutil.copy(os.path.join(image_src, img), os.path.join(image_dst, img)) | 37 copy_file(os.path.join(image_src, img), os.path.join(image_dst, img)) |
30 shutil.copy(os.path.join(label_src, lbl), os.path.join(label_dst, lbl)) | 38 copy_file(os.path.join(label_src, lbl), os.path.join(label_dst, lbl)) |
31 | 39 |
32 | 40 |
33 def write_yolo_yaml(output_dir): | 41 def write_yolo_yaml(output_dir): |
34 | 42 |
35 yolo_yaml_path = os.path.join(output_dir, "yolo.yml") | 43 yolo_yaml_path = os.path.join(output_dir, "yolo.yml") |