changeset 34:115774aff442 branch-tests

music bounds not centered but aligned with start of segment to match the way features are computed
author Maria Panteli
date Thu, 14 Sep 2017 10:16:59 +0100
parents 928d9bf9224f
children c4428589b82b
files scripts/load_features.py tests/test_load_features.py
diffstat 2 files changed, 22 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/load_features.py	Wed Sep 13 20:04:09 2017 +0100
+++ b/scripts/load_features.py	Thu Sep 14 10:16:59 2017 +0100
@@ -76,13 +76,16 @@
             # all segments are speech
             return music_idx
         else:
-            half_win_hop = int(round(0.5 * self.win2 / float(self.hop2)))
+            win2_frames = np.int(np.round(self.win2sec * self.framessr2))
+            #half_win_hop = int(round(0.5 * self.win2 / float(self.hop2)))
             music_bounds = np.where(bounds[:, 2] == 'm')[0]
             bounds_in_frames = np.round(np.array(bounds[:, 0], dtype=float) * sr)
-            duration_in_frames = np.round(np.array(bounds[:, 1], dtype=float) * sr)
+            duration_in_frames = np.ceil(np.array(bounds[:, 1], dtype=float) * sr)
             for music_bound in music_bounds:
-                lower_bound = np.max([0, bounds_in_frames[music_bound] - half_win_hop])
-                upper_bound = bounds_in_frames[music_bound] + duration_in_frames[music_bound] - half_win_hop
+                #lower_bound = np.max([0, bounds_in_frames[music_bound] - half_win_hop])
+                #upper_bound = bounds_in_frames[music_bound] + duration_in_frames[music_bound] - half_win_hop
+                lower_bound = bounds_in_frames[music_bound]
+                upper_bound = bounds_in_frames[music_bound] + duration_in_frames[music_bound] - win2_frames
                 music_idx.append(np.arange(lower_bound, upper_bound, dtype=int))
             if len(music_idx)>0:
                 music_idx = np.sort(np.concatenate(music_idx))  # it should be sorted, but just in case segments overlap -- remove duplicates if segments overlap
--- a/tests/test_load_features.py	Wed Sep 13 20:04:09 2017 +0100
+++ b/tests/test_load_features.py	Thu Sep 14 10:16:59 2017 +0100
@@ -19,14 +19,15 @@
     sr = feat_loader.framessr2            
     music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
     # upper bound minus half window size
-    half_win_sec = 4.0  # assume 8-second window
-    music_bounds_true = np.arange(np.round(sr * (np.float(bounds[-1, 1]) - half_win_sec)), dtype=int)
+    #half_win_sec = 4.0  # assume 8-second window
+    win_sec = 8
+    music_bounds_true = np.arange(np.round(sr * (np.float(bounds[-1, 1]) - win_sec)), dtype=int)
     assert np.array_equal(music_bounds, music_bounds_true)
     
     
 def test_get_music_idx_from_bounds_short_segment():
     # anything less than half window size is not processed
-    bounds = np.array([['0', '3.8', 'm']])
+    bounds = np.array([['0', '7.9', 'm']])
     sr = feat_loader.framessr2
     music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
     music_bounds_true = np.array([])
@@ -34,8 +35,8 @@
 
 
 def test_get_music_idx_from_bounds_single_frame():
-    bounds = np.array([['0', '4.3', 'm']])
-    sr = feat_loader.framessr2         
+    bounds = np.array([['0', '8.1', 'm']])
+    sr = feat_loader.framessr2
     music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
     music_bounds_true = np.array([0])
     assert np.array_equal(music_bounds, music_bounds_true)
@@ -47,10 +48,11 @@
               ['13.5', '5.0', 'm']])
     sr = feat_loader.framessr2
     music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
-    half_win_sec = 4.0  # assume 8-second window
-    music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - half_win_sec)), dtype=int),
-                                        np.arange(np.round(sr * (13.5 - half_win_sec)), 
-                                            np.round(sr * (18.5 - half_win_sec)), dtype=int)])
+    #half_win_sec = 4.0  # assume 8-second window
+    win_sec = 8.0  # assume 8-second window
+    music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - win_sec)), dtype=int),
+                                        np.arange(np.round(sr * 13.5), 
+                                            np.round(sr * (18.5 - win_sec)), dtype=int)])
     assert np.array_equal(music_bounds, music_bounds_true)
     
 
@@ -61,9 +63,10 @@
     sr = feat_loader.framessr2
     music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
     half_win_sec = 4.0  # assume 8-second window
-    music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - half_win_sec)), dtype=int),
-                                        np.arange(np.round(sr * (11.5 - half_win_sec)), 
-                                            np.round(sr * (16.5 - half_win_sec)), dtype=int)])
+    win_sec = 8.0  # assume 8-second window
+    music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - win_sec)), dtype=int),
+                                        np.arange(np.round(sr * 11.5), 
+                                            np.round(sr * (16.5 - win_sec)), dtype=int)])
     assert np.array_equal(music_bounds, music_bounds_true)