Rexnime

function - DWT/CWT and NN

Jun 1st, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.80 KB | None | 0 0
  1. % function helperCreateRGBfromTF(ads,datafolder_scallogram)
  2. %
  3. % for i = 1:length(ads.Files)
  4. %     clearvars sig
  5. %     Fs = 44100;
  6. %     sig = audioread(ads.Files{i});
  7. %    
  8. %    
  9. %     fb = cwtfilterbank('SignalLength',length(sig),...
  10. %     'SamplingFrequency',Fs,...
  11. %     'VoicesPerOctave',4);
  12. %     cfs = abs(fb.wt(sig(:)));
  13. %     im = ind2rgb(im2uint8(rescale(cfs)),jet(128));  
  14. %     imgLoc = fullfile(datafolder_scallogram,char(ads.Labels(i)));
  15. %     imFileName = strcat(char(ads.Labels(i)),'_',num2str(i),'.jpg');
  16. %     imwrite(imresize(im,[224 224]),fullfile(imgLoc,imFileName));
  17. % end
  18. % end
  19.  
  20. function helperCreateRGBfromTF(ads,datafolder_scallogram)
  21.  
  22. for i = 1:length(ads.Files)
  23.     clearvars sig
  24.    
  25.     level=2;
  26.     sig = audioread(ads.Files{i});
  27.     cfs = abs(wavedec(sig(:),level,'rbio2.8'));
  28.    
  29.     im = ind2rgb(im2uint8(rescale(cfs)),jet(128));  
  30.     imgLoc = fullfile(datafolder_scallogram,char(ads.Labels(i)));
  31.     imFileName = strcat(char(ads.Labels(i)),'_',num2str(i),'.jpg');
  32.     imwrite(imresize(im,[224 224]),fullfile(imgLoc,imFileName));
  33. end
  34. end
  35.  
  36.  
  37. % findLayersToReplace(lgraph) finds the single classification layer and the
  38. % preceding learnable (fully connected or convolutional) layer of the layer
  39. % graph lgraph.
  40.  
  41. function [learnableLayer,classLayer] = findLayersToReplace(lgraph)
  42.  
  43. if ~isa(lgraph,'nnet.cnn.LayerGraph')
  44.     error('Argument must be a LayerGraph object.')
  45. end
  46.  
  47. % Get source, destination, and layer names.
  48. src = string(lgraph.Connections.Source);
  49. dst = string(lgraph.Connections.Destination);
  50. layerNames = string({lgraph.Layers.Name}');
  51.  
  52. % Find the classification layer. The layer graph must have a single
  53. % classification layer.
  54. isClassificationLayer = arrayfun(@(l) ...
  55.     (isa(l,'nnet.cnn.layer.ClassificationOutputLayer')|isa(l,'nnet.layer.ClassificationLayer')), ...
  56.     lgraph.Layers);
  57.  
  58. if sum(isClassificationLayer) ~= 1
  59.     error('Layer graph must have a single classification layer.')
  60. end
  61. classLayer = lgraph.Layers(isClassificationLayer);
  62.  
  63.  
  64. % Traverse the layer graph in reverse starting from the classification
  65. % layer. If the network branches, throw an error.
  66. currentLayerIdx = find(isClassificationLayer);
  67. while true
  68.    
  69.     if numel(currentLayerIdx) ~= 1
  70.         error('Layer graph must have a single learnable layer preceding the classification layer.')
  71.     end
  72.    
  73.     currentLayerType = class(lgraph.Layers(currentLayerIdx));
  74.     isLearnableLayer = ismember(currentLayerType, ...
  75.         ['nnet.cnn.layer.FullyConnectedLayer','nnet.cnn.layer.Convolution2DLayer']);
  76.    
  77.     if isLearnableLayer
  78.         learnableLayer =  lgraph.Layers(currentLayerIdx);
  79.         return
  80.     end
  81.    
  82.     currentDstIdx = find(layerNames(currentLayerIdx) == dst);
  83.     currentLayerIdx = find(src(currentDstIdx) == layerNames);
  84.    
  85. end
  86. end
  87.  
Advertisement
Add Comment
Please, Sign In to add comment