Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/multi batch processing #127

Merged
merged 15 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/deepness/common/config_entry_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ConfigEntryKey(enum.Enum):
PROCESSED_AREA_TYPE = enum.auto(), '' # string of ProcessedAreaType, e.g. "ProcessedAreaType.VISIBLE_PART.value"
MODEL_TYPE = enum.auto(), '' # string of ModelType enum, e.g. "ModelType.SEGMENTATION.value"
PREPROCESSING_RESOLUTION = enum.auto(), 3.0
MODEL_BATCH_SIZE = enum.auto(), 1
PROCESS_LOCAL_CACHE = enum.auto(), False
PREPROCESSING_TILES_OVERLAP = enum.auto(), 15

SEGMENTATION_PROBABILITY_THRESHOLD_ENABLED = enum.auto(), True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class MapProcessingParameters:
resolution_cm_per_px: float # image resolution to used during processing
processed_area_type: ProcessedAreaType # whether to perform operation on the entire field or part
tile_size_px: int # Tile size for processing (model input size)
batch_size: int # Batch size for processing
local_cache: bool # Whether to use local cache for tiles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding in comment it is caching on disk?


input_layer_id: str # raster layer to process
mask_layer_id: Optional[str] # Processing of masked layer - if processed_area_type is FROM_POLYGONS
Expand Down
19 changes: 19 additions & 0 deletions src/deepness/common/temp_files_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os.path as path
import shutil
from tempfile import mkdtemp


class TempFilesHandler:
def __init__(self) -> None:
self._temp_dir = mkdtemp()

print(f'Created temp dir: {self._temp_dir} for processing')

def get_results_img_path(self):
return path.join(self._temp_dir, 'results.dat')

def get_area_mask_img_path(self):
return path.join(self._temp_dir, 'area_mask.dat')

def __del__(self):
shutil.rmtree(self._temp_dir)
27 changes: 22 additions & 5 deletions src/deepness/deepness_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ def _load_ui_from_config(self):

# needs to be loaded after the model is set up
self.comboBox_outputFormatClassNumber.setCurrentIndex(ConfigEntryKey.MODEL_OUTPUT_FORMAT_CLASS_NUMBER.get())

self.doubleSpinBox_resolution_cm_px.setValue(ConfigEntryKey.PREPROCESSING_RESOLUTION.get())
self.spinBox_batchSize.setValue(ConfigEntryKey.MODEL_BATCH_SIZE.get())
self.checkBox_local_cache.setChecked(ConfigEntryKey.PROCESS_LOCAL_CACHE.get())
self.spinBox_processingTileOverlapPercentage.setValue(ConfigEntryKey.PREPROCESSING_TILES_OVERLAP.get())

self.doubleSpinBox_probabilityThreshold.setValue(
Expand Down Expand Up @@ -129,6 +130,8 @@ def _save_ui_to_config(self):
ConfigEntryKey.MODEL_OUTPUT_FORMAT_CLASS_NUMBER.set(self.comboBox_outputFormatClassNumber.currentIndex())

ConfigEntryKey.PREPROCESSING_RESOLUTION.set(self.doubleSpinBox_resolution_cm_px.value())
ConfigEntryKey.MODEL_BATCH_SIZE.set(self.spinBox_batchSize.value())
ConfigEntryKey.PROCESS_LOCAL_CACHE.set(self.checkBox_local_cache.isChecked())
ConfigEntryKey.PREPROCESSING_TILES_OVERLAP.set(self.spinBox_processingTileOverlapPercentage.value())

ConfigEntryKey.SEGMENTATION_PROBABILITY_THRESHOLD_ENABLED.set(
Expand Down Expand Up @@ -225,10 +228,10 @@ def _model_type_changed(self):
else:
raise Exception(f"Unsupported model type ({model_type})!")

self.mGroupBox_segmentationParameters.setEnabled(segmentation_enabled)
self.mGroupBox_detectionParameters.setEnabled(detection_enabled)
self.mGroupBox_regressionParameters.setEnabled(regression_enabled)
self.mGroupBox_superresolutionParameters.setEnabled(superresolution_enabled)
self.mGroupBox_segmentationParameters.setVisible(segmentation_enabled)
self.mGroupBox_detectionParameters.setVisible(detection_enabled)
self.mGroupBox_regressionParameters.setVisible(regression_enabled)
self.mGroupBox_superresolutionParameters.setVisible(superresolution_enabled)
# Disable output format options for super-resolution models.
self.mGroupBox_6.setEnabled(not superresolution_enabled)

Expand Down Expand Up @@ -272,6 +275,11 @@ def _load_default_model_parameters(self):
value = self._model.get_metadata_resolution()
if value is not None:
self.doubleSpinBox_resolution_cm_px.setValue(value)

value = self._model.get_model_batch_size()
if value is not None:
self.spinBox_batchSize.setValue(value)
self.spinBox_batchSize.setEnabled(False)

value = self._model.get_metadata_tile_size()
if value is not None:
Expand Down Expand Up @@ -355,10 +363,16 @@ def _load_model_and_display_info(self, abort_if_no_file_path: bool = False):
input_0_shape = self._model.get_input_shape()
txt += f'Input shape: {input_0_shape} = [BATCH_SIZE * CHANNELS * SIZE * SIZE]'
input_size_px = input_0_shape[-1]
batch_size = self._model.get_model_batch_size()

# TODO idk how variable input will be handled
self.spinBox_tileSize_px.setValue(input_size_px)
self.spinBox_tileSize_px.setEnabled(False)

if batch_size is not None:
self.spinBox_batchSize.setValue(batch_size)
self.spinBox_batchSize.setEnabled(False)

self._input_channels_mapping_widget.set_model(self._model)

# super resolution
Expand All @@ -375,6 +389,7 @@ def _load_model_and_display_info(self, abort_if_no_file_path: bool = False):
"Model may be not usable."
logging.exception(txt)
self.spinBox_tileSize_px.setEnabled(True)
self.spinBox_batchSize.setEnabled(True)
length_limit = 300
exception_msg = (str(e)[:length_limit] + '..') if len(str(e)) > length_limit else str(e)
msg = txt + f'\n\nException: {exception_msg}'
Expand Down Expand Up @@ -517,6 +532,8 @@ def _get_map_processing_parameters(self) -> MapProcessingParameters:
params = MapProcessingParameters(
resolution_cm_per_px=self.doubleSpinBox_resolution_cm_px.value(),
tile_size_px=self.spinBox_tileSize_px.value(),
batch_size=self.spinBox_batchSize.value(),
local_cache=self.checkBox_local_cache.isChecked(),
processed_area_type=processed_area_type,
mask_layer_id=self.get_mask_layer_id(),
input_layer_id=self._get_input_layer_id(),
Expand Down
Loading