From 854b9766277a1c3599bf99d3136598f8f8b5e4aa Mon Sep 17 00:00:00 2001 From: vorozhkog Date: Fri, 13 Sep 2024 14:56:43 +0100 Subject: [PATCH] fix num and percentage splits --- src/compute/layers/processing/SplitDataLayer.py | 6 ++++-- .../actions/other/split_data/layout/split_data_sidebar.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/compute/layers/processing/SplitDataLayer.py b/src/compute/layers/processing/SplitDataLayer.py index 7c5fe4c4..bc4c1059 100644 --- a/src/compute/layers/processing/SplitDataLayer.py +++ b/src/compute/layers/processing/SplitDataLayer.py @@ -50,7 +50,8 @@ def process(self, data_el: Tuple[ImageDescriptor, Annotation]): def _split_by_percent() -> List[Tuple[ImageDescriptor, Annotation]]: new_item_desc = deepcopy(item_desc) split_ratio = self.settings.get("split_ratio", 0.8) - split_index = int(item_idx / (total_items_cnt * split_ratio)) + split_num = total_items_cnt * split_ratio + split_index = int(item_idx / split_num) + (item_idx % split_num > 0) dataset = f"split_{split_index}" new_item_desc.res_ds_name = dataset return [(new_item_desc, ann)] @@ -58,7 +59,8 @@ def _split_by_percent() -> List[Tuple[ImageDescriptor, Annotation]]: def _split_by_num() -> List[Tuple[ImageDescriptor, Annotation]]: new_item_desc = deepcopy(item_desc) split_num = self.settings.get("split_num", total_items_cnt // 2) - split_index = int(item_idx / split_num) + split_index = int(item_idx / split_num) + (item_idx % split_num > 0) + print(f"ITEM INDEX: {item_idx}, SPLIT INDEX: {split_index}") dataset = f"split_{split_index}" new_item_desc.res_ds_name = dataset return [(new_item_desc, ann)] diff --git a/src/ui/dtl/actions/other/split_data/layout/split_data_sidebar.py b/src/ui/dtl/actions/other/split_data/layout/split_data_sidebar.py index fa9dc8d5..fe7603a0 100644 --- a/src/ui/dtl/actions/other/split_data/layout/split_data_sidebar.py +++ b/src/ui/dtl/actions/other/split_data/layout/split_data_sidebar.py @@ -12,7 +12,9 @@ def create_sidebar_widgets(): # Sidebar Initialization widgets - sidebar_percent_slider = Slider(show_input=True, show_input_controls=True, min=1) + sidebar_percent_slider = Slider( + show_input=True, show_input_controls=True, min=0.01, max=1, step=0.01 + ) sidebar_percent_field = Field( sidebar_percent_slider, "Select percentage",