mirror of
https://github.com/macaodha/batdetect2.git
synced 2026-05-22 22:32:18 +02:00
Fix logging imports
This commit is contained in:
parent
da113eaea8
commit
4303d4e42d
@ -2,10 +2,6 @@
|
||||
|
||||
import click
|
||||
|
||||
from batdetect2.logging import enable_logging
|
||||
|
||||
# from batdetect2.cli.ascii import BATDETECT_ASCII_ART
|
||||
|
||||
__all__ = [
|
||||
"cli",
|
||||
]
|
||||
@ -34,5 +30,7 @@ def cli(verbose: int = 0):
|
||||
"""
|
||||
click.echo(INFO_STR)
|
||||
|
||||
from batdetect2.logging import enable_logging
|
||||
|
||||
enable_logging(verbose)
|
||||
# click.echo(BATDETECT_ASCII_ART)
|
||||
|
||||
@ -4,8 +4,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
import click
|
||||
from loguru import logger
|
||||
from soundevent import io
|
||||
from soundevent.audio.files import get_audio_files
|
||||
|
||||
from batdetect2.cli.base import cli
|
||||
|
||||
@ -219,6 +217,8 @@ def predict_directory_command(
|
||||
Loads a checkpoint, scans `audio_dir` for supported audio files, runs
|
||||
inference, and saves predictions to `output_path`.
|
||||
"""
|
||||
from soundevent.audio.files import get_audio_files
|
||||
|
||||
audio_files = list(get_audio_files(audio_dir))
|
||||
_run_prediction(
|
||||
model_path=model_path,
|
||||
@ -309,6 +309,8 @@ def predict_dataset_command(
|
||||
The dataset is read as a soundevent annotation set and unique recording
|
||||
paths are extracted before inference.
|
||||
"""
|
||||
from soundevent import io
|
||||
|
||||
dataset_path = Path(dataset_path)
|
||||
dataset = io.load(dataset_path, type="annotation_set")
|
||||
audio_files = sorted(
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import sys
|
||||
from collections.abc import Callable
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Annotated,
|
||||
Any,
|
||||
Dict,
|
||||
@ -13,21 +16,23 @@ from typing import (
|
||||
TypeVar,
|
||||
)
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from lightning.pytorch.loggers import (
|
||||
CSVLogger,
|
||||
Logger,
|
||||
MLFlowLogger,
|
||||
TensorBoardLogger,
|
||||
)
|
||||
from loguru import logger
|
||||
from matplotlib.figure import Figure
|
||||
from pydantic import Field
|
||||
from soundevent import data
|
||||
|
||||
from batdetect2.core.configs import BaseConfig
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from lightning.pytorch.loggers import (
|
||||
CSVLogger,
|
||||
Logger,
|
||||
MLFlowLogger,
|
||||
TensorBoardLogger,
|
||||
)
|
||||
from matplotlib.figure import Figure
|
||||
from soundevent import data
|
||||
|
||||
DEFAULT_LOGS_DIR: Path = Path("outputs") / "logs"
|
||||
|
||||
__all__ = [
|
||||
@ -271,10 +276,16 @@ def build_logger(
|
||||
)
|
||||
|
||||
|
||||
PlotLogger = Callable[[str, Figure, int], None]
|
||||
PlotLogger = Callable[[str, "Figure", int], None]
|
||||
|
||||
|
||||
def get_image_logger(logger: Logger) -> PlotLogger | None:
|
||||
from lightning.pytorch.loggers import (
|
||||
CSVLogger,
|
||||
MLFlowLogger,
|
||||
TensorBoardLogger,
|
||||
)
|
||||
|
||||
if isinstance(logger, TensorBoardLogger):
|
||||
return logger.experiment.add_figure
|
||||
|
||||
@ -296,10 +307,16 @@ def get_image_logger(logger: Logger) -> PlotLogger | None:
|
||||
return partial(save_figure, dir=Path(logger.log_dir))
|
||||
|
||||
|
||||
TableLogger = Callable[[str, pd.DataFrame, int], None]
|
||||
TableLogger = Callable[[str, "pd.DataFrame", int], None]
|
||||
|
||||
|
||||
def get_table_logger(logger: Logger) -> TableLogger | None:
|
||||
from lightning.pytorch.loggers import (
|
||||
CSVLogger,
|
||||
MLFlowLogger,
|
||||
TensorBoardLogger,
|
||||
)
|
||||
|
||||
if isinstance(logger, TensorBoardLogger):
|
||||
return partial(save_table, dir=Path(logger.log_dir))
|
||||
|
||||
@ -337,6 +354,8 @@ def save_figure(name: str, fig: Figure, step: int, dir: Path) -> None:
|
||||
|
||||
|
||||
def _convert_figure_to_array(figure: Figure) -> np.ndarray:
|
||||
import numpy as np
|
||||
|
||||
with io.BytesIO() as buff:
|
||||
figure.savefig(buff, format="raw")
|
||||
buff.seek(0)
|
||||
|
||||
@ -15,11 +15,11 @@ GENERIC_CLASS_KEY = "class"
|
||||
|
||||
|
||||
data_source = data.Term(
|
||||
name="soundevent:data_source",
|
||||
label="Data Source",
|
||||
name="dcterms:source",
|
||||
label="Source",
|
||||
uri="http://purl.org/dc/terms/source",
|
||||
definition=(
|
||||
"A unique identifier for the source of the data, typically "
|
||||
"representing the project, site, or deployment context."
|
||||
"A related resource from which the described resource is derived."
|
||||
),
|
||||
)
|
||||
|
||||
@ -45,6 +45,17 @@ individual = data.Term(
|
||||
)
|
||||
"""Term used for tags identifying a specific individual animal."""
|
||||
|
||||
dataset_split = data.Term(
|
||||
name="batdetect2:split",
|
||||
label="Dataset Split",
|
||||
definition=(
|
||||
"Identifies the specific data partition (e.g., 'train', 'test') "
|
||||
"that the item belongs to within an experimental setup. "
|
||||
"The expected value is a literal text string."
|
||||
),
|
||||
)
|
||||
"""Custom metadata term defining the machine learning partition of an item."""
|
||||
|
||||
generic_class = data.Term(
|
||||
name="soundevent:class",
|
||||
label="Class",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user