|
|
""" |
|
|
Minimal configuration for the Sorghum Pipeline. |
|
|
""" |
|
|
|
|
|
import os |
|
|
from pathlib import Path |
|
|
from dataclasses import dataclass |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class Paths: |
|
|
"""Configuration for file paths.""" |
|
|
input_folder: str |
|
|
output_folder: str |
|
|
boundingbox_dir: str = "" |
|
|
|
|
|
def __post_init__(self): |
|
|
"""Ensure paths are absolute.""" |
|
|
self.input_folder = os.path.abspath(self.input_folder) |
|
|
self.output_folder = os.path.abspath(self.output_folder) |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class ProcessingParams: |
|
|
"""Minimal processing parameters.""" |
|
|
target_size: tuple = None |
|
|
min_component_area: int = 1000 |
|
|
morphology_kernel_size: int = 7 |
|
|
segmentation_threshold: float = 0.5 |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class OutputSettings: |
|
|
"""Output settings.""" |
|
|
save_images: bool = True |
|
|
save_plots: bool = False |
|
|
save_metadata: bool = False |
|
|
plot_dpi: int = 100 |
|
|
segmentation_dir: str = "results" |
|
|
texture_dir: str = "texture_output" |
|
|
morphology_dir: str = "results" |
|
|
vegetation_dir: str = "Vegetation_indices_images" |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class ModelSettings: |
|
|
"""Model settings.""" |
|
|
device: str = "auto" |
|
|
model_name: str = "briaai/RMBG-2.0" |
|
|
trust_remote_code: bool = True |
|
|
cache_dir: str = "" |
|
|
local_files_only: bool = False |
|
|
|
|
|
|
|
|
class Config: |
|
|
"""Minimal configuration class.""" |
|
|
|
|
|
def __init__(self): |
|
|
"""Initialize with defaults.""" |
|
|
self.paths = Paths(input_folder="", output_folder="", boundingbox_dir="") |
|
|
self.processing = ProcessingParams() |
|
|
self.output = OutputSettings() |
|
|
self.model = ModelSettings() |
|
|
|
|
|
def get_device(self) -> str: |
|
|
"""Get processing device.""" |
|
|
if self.model.device == "auto": |
|
|
import torch |
|
|
return "cuda" if torch.cuda.is_available() else "cpu" |
|
|
return self.model.device |
|
|
|
|
|
def validate(self) -> bool: |
|
|
"""Validate configuration.""" |
|
|
if self.paths.input_folder and not os.path.exists(self.paths.input_folder): |
|
|
raise FileNotFoundError(f"Input folder does not exist: {self.paths.input_folder}") |
|
|
return True |