File size: 2,091 Bytes
b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 b4123b8 dd1d7f5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
"""
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 |