Source code for deeptrees

import importlib
from typing import TYPE_CHECKING, Any

__version__ = "v1.6.0"

if TYPE_CHECKING:
    from . import dataloading, model, modules
    from .inference import TreeCrownPredictor
    from .model.deeptrees_model import TreeCrownDelineationModel
    from .pretrained import freudenberg2022

__all__ = [
    "__version__",
    "TreeCrownDelineationModel",
    "TreeCrownPredictor",
    "dataloading",
    "freudenberg2022",
    "model",
    "modules",
    "predict",
]


def __getattr__(name: str) -> Any:
    if name in {"model", "modules", "dataloading"}:
        module = importlib.import_module(f".{name}", __name__)
        globals()[name] = module
        return module

    if name == "TreeCrownDelineationModel":
        from .model.deeptrees_model import TreeCrownDelineationModel as model_cls

        globals()[name] = model_cls
        return model_cls

    if name == "TreeCrownPredictor":
        from .inference import TreeCrownPredictor as predictor_cls

        globals()[name] = predictor_cls
        return predictor_cls

    if name == "freudenberg2022":
        from .pretrained import freudenberg2022 as pretrained_model

        globals()[name] = pretrained_model
        return pretrained_model

    raise AttributeError(f"module '{__name__}' has no attribute '{name}'")


[docs] def predict(image_path: list[str], config_path: str): """ Run tree crown delineation prediction on the provided image paths using the given configuration. Args: image_path (list[str]): A list of file paths to the images to be processed. config_path (str): The file path to the configuration file for the prediction. Returns: None: This function does not return any value. It performs the prediction in-place. """ from .inference import TreeCrownPredictor predictor = TreeCrownPredictor(image_path=image_path, config_path=config_path) # Uses default config path and name predictor.predict()