mirror of
https://github.com/macaodha/batdetect2.git
synced 2026-05-22 22:32:18 +02:00
perf: defer heavy api imports
This commit is contained in:
parent
5526ac99fc
commit
d83f801515
@ -3,13 +3,12 @@ from __future__ import annotations
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Literal
|
from typing import TYPE_CHECKING, Literal
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
from soundevent import data
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
|
from soundevent import data
|
||||||
|
|
||||||
from batdetect2.audio import AudioConfig, AudioLoader
|
from batdetect2.audio import AudioConfig, AudioLoader
|
||||||
from batdetect2.data import Dataset
|
from batdetect2.data import Dataset
|
||||||
@ -313,6 +312,8 @@ class BatDetect2API:
|
|||||||
def get_top_class_name(self, detection: Detection) -> str:
|
def get_top_class_name(self, detection: Detection) -> str:
|
||||||
"""Get highest-confidence class name for one detection."""
|
"""Get highest-confidence class name for one detection."""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
top_index = int(np.argmax(detection.class_scores))
|
top_index = int(np.argmax(detection.class_scores))
|
||||||
return self.targets.class_names[top_index]
|
return self.targets.class_names[top_index]
|
||||||
|
|
||||||
@ -368,6 +369,8 @@ class BatDetect2API:
|
|||||||
batch_size: int | None = None,
|
batch_size: int | None = None,
|
||||||
detection_threshold: float | None = None,
|
detection_threshold: float | None = None,
|
||||||
) -> ClipDetections:
|
) -> ClipDetections:
|
||||||
|
from soundevent import data
|
||||||
|
|
||||||
from batdetect2.postprocess import ClipDetections
|
from batdetect2.postprocess import ClipDetections
|
||||||
|
|
||||||
recording = data.Recording.from_file(audio_file, compute_hash=False)
|
recording = data.Recording.from_file(audio_file, compute_hash=False)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user