-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50fbdc2
commit 8af0232
Showing
5 changed files
with
116 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import json | ||
import os | ||
|
||
def load_metadata(metadata_path): | ||
if os.path.exists(metadata_path): | ||
with open(metadata_path, 'r') as f: | ||
metadata = json.load(f) | ||
return metadata | ||
else: | ||
return None | ||
|
||
def determine_additional_steps(old_params, new_params): | ||
""" | ||
Determines which additional steps need to be performed based on the difference | ||
between old and new run parameters. | ||
Returns: | ||
- reprocess_segmentation (bool): Whether segmentation needs to be reprocessed. | ||
- additional_steps (list): List of additional steps to perform. | ||
""" | ||
reprocess_segmentation = False | ||
additional_steps = [] | ||
|
||
# Parameters that affect the main segmentation process | ||
segmentation_params = ['sam_model_name', 'yolo_model_name', 'resize_mode', 'size', 'padding_color', 'interpolation'] | ||
|
||
# Check if any main segmentation parameters have changed | ||
for param in segmentation_params: | ||
old_value = old_params.get(param) | ||
new_value = new_params.get(param) | ||
if old_value != new_value: | ||
reprocess_segmentation = True | ||
break | ||
|
||
# Parameters for additional processing steps | ||
processing_flags = ['visualize_segmentation', 'crop_by_class', 'remove_crops_background', 'remove_full_background', 'background_color'] | ||
|
||
# Determine additional steps to perform | ||
for flag in processing_flags: | ||
old_value = old_params.get(flag, False) | ||
new_value = new_params.get(flag, False) | ||
if new_value and not old_value: | ||
additional_steps.append(flag) | ||
|
||
return reprocess_segmentation, additional_steps | ||
|
||
def update_metadata_run_parameters(metadata_path, new_params): | ||
with open(metadata_path, 'r') as f: | ||
metadata = json.load(f) | ||
|
||
metadata['run_parameters'].update(new_params) | ||
|
||
with open(metadata_path, 'w') as f: | ||
json.dump(metadata, f, indent=4) |
This file contains 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
This file contains 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