fix: move SELVA_CATEGORIES to module level, harden append_to_tsv, fix tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -96,10 +96,15 @@ def build_annotation_tsv_path(folder: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def append_to_tsv(folder: str, clip_stem: str, label: str) -> None:
|
def append_to_tsv(folder: str, clip_stem: str, label: str) -> None:
|
||||||
"""Append one line to <folder>/dataset.tsv (creates file if absent)."""
|
"""Append one line to <folder>/dataset.tsv (creates file if absent).
|
||||||
if not label:
|
|
||||||
|
Format: ``{clip_stem}\\t{label}`` — matches VGGSound training TSV (2 columns).
|
||||||
|
Category is stored in the database only, not in the TSV.
|
||||||
|
"""
|
||||||
|
if not label.strip():
|
||||||
return
|
return
|
||||||
tsv_path = build_annotation_tsv_path(folder)
|
tsv_path = build_annotation_tsv_path(folder)
|
||||||
|
os.makedirs(folder, exist_ok=True)
|
||||||
with open(tsv_path, "a", encoding="utf-8") as f:
|
with open(tsv_path, "a", encoding="utf-8") as f:
|
||||||
f.write(f"{clip_stem}\t{label}\n")
|
f.write(f"{clip_stem}\t{label}\n")
|
||||||
|
|
||||||
@@ -144,6 +149,7 @@ _QUALITY_RE = re.compile(
|
|||||||
re.IGNORECASE,
|
re.IGNORECASE,
|
||||||
)
|
)
|
||||||
_SEP_RE = re.compile(r'[\s_\-\.]+')
|
_SEP_RE = re.compile(r'[\s_\-\.]+')
|
||||||
|
_SELVA_CATEGORIES = ["", "Human", "Animal", "Vehicle", "Tool", "Music", "Nature", "Sport", "Other"]
|
||||||
|
|
||||||
|
|
||||||
def _normalize_filename(filename: str) -> str:
|
def _normalize_filename(filename: str) -> str:
|
||||||
@@ -912,7 +918,6 @@ class MainWindow(QMainWindow):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self._cmb_category = QComboBox()
|
self._cmb_category = QComboBox()
|
||||||
_SELVA_CATEGORIES = ["", "Human", "Animal", "Vehicle", "Tool", "Music", "Nature", "Sport", "Other"]
|
|
||||||
self._cmb_category.addItems(_SELVA_CATEGORIES)
|
self._cmb_category.addItems(_SELVA_CATEGORIES)
|
||||||
saved_cat = self._settings.value("sound_category", "")
|
saved_cat = self._settings.value("sound_category", "")
|
||||||
cat_idx = self._cmb_category.findText(saved_cat)
|
cat_idx = self._cmb_category.findText(saved_cat)
|
||||||
@@ -999,7 +1004,7 @@ class MainWindow(QMainWindow):
|
|||||||
annotation_row = QHBoxLayout()
|
annotation_row = QHBoxLayout()
|
||||||
annotation_row.addWidget(QLabel("Label:"))
|
annotation_row.addWidget(QLabel("Label:"))
|
||||||
annotation_row.addWidget(self._txt_label)
|
annotation_row.addWidget(self._txt_label)
|
||||||
annotation_row.addWidget(QLabel("Cat:"))
|
annotation_row.addWidget(QLabel("Category:"))
|
||||||
annotation_row.addWidget(self._cmb_category)
|
annotation_row.addWidget(self._cmb_category)
|
||||||
annotation_row.addStretch()
|
annotation_row.addStretch()
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -266,8 +266,15 @@ def test_db_stores_label_and_category():
|
|||||||
try:
|
try:
|
||||||
db = ProcessedDB(path)
|
db = ProcessedDB(path)
|
||||||
db.add("video.mp4", 0.0, "/out/clip_001.mp4", label="dog barking", category="Animal")
|
db.add("video.mp4", 0.0, "/out/clip_001.mp4", label="dog barking", category="Animal")
|
||||||
markers = db.get_markers("video.mp4")
|
row = db._con.execute(
|
||||||
assert len(markers) == 1
|
"SELECT label, category FROM processed WHERE filename = ?", ("video.mp4",)
|
||||||
assert markers[0][0] == 0.0
|
).fetchone()
|
||||||
|
assert row == ("dog barking", "Animal")
|
||||||
finally:
|
finally:
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
|
||||||
|
def test_append_to_tsv_missing_folder_creates_it():
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
nested = os.path.join(d, "subdir", "deep")
|
||||||
|
append_to_tsv(nested, "clip_001", "dog barking")
|
||||||
|
assert os.path.exists(os.path.join(nested, "dataset.tsv"))
|
||||||
|
|||||||
Reference in New Issue
Block a user