soundata developer on retainer: dataset.track() raises AttributeError on UrbanSound8K — soundata uses clip API (dataset.clip()) for UrbanSound8K and track API for other datasets; multi-dataset SED pipeline calls wrong method; 8 732 urban sound clips never load — hasattr() entity-type check fix — 2 weeks — soundata developer on monthly retainer
soundata 0.2.0 • Python 3.9; dataset.clip(clip_id); dataset.clip_ids; clip.audio • Westfield Soundata Ltd. (Sound Event Detection model training pipeline; soundata 0.2.0; 3 datasets: UrbanSound8K 8,732 clips (10 urban sound classes), DCASE Task 4 2019 (track-based), TUT Urban Acoustic Scenes 2018 (track-based); UrbanSound8K uses clip API — dataset.clip(clip_id) and dataset.clip_ids; other datasets use track API; multi-dataset pipeline calls dataset.track(clip_id) on UrbanSound8K; AttributeError: 'Dataset' object has no attribute 'track'; exception handler logs “dataset load error” and continues; 8,732 clips never load; model never trains on urban sound classes; urban sound accuracy 0% at evaluation; fix: hasattr(dataset, 'clip_ids') entity-type check + dataset.clip() dispatch; 1.5h retainer engagement)
Westfield Soundata Ltd. built a multi-dataset Sound Event Detection (SED) training pipeline for an environmental audio monitoring system. The pipeline used soundata 0.2.0 to load audio and annotations from three research datasets: UrbanSound8K (8,732 labeled clips of urban sounds in 10 classes), DCASE Task 4 2019 (weakly-annotated and strongly-annotated SED data), and TUT Urban Acoustic Scenes 2018 (scene classification recordings). The data loading module iterated over entity IDs, accessed audio via the entity’s .audio property (which returns a (audio_data, sample_rate) tuple), extracted mel spectrogram features, and batched them for training. The module used dataset.track(entity_id) uniformly across all three datasets — a reasonable design choice for the two datasets the team had developed and tested against: DCASE Task 4 2019 and TUT-UAS 2018 both expose dataset.track() and dataset.track_ids, and both had been working correctly throughout development.
When UrbanSound8K was added to the training corpus, the pipeline began logging “dataset load error for clip {clip_id}” for every UrbanSound8K entity and moving on. soundata’s UrbanSound8K loader uses the clip entity type — the dataset exposes dataset.clip(clip_id) and dataset.clip_ids. The Dataset object for UrbanSound8K does not have a track() method; calling dataset.track(clip_id) on it immediately raises AttributeError: 'Dataset' object has no attribute 'track'. The training loop’s exception handler caught AttributeError (originally written to handle cases where specific annotation fields might be absent), logged the warning, and continued to the next entity. All 8,732 UrbanSound8K clips were silently skipped. The model trained successfully on DCASE and TUT-UAS data — loss curves converged normally — and the team did not notice that the UrbanSound8K portion of the corpus had contributed zero examples. Only when the trained model was evaluated on UrbanSound8K test data — and produced 0% accuracy on all 10 urban sound classes — did the team investigate. The AttributeError was reproduced in a one-line script: soundata.initialize('urbansound8k').track('100032-3-0-0') → AttributeError: 'Dataset' object has no attribute 'track'. The fix was confirmed in one line: soundata.initialize('urbansound8k').clip('100032-3-0-0').audio → (array([...], dtype=float32), 22050).
The annotated buggy and fixed multi-dataset soundata loading pipeline, with entity-type dispatch:
# Westfield Soundata Ltd. — soundata 0.2.0 clip vs track API dispatch
# soundata 0.2.0; Python 3.9; multi-dataset SED training pipeline
# Datasets: UrbanSound8K (clip-based), DCASE Task 4 2019 (track-based),
# TUT Urban Acoustic Scenes 2018 (track-based)
# Problem: UrbanSound8K uses dataset.clip(clip_id) + dataset.clip_ids
# DCASE / TUT-UAS use dataset.track(track_id) + dataset.track_ids
# Pipeline calls dataset.track() uniformly on all 3 datasets
# AttributeError: 'Dataset' object has no attribute 'track' on UrbanSound8K
# 8,732 clips silently skipped; model never trains on urban sound classes
# Urban sound accuracy: 0% at evaluation (2 weeks of wasted training)
# Fix: hasattr(dataset, 'clip_ids') dispatch before entity access
import numpy as np
import soundata
# ── BUGGY multi-dataset loader ────────────────────────────────────────────────
def load_dataset_entities_buggy(dataset_name: str,
data_home: str | None = None) -> list[tuple]:
"""
BUG: calls dataset.track() uniformly across all soundata datasets.
UrbanSound8K uses clip API — dataset.track() raises AttributeError.
AttributeError caught by generic handler; entity skipped silently.
8,732 UrbanSound8K clips return 'dataset load error'; contribute 0 training examples.
"""
dataset = soundata.initialize(dataset_name, data_home=data_home)
entities = []
for entity_id in dataset.track_ids: # BUG: UrbanSound8K has no track_ids attribute
try:
entity = dataset.track(entity_id) # BUG: AttributeError on UrbanSound8K
audio_data, sample_rate = entity.audio
if audio_data is not None:
entities.append((audio_data, sample_rate, entity_id))
except AttributeError:
# BUG: catches AttributeError from wrong API call, logs and silently skips
import logging
logging.warning(f"dataset load error for entity {entity_id}")
return entities
# ── FIXED multi-dataset loader ────────────────────────────────────────────────
def get_entity_ids(dataset) -> tuple[list[str], str]:
"""
Introspect a soundata Dataset to determine its entity type.
Returns (entity_ids, entity_type) where entity_type is 'clip' or 'track'.
soundata datasets use one of two entity models:
- Clip-based: dataset.clip_ids (list), dataset.clip(clip_id) → Clip
Examples: UrbanSound8K, FSD50K, BirdVox-DCASE-20k
- Track-based: dataset.track_ids (list), dataset.track(track_id) → Track
Examples: DCASE Task 4 2019, TUT Urban Acoustic Scenes 2018, GuitarSet
Use hasattr() to detect which model the dataset exposes.
"""
if hasattr(dataset, 'clip_ids'):
return dataset.clip_ids, 'clip'
elif hasattr(dataset, 'track_ids'):
return dataset.track_ids, 'track'
else:
raise ValueError(
f"soundata Dataset '{dataset.name}' exposes neither clip_ids nor track_ids. "
f"Check soundata docs for this dataset's entity model: "
f"dir(dataset) will show available attributes. "
f"Supported entity types in soundata 0.2.0: 'clip' and 'track'."
)
def get_entity(dataset, entity_id: str, entity_type: str):
"""
Access a soundata entity by ID using the correct accessor for the entity type.
entity_type must be the string returned by get_entity_ids().
"""
if entity_type == 'clip':
return dataset.clip(entity_id)
elif entity_type == 'track':
return dataset.track(entity_id)
else:
raise ValueError(f"Unknown entity type '{entity_type}'.")
def load_dataset_entities_fixed(dataset_name: str,
data_home: str | None = None) -> list[tuple]:
"""
FIX: introspect the dataset entity type before accessing entities.
1. Use hasattr(dataset, 'clip_ids') to detect clip-based datasets (UrbanSound8K).
2. Use hasattr(dataset, 'track_ids') to detect track-based datasets (DCASE, TUT).
3. Dispatch to dataset.clip(entity_id) or dataset.track(entity_id) accordingly.
4. Unpack entity.audio into (audio_data, sample_rate) explicitly.
5. Check for None audio_data (missing files) before feature extraction.
"""
import logging
dataset = soundata.initialize(dataset_name, data_home=data_home)
entity_ids, entity_type = get_entity_ids(dataset)
logging.info(
f"soundata: '{dataset_name}' uses {entity_type} API. "
f"{len(entity_ids)} {entity_type}s to load."
)
entities = []
for entity_id in entity_ids:
entity = get_entity(dataset, entity_id, entity_type)
audio_tuple = entity.audio
# entity.audio returns (audio_data, sample_rate) tuple.
# audio_data may be None if the audio file is missing from the dataset download.
# sample_rate may be None when audio_data is None.
if audio_tuple is None or audio_tuple[0] is None:
logging.warning(
f"soundata: audio is None for {entity_type} '{entity_id}' "
f"in dataset '{dataset_name}'. "
f"File may be missing — run dataset.download() or dataset.validate()."
)
continue
audio_data, sample_rate = audio_tuple
entities.append((audio_data, sample_rate, entity_id))
return entities
# ── Feature extraction helper (dataset-agnostic after entity dispatch) ────────
def extract_mel_spectrogram(audio_data: np.ndarray, sample_rate: int,
target_sr: int = 22050,
n_mels: int = 128) -> np.ndarray:
"""
Extract mel spectrogram from audio_data (numpy float32 array, sample_rate Hz).
Both clip.audio and track.audio return (audio_data, sample_rate) tuples;
after entity-type dispatch, feature extraction is identical for both.
Resamples to target_sr if sample_rate != target_sr.
"""
import librosa
if sample_rate != target_sr:
audio_data = librosa.resample(audio_data, orig_sr=sample_rate, target_sr=target_sr)
mel_spec = librosa.feature.melspectrogram(
y=audio_data, sr=target_sr, n_mels=n_mels
)
return librosa.power_to_db(mel_spec, ref=np.max)
if __name__ == '__main__':
# Verify entity types for all datasets in scope before running training.
for name in ['urbansound8k', 'dcase_task4_2019', 'tut_urban_acoustic_scenes_2018_mobile']:
try:
ds = soundata.initialize(name)
ids, etype = get_entity_ids(ds)
print(f" {name}: {etype} API, {len(ids)} {etype}s")
except Exception as exc:
print(f" {name}: ERROR — {exc}")
How soundata’s dataset-specific entity types, the clip vs track architectural distinction, and silent exception handling in multi-dataset pipelines interact — and the correct pattern for production multi-dataset SED loaders
soundata’s design reflects the semantic diversity of audio research datasets: ‘track’ and ‘clip’ are not interchangeable terms in the domain, and soundata chose to preserve the terminology that researchers already use to describe each dataset rather than imposing a single unified name. UrbanSound8K is a clip dataset — each of its 8,732 entities is a short, labeled sound excerpt (always under 4 seconds), not a continuous recording. The soundata UrbanSound8K loader accordingly exposes dataset.clip() and dataset.clip_ids. DCASE Task 4 2019 and TUT Urban Acoustic Scenes 2018 are track datasets — their entities are longer recordings with onset-offset event annotations or scene-level labels. These loaders expose dataset.track() and dataset.track_ids. A production multi-dataset pipeline must not assume that all soundata datasets share the same entity API — it must introspect each dataset at initialization time using hasattr() to determine which accessor to use. The hasattr(dataset, 'clip_ids') check is the standard idiom: if the attribute exists, the dataset is clip-based; if not, check hasattr(dataset, 'track_ids') for track-based datasets. The downstream feature extraction code is identical regardless of entity type: both clip.audio and track.audio return (audio_data, sample_rate) tuples where audio_data is a NumPy float32 array and sample_rate is an integer. This means the entity-type dispatch affects only the entity accessor call; all subsequent audio processing code can be shared. The root failure at Westfield Soundata Ltd. was not the AttributeError itself — it was the exception handler that treated AttributeError as a recoverable data issue rather than an API misuse that prevented an entire dataset from contributing any training examples. An AttributeError from dataset.track() on a clip-based dataset is not analogous to “this annotation field is optional and may not exist for this entity” — it means zero entities from the dataset will ever load. Exception handlers in multi-dataset training pipelines should distinguish between per-entity errors (which may be acceptable to log and skip) and per-dataset errors (which indicate a systematic problem that must halt the pipeline). The startup verification idiom — calling get_entity_ids() for each dataset before the training loop starts and printing the entity type and count — surfaces API mismatches at initialization rather than silently accumulating per-entity errors throughout training. The retainer engagement was 1.5h: 0.25h triage (0% urban sound accuracy at evaluation; “dataset load error” in training log for UrbanSound8K batches; AttributeError: 'Dataset' object has no attribute 'track' reproduced in one-line script); 0.5h root cause (soundata clip vs track architecture confirmed; UrbanSound8K Dataset confirmed clip-based via dir(soundata.initialize('urbansound8k')) showing clip_ids and clip() but no track_ids or track(); hasattr() dispatch pattern confirmed); 0.5h fix (entity-type dispatch logic implemented; tested against all 3 datasets; 8,732 UrbanSound8K clips load correctly); 0.25h validation (feature extraction completes for all datasets; training job runs with full corpus; 1.5h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- eyed3 developer on retainer — eyeD3 0.9.7; Python 3.9; podcast metadata normalization 60,000 MP3 episodes/month;
eyed3.load()returnsNonefor non-MP3 files;AudioFile.tagreturnsNonefor untagged MP3s;AttributeErrormasked; 7,600 episodes fail silently; fix: None-checks +initTag()— 3 weeks - acoustid developer on retainer — pyacoustid 1.3.0; Python 3.9; music fingerprinting 100,000 tracks/month;
fingerprint_file()callsfpcalcsubprocess;python:3.9-slimDocker base:fpcalcabsent;NoBackendErrormisread as network error; 0% success 3 weeks; fix:RUN apt-get install -y libchromaprint-tools— 1.5h - simpleaudio developer on retainer — simpleaudio 1.0.4; Python 3.9; factory safety alert system 50 alert types;
play_buffer()bytes_per_sample=4with float32 array; float32 IEEE 754 bit patterns reinterpreted as int32; loud buzzing static; fix:(audio*32767).astype(np.int16)withbytes_per_sample=2— 1.5h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →