-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_embeddings.m
47 lines (40 loc) · 1.31 KB
/
calculate_embeddings.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function success = calculate_embeddings(folder_name)
% Given the spectrogram, calculate the embedding for every time point
addpath(genpath(pwd))
%set up parameters
parameters = load_parameters(folder_name);
if parameters.TrackOnly
success = true;
return
end
load('reference_embedding.mat')
relevant_track_fields = {'Spectra'};
%% Load tracks
Tracks = load_single_folder(folder_name, relevant_track_fields);
if isempty(Tracks)
error('Empty Tracks');
end
try
parpool(feature('numcores'))
catch
%sometimes matlab attempts to write to the same temp file. wait and
%restart
pause(randi(60));
parpool(feature('numcores'))
end
data = vertcat(Tracks.Spectra);
[embeddingValues,~] = findEmbeddings(data,trainingSetData,trainingEmbedding,parameters);
clear data
% cut the embeddings
Tracks(1).Embeddings = []; %preallocate memory
start_index = 1;
for track_index = 1:length(Tracks)
end_index = start_index + size(Tracks(track_index).Spectra,1) - 1;
Tracks(track_index).Embeddings = embeddingValues(start_index:end_index, :);
start_index = end_index + 1;
end
delete(gcp('nocreate'))
%save
savetracks(Tracks, folder_name);
success = true;
end