-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnormalDevelopment.m
More file actions
87 lines (65 loc) · 3.61 KB
/
normalDevelopment.m
File metadata and controls
87 lines (65 loc) · 3.61 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
% USVlegend is saved in USVmetadataC1-9.at
% lets take just the males, and just between P4 to P10
% this is hardcoded for now, but suffice to say its going to be 600 msec
% images from 15 khz to 90 khz
runSess=USVlegend(lower(USVlegend.Sex)=='m',:);
callFolder='E:\Brandeis datasets\FMR1 Project Data\USV data\segData';
%runSess=USVlegend(USVlegend.age>10,:);
allcalls=[]; allCalldurs=[];
wb=waitbar(0,'concatenating animal images');
% what percentage of images will we need to classify these guys????
% probably like half
bigclock=tic;
for i=1:height(runSess)
load(fullfile(callFolder,runSess.name(i)),'blobs','segCalls','params','spect');
okfreqs=params.fvec>15000 & params.fvec<90000;
badcalls=segCalls.onsetTime<5 | segCalls.offsetTime>min([180 size(blobs,2)*params.timestep])-5;
segCalls=segCalls(~badcalls,:);
mycalls=nan(128,128,1,height(segCalls));
callcenters=mean(table2array(segCalls(:,1:2)),2);
centerinds=interp1(params.tvec,1:length(params.tvec),callcenters,'nearest');
calldurs=(segCalls.offsetTime-segCalls.onsetTime)/params.timestep;
for j=1:length(callcenters)
% go forward 200 msec, and forward 200 msec, then resize to 256
% were going from many to 128x128 x 1 images- this is the bw
%mycalls(:,:,:,j)=imresize(blobs(okfreqs,(centerinds(j)-round(calldurs(j)/1.9)):(centerinds(j)+round(calldurs(j)/1.9))),[128,128]);
% or use the actual image, which may be better...
mycalls(:,:,:,j)=imresize(spect(okfreqs,(centerinds(j)-round(calldurs(j)/1.9)):(centerinds(j)+round(calldurs(j)/1.9))),[128,128]);
% or use both! but you'll have to edit here!
%mycalls(:,:,1,j)=imresize(blobs(okfreqs,(centerinds(j)-round(calldurs(j)/1.9)):(centerinds(j)+round(calldurs(j)/1.9))),[128,128]);
%mycalls(:,:,2,j)=imresize(spect(okfreqs,(centerinds(j)-round(calldurs(j)/1.9)):(centerinds(j)+round(calldurs(j)/1.9))),[128,128]);
end
allCalldurs=[allCalldurs; [calldurs ones(size(calldurs,1),1)*i (1:length(calldurs))']]; % add call duration, then the sessnum and callnum
allcalls=cat(4,allcalls,mycalls);
waitbar(i/height(runSess),wb,sprintf('Has taken %d mins, will prolly go %d more mins',...
round(toc(bigclock)/60),round(toc(bigclock)/i*(height(runSess)-i)/60)));
end
close(wb);
allCallinfo=table(allCalldurs(:,2),allCalldurs(:,3),'VariableNames',...
{'sessionNumber','call number'});
for i=1:height(allCallinfo)
allCallinfo.Age(i)=runSess.age(allCallinfo.sessionNumber(i));
allCallinfo.Sex(i)=runSess.Sex(allCallinfo.sessionNumber(i));
allCallinfo.Cohort(i)=runSess.Cohort(allCallinfo.sessionNumber(i));
allCallinfo.Rat(i)=runSess.ratname(allCallinfo.sessionNumber(i));
allCallinfo.Genotype(i)=runSess.Genotype(allCallinfo.sessionNumber(i));
end
save('AllCallImages_Male_20220318','runSess','allCallinfo','allcalls','-v7.3')
%%
% this is all images for all sessions:
load('E:\Brandeis datasets\FMR1 Project Data\USV data\AllCallImages_Male_20220318');
testimages=allcalls(:,:,:,randi(size(allcalls,4),10));
figure; imagesc(imtile(testimages))
[data] = run_VAE_encoder(encoderNet,allcalls);
%%
% use create_tsne callback to generate this code
%edit generate_VAE_encoder
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% USE [encoderNet,decoderNet,data] = generate_VAE_encoder(imageStack)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% now run the encoder decoder...
% Load the network model
% then yu can run tsne or umap on this and cluster
% first will need to pull a random set of usvs to generate our model. This
% is throttled by the size of the gpu i guess...
edit callsAutoencoder.m