Last active
December 15, 2022 18:19
-
-
Save guidorice/3190c8dbcf9b869d8ec42bc0537a0688 to your computer and use it in GitHub Desktop.
model_ecaas_agrifieldnet_silver / prepare dirs named by chip id.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Preprocess chips and fields dirs for model_ecaas_agrifieldnet_silver. | |
| """ | |
| from pathlib import Path | |
| import shutil | |
| dataset_src = Path.home() / 'data/ref_agrifieldnet_competition_v1' | |
| fields_src = dataset_src / 'ref_agrifieldnet_competition_v1_labels_test' | |
| images_src = dataset_src / 'ref_agrifieldnet_competition_v1_source' | |
| fields_dest = Path.cwd() / 'fields' | |
| images_dest = Path.cwd() / 'images' # instead use `Images` capitalized directory name, if running masawdah's docker image. | |
| chip_ids = set() | |
| for field_dir in fields_src.iterdir(): | |
| chip_id = str(field_dir).split('_').pop() | |
| if '.json' in chip_id: | |
| continue | |
| print(f'copy field {chip_id}...') | |
| shutil.copytree(field_dir, fields_dest / chip_id, dirs_exist_ok=True) | |
| chip_ids.add(chip_id) | |
| for image_dir in images_src.iterdir(): | |
| chip_id = str(image_dir).split('_').pop() | |
| if '.json' in chip_id: | |
| continue | |
| if chip_id not in chip_ids: | |
| continue | |
| print(f'copy image {chip_id}...') | |
| shutil.copytree(image_dir, images_dest / chip_id, dirs_exist_ok=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment