Update map_to_hear.py
Browse files- map_to_hear.py +3 -29
map_to_hear.py
CHANGED
|
@@ -40,7 +40,7 @@ def process_csv(csv_path):
|
|
| 40 |
assert path.exists(), f"CSV Path {csv_path} does not exist"
|
| 41 |
|
| 42 |
# Load all rows from CSV and group by label (ignoring source)
|
| 43 |
-
|
| 44 |
with open(path, newline='') as csvfile:
|
| 45 |
reader = csv_module.reader(csvfile, delimiter=',')
|
| 46 |
for row in reader:
|
|
@@ -48,37 +48,11 @@ def process_csv(csv_path):
|
|
| 48 |
frame_idx = int(row[0])
|
| 49 |
class_idx = int(row[1])
|
| 50 |
label = LABEL_MAPPING[str(class_idx)]
|
| 51 |
-
label_frames.setdefault(label, set()).add(frame_idx)
|
| 52 |
-
|
| 53 |
-
if not label_frames:
|
| 54 |
-
return []
|
| 55 |
-
|
| 56 |
-
# Convert to time-based events for each label
|
| 57 |
-
data = []
|
| 58 |
-
for label, frames in label_frames.items():
|
| 59 |
-
frames = sorted(frames)
|
| 60 |
-
|
| 61 |
-
# Group consecutive frames into events
|
| 62 |
-
start_frame = frames[0]
|
| 63 |
-
prev_frame = frames[0]
|
| 64 |
-
|
| 65 |
-
for frame in frames[1:]:
|
| 66 |
-
if frame - prev_frame > 1: # Gap detected, end current event
|
| 67 |
data.append({
|
| 68 |
"label": label,
|
| 69 |
-
"start": float(
|
| 70 |
-
"end": float((
|
| 71 |
})
|
| 72 |
-
start_frame = frame
|
| 73 |
-
prev_frame = frame
|
| 74 |
-
|
| 75 |
-
# Add the final event
|
| 76 |
-
data.append({
|
| 77 |
-
"label": label,
|
| 78 |
-
"start": float(start_frame * ANNOTATION_FREQ),
|
| 79 |
-
"end": float((prev_frame + 1) * ANNOTATION_FREQ)
|
| 80 |
-
})
|
| 81 |
-
|
| 82 |
return data
|
| 83 |
|
| 84 |
def map_to_splits(audios, fold_to_split):
|
|
|
|
| 40 |
assert path.exists(), f"CSV Path {csv_path} does not exist"
|
| 41 |
|
| 42 |
# Load all rows from CSV and group by label (ignoring source)
|
| 43 |
+
data = []
|
| 44 |
with open(path, newline='') as csvfile:
|
| 45 |
reader = csv_module.reader(csvfile, delimiter=',')
|
| 46 |
for row in reader:
|
|
|
|
| 48 |
frame_idx = int(row[0])
|
| 49 |
class_idx = int(row[1])
|
| 50 |
label = LABEL_MAPPING[str(class_idx)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
data.append({
|
| 52 |
"label": label,
|
| 53 |
+
"start": float(frame_idx * ANNOTATION_FREQ),
|
| 54 |
+
"end": float((frame_idx + 1) * ANNOTATION_FREQ)
|
| 55 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
return data
|
| 57 |
|
| 58 |
def map_to_splits(audios, fold_to_split):
|