### Initialize DeepSqueak Source: https://context7.com/drcoffey/deepsqueak/llms.txt Launch the DeepSqueak application by navigating to the installation directory and calling the main function. ```matlab % Navigate to the DeepSqueak folder and launch the application cd('/path/to/DeepSqueak') DeepSqueak % DeepSqueak automatically adds itself to MATLAB path % Required MATLAB version: 2020a or later % Required toolboxes: % - Deep Learning Toolbox % - Computer Vision System Toolbox % - Image Processing Toolbox % - Curve Fitting Toolbox % - Signal Processing Toolbox % - Parallel Computing Toolbox % - Statistics and Machine Learning Toolbox ``` -------------------------------- ### Example Label File Content Source: https://github.com/drcoffey/deepsqueak/blob/master/Scripts/Readme.md Format for tab-separated value files containing call timestamps and labels. ```text 0.1234 0.5678 call 1.2345 1.6789 call ``` -------------------------------- ### Example DeepSqueak JSON Output Source: https://github.com/drcoffey/deepsqueak/blob/master/Scripts/Readme.md This JSON file represents the structure of DeepSqueak's output, containing audio metadata and detected call information. Ensure that the 'Calls' properties like 'Box', 'Score', 'Type', and 'Accept' have matching lengths. ```JSON { "audiodata": { "Filename": "..\\Annotated audio files\\example\\audio.wav", "CompressionMethod": "NONE", "NumChannels": 2, "SampleRate": 48000, "TotalSamples": 140393039, "Duration": 2924.8549791666665, "Title": "audio.wav", "Comment": "", "Artist": "", "BitsPerSample": 16 }, "Calls": { "Box": [ [ 1801.644187, 0.0, 0.14722299999993993, 60.0 ], [ 1801.79141, 0.0, 0.2024309999999332, 60.0 ] ], "Score": [ 1.0, 1.0 ], "Type": [ "Call", "Call" ], "Accept": [ true, true ] } } ``` -------------------------------- ### DeepSqueak Initialization Source: https://context7.com/drcoffey/deepsqueak/llms.txt The main entry point for launching the DeepSqueak GUI and initializing the environment. ```APIDOC ## DeepSqueak Initialization ### Description Initializes the DeepSqueak GUI, loads necessary settings, verifies required MATLAB toolboxes, and sets up the visualization environment. ### Usage ```matlab cd('/path/to/DeepSqueak') DeepSqueak ``` ``` -------------------------------- ### Manage Application State with squeakData Source: https://context7.com/drcoffey/deepsqueak/llms.txt Use the squeakData handle class to manage detection results, audio metadata, and user configuration settings. ```matlab classdef squeakData < handle properties calls % Table of detected calls currentcall % Index of currently selected call audiodata % Audio file metadata settings % User preferences and detection parameters focusCenter % Current position in focus window (seconds) pageSizes % Available page view durations [2, 3, 5, 10, 30] focusSizes % Available focus window sizes [.25, .5, 1, 2, 5] end end % Example: Create data object and load settings squeakfolder = '/path/to/DeepSqueak'; data = squeakData(squeakfolder); data.loadSettings(); % Default settings structure data.defaultSettings = struct(... 'detectionfolder', fullfile(squeakfolder, 'Detections/'), ... 'networkfolder', fullfile(squeakfolder, 'Networks/'), ... 'audiofolder', fullfile(squeakfolder, 'Audio/'), ... 'detectionSettings', {'0', '100', '18', '0', '1'}, ... % length, high_freq, low_freq, score, append_date 'playback_rate', 0.05, ... 'LowFreq', 0, ... 'HighFreq', 115, ... 'AmplitudeThreshold', 0.825, ... 'EntropyThreshold', 0.215, ... 'pageSize', 3, ... 'focus_window_size', 0.5 ... ); % Read audio samples from a time range samples = data.AudioSamples(startTime, endTime); ``` -------------------------------- ### UnsupervisedClustering_Callback - K-means and VAE Clustering Source: https://context7.com/drcoffey/deepsqueak/llms.txt Handles unsupervised clustering of detected calls using K-means, VAE, or ARTwarp methods. Requires configuration of clustering parameters and selection of detection files. ```matlab function UnsupervisedClustering_Callback(hObject, eventdata, handles) % Three clustering methods available: % 1. 'Contour Parameters' - K-means on shape, frequency, duration features % 2. 'Auto Encoder + Contour' - VAE embeddings + frequency features (recommended) % 3. 'ARTwarp' - Adaptive Resonance Theory with dynamic time warping % Example workflow: % 1. Select detection files to cluster % 2. Choose clustering method % 3. Configure parameters: % For Contour Parameters method: clusterParameters = struct(... 'shape_weight', 3, ... % Importance of contour shape 'freq_weight', 2, ... % Importance of frequency 'duration_weight', 1 ... % Importance of duration ); % For VAE method (recommended): % - Trains variational autoencoder on call spectrograms % - Extracts latent embeddings for clustering % - Combines with frequency contour features % K-means optimization options: % 'Elbow Optimized' - Tests 1 to max clusters, finds optimal via elbow method % 'User Defined' - Manually specify number of clusters % After clustering: % - Review clusters in interactive GUI % - Name clusters by entering labels % - Reject misclassified calls by clicking % - Save model for future use % - Update detection files with cluster assignments ``` -------------------------------- ### squeakData - Data Management Class Source: https://context7.com/drcoffey/deepsqueak/llms.txt Handle class for managing application state, audio metadata, and user settings. ```APIDOC ## squeakData ### Description Manages application state including detected calls, audio data, and user preferences. Provides methods for loading/saving configurations and accessing audio samples. ### Properties - **calls** (table) - Detected vocalizations. - **settings** (struct) - User preferences and detection parameters. - **audiodata** (struct) - Audio file metadata. ### Methods - **loadSettings()** - Loads user configuration. - **AudioSamples(startTime, endTime)** - Reads audio samples from a specific time range. ``` -------------------------------- ### Apply Supervised Classification with CNN Source: https://context7.com/drcoffey/deepsqueak/llms.txt Uses a pre-trained CNN to categorize detected calls. Requires a .mat file containing the classification network and image size parameters. ```matlab function SupervisedClassification_Callback(hObject, eventdata, handles) % Uses CNN trained via TrainSupervisedClassifier_Callback % Example: Apply supervised classification % 1. Select trained classification network [FileName, PathName] = uigetfile('Clustering Models/*.mat', 'Select Network'); net = load(fullfile(PathName, FileName), 'ClassifyNet', 'imageSize'); % 2. Process detection files % - Extracts spectrograms from each call % - Resizes to network input size (128x128) % - Classifies using trained CNN % 3. Image preprocessing options.imageSize = [128, 128, 1]; images = zeros([options.imageSize, numCalls]); for i = 1:numCalls images(:,:,:,i) = imresize(ClusteringData.Spectrogram{i}, options.imageSize(1:2)); end % 4. Classification loop for j = 1:height(ClusteringData) X = images(:,:,:,j) ./ 256; % Normalize to [0,1] [clustAssign(j), score] = classify(net.ClassifyNet, X); end % 5. Update detection files with classifications UpdateCluster(ClusteringData, clustAssign, clusterName, rejected); ``` -------------------------------- ### Configure USV Detection and Spectrogram Settings in MATLAB Source: https://context7.com/drcoffey/deepsqueak/llms.txt This MATLAB code defines parameters for USV detection and spectrogram visualization. It includes settings for analysis length, frequency cutoffs, score threshold, and spectrogram parameters like window size and overlap. These can be set via the detect dialog or the Settings array. ```matlab % Detection settings (via detect dialog or Settings array) detectionSettings = { '0', % Total analysis length (seconds, 0=entire file) '100', % High frequency cutoff (kHz) '18', % Low frequency cutoff (kHz) '0', % Score threshold (0-1) '1' % Append date to filename (0 or 1) }; % Spectrogram settings (defined in squeakData) spect_settings = struct(... 'windowsize', 0.0032, ... % FFT window in seconds 'noverlap', 0.0016, ... % Overlap in seconds 'nfft', 0.0032, ... % FFT length in seconds 'type', 'Amplitude' ... ); % Contour detection thresholds EntropyThreshold = 0.215; % Tonality threshold (0-1, higher = more conservative) AmplitudeThreshold = 0.825; % Amplitude percentile (0-1, higher = more conservative) % Change thresholds via: % Tools > Change Contour Threshold ``` -------------------------------- ### DeepSqueak Keyboard Shortcuts in MATLAB Source: https://context7.com/drcoffey/deepsqueak/llms.txt This MATLAB code snippet lists keyboard shortcuts for navigating and managing calls within the DeepSqueak review interface. It covers call navigation, acceptance/rejection, redrawing, deletion, playback, and custom label application. ```matlab % Call Navigation 'e' or Right Arrow % View next call 'q' or Left Arrow % View previous call Up Arrow % Slide focus window forward Down Arrow % Slide focus window backward Space % Next page % Call Management 'a' % Accept current call 'r' % Reject current call 'd' % Redraw bounding box Delete % Delete current call 'p' % Play call audio (at playback_rate) % Classification (when custom labels configured) '1'-'9', '0', '-', '=' % Apply labels 1-12 '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+' % Apply labels 13-24 % Configure custom labels: % Tools > Call Classification > Add Custom Labels % Change playback rate: % Tools > Change Playback Rate (default: 0.05x) ``` -------------------------------- ### TrainSqueakDetector - YOLO v2 Network Training Source: https://context7.com/drcoffey/deepsqueak/llms.txt Trains a custom YOLO v2 object detector using MobileNet v2 as the backbone. Requires labeled training data in a table format. ```matlab function [detector, lgraph, options] = TrainSqueakDetector(TrainingTables, layers) % TrainingTables - Table with columns: imageFilename, USV (bounding boxes) % Example: Train a new detection network % First, create training images using the GUI: % Tools > Network Training > Create Network Training Images % Load training data TrainingTables = load('Training/MouseTrainingData.mat'); % Train the network (takes several hours) [detector, lgraph, options] = TrainSqueakDetector(TrainingTables); % Network architecture details: % - Base: MobileNet v2 % - Feature extraction layer: block_12_add % - 8 anchor boxes estimated from training data % - YOLO v2 detection head with batch normalization % Training options options = trainingOptions('sgdm', ... 'InitialLearnRate', 0.001, ... 'MiniBatchSize', 16, ... 'MaxEpochs', 250, ... 'CheckpointPath', tempdir, ... 'Plots', 'training-progress'); % Save the trained network for detection save('Networks/CustomNetwork.mat', 'detector', 'wind', 'noverlap', 'nfft', 'imLength', 'imScale'); ``` -------------------------------- ### Detect Vocalizations with SqueakDetect Source: https://context7.com/drcoffey/deepsqueak/llms.txt Process audio files using a trained YOLO v2 network to identify vocalizations based on frequency and score thresholds. ```matlab function Calls = SqueakDetect(inputfile, networkfile, fname, Settings, currentFile, totalFiles, networkname) % Settings array: % Settings(1) - Detection length in seconds (0 = entire file) % Settings(2) - High frequency cutoff in kHz % Settings(3) - Low frequency cutoff in kHz % Settings(4) - Score threshold (0-1, calls below this are auto-rejected) % Example: Detect calls in a recording using a pre-trained network inputfile = '/path/to/audio/recording.wav'; networkfile = load('Networks/2025.02.18.Mouse.YoloR3.mat'); fname = 'recording'; Settings = [0, 100, 18, 0]; % Full file, 18-100 kHz range, no score threshold Calls = SqueakDetect(inputfile, networkfile, fname, Settings, 1, 1, 'Mouse'); % Returns table with columns: % Box - [start_time, low_freq, duration, bandwidth] in seconds/kHz % Score - Neural network confidence (0-1) % Type - Call category (default: 'USV') % Accept - Boolean acceptance status ``` -------------------------------- ### CalculateStats - Call Statistics Extraction Source: https://context7.com/drcoffey/deepsqueak/llms.txt Extracts acoustic parameters from spectrograms including frequency, temporal, and power metrics. Uses a contour detection algorithm based on entropy and amplitude thresholds. ```matlab function stats = CalculateStats(I, windowsize, noverlap, nfft, SampleRate, Box, EntropyThreshold, AmplitudeThreshold) % I - Spectrogram matrix % windowsize - FFT window size in samples % noverlap - Overlap between windows in samples % nfft - FFT length in samples % SampleRate - Audio sample rate in Hz % Box - [start_time, low_freq, duration, bandwidth] % EntropyThreshold - Tonality threshold (0-1, default 0.215) % AmplitudeThreshold - Amplitude percentile (0-1, default 0.825) % Returns structure with: stats.BeginTime % Call start time (s) stats.EndTime % Call end time (s) stats.DeltaTime % Call duration (s) stats.PrincipalFreq % Median contour frequency (kHz) stats.LowFreq % Minimum contour frequency (kHz) stats.HighFreq % Maximum contour frequency (kHz) stats.DeltaFreq % Frequency bandwidth (kHz) stats.stdev % Frequency standard deviation (kHz) stats.Slope % Linear slope of contour (kHz/s) stats.Sinuosity % Path length / euclidean distance stats.MeanPower % Average power spectral density (dB/Hz) stats.SignalToNoise % Mean tonality of contour stats.PeakFreq % Frequency at maximum power (kHz) stats.ridgeFreq % Raw contour frequency indices stats.ridgeTime % Raw contour time indices stats.Entropy % Spectral entropy at each time point % Contour detection algorithm: % 1. Calculate entropy: geomean(spectrum) / mean(spectrum) % 2. Find amplitude maxima at each time point % 3. Keep points where amplitude > threshold AND tonality > threshold % 4. Smooth contour using robust lowess filter ``` -------------------------------- ### Define Calls Structure in C Source: https://github.com/drcoffey/deepsqueak/blob/master/Scripts/Readme.md C-style representation of the Calls table structure used in DeepSqueak .mat files. ```C enum CallType{ // Your text labels } struct Calls{ double Box[NUMBER_OF_CALLS][4]; double Score[NUMBER_OF_CALLS]; CallType Type[NUMBER_OF_CALLS]; bool Accept[NUMBER_OF_CALLS]; }; ``` -------------------------------- ### Train Variational Autoencoder Source: https://context7.com/drcoffey/deepsqueak/llms.txt Trains an encoder and decoder network using the Adam optimizer and ELBO loss. Designed for learning compressed spectrogram representations. ```matlab function [encoderNet, decoderNet] = train_vae(encoderNet, decoderNet, XTrain, XTest) % Training parameters numEpochs = 250; miniBatchSize = 128; lr = 0.25e-3; % Learning rate % Training loop with Adam optimizer for epoch = 1:numEpochs for i = 1:numIterations XBatch = dlarray(single(XTrain(:,:,:,idx)), 'SSCB'); % Compute gradients via automatic differentiation [infGrad, genGrad] = dlfeval(@modelGradients, encoderNet, decoderNet, XBatch); % Update networks with Adam [decoderNet.Learnables, avgGradDec, avgGradSqDec] = ... adamupdate(decoderNet.Learnables, genGrad, avgGradDec, avgGradSqDec, iteration, lr); [encoderNet.Learnables, avgGradEnc, avgGradSqEnc] = ... adamupdate(encoderNet.Learnables, infGrad, avgGradEnc, avgGradSqEnc, iteration, lr); end % Evaluate ELBO loss on test set [z, zMean, zLogvar] = sampling(encoderNet, XTest); xPred = sigmoid(forward(decoderNet, z)); elbo = ELBOloss(XTest, xPred, zMean, zLogvar); end % Close training window to stop early if desired ``` -------------------------------- ### Apply Post-Hoc Denoising Source: https://context7.com/drcoffey/deepsqueak/llms.txt Identifies and rejects false positive detections using a trained denoising network. The network classifies inputs as either 'USV' or 'Noise'. ```matlab function PostHocDenoising_Callback(hObject, eventdata, handles) % Load denoising network trained on labeled noise vs. USV examples % Example: Apply post-hoc denoising % 1. Select denoising network [FileName, PathName] = uigetfile('Denoising Network/*.mat', 'Select Denoising Network'); net = load(fullfile(PathName, FileName), 'DenoiseNet', 'imageSize'); % 2. Process each call options.imageSize = [128, 128, 1]; for j = 1:height(ClusteringData) X = images(:,:,:,j) ./ 256; [Classification, score] = classify(net.DenoiseNet, X); % Network outputs 'USV' or 'Noise' classification end % 3. Noise detections are labeled as "Noise" and rejected % 4. Update files with denoising results % Training a denoising network: % Tools > Network Training > Train Post Hoc Denoiser % - Calls labeled "Noise" = negative training samples % - Accepted calls not labeled "Noise" = positive samples ``` -------------------------------- ### SqueakDetect - Neural Network Call Detection Source: https://context7.com/drcoffey/deepsqueak/llms.txt Core function for processing audio files to identify vocalizations using YOLO v2 neural networks. ```APIDOC ## SqueakDetect ### Description Processes audio files using trained YOLO v2 neural networks to identify vocalizations, converts audio to spectrograms, and merges overlapping detections. ### Parameters - **inputfile** (string) - Path to the audio file. - **networkfile** (struct) - Loaded neural network model. - **fname** (string) - Filename identifier. - **Settings** (array) - Detection parameters: [length, high_freq, low_freq, score_threshold]. - **currentFile** (int) - Index of current file. - **totalFiles** (int) - Total number of files. - **networkname** (string) - Name of the network. ### Response - **Calls** (table) - Contains columns: Box (start_time, low_freq, duration, bandwidth), Score (confidence), Type (category), Accept (boolean). ``` -------------------------------- ### Export Call Statistics to Excel in MATLAB Source: https://context7.com/drcoffey/deepsqueak/llms.txt This MATLAB function exports detailed call statistics to an Excel file. It defines the column headers for the output table and calculates statistics using the CalculateStats function. Use this for external data analysis. ```matlab function excel_Callback(hObject, eventdata, handles) % Export workflow: % 1. Select detection folder: File > Select Detection Folder % 2. Click: File > Import / Export > Export to Excel Log % 3. Select files to export % 4. Choose whether to include rejected calls % 5. Select output folder % Excel output columns: exceltable = { 'File', % Source audio filename 'ID', % Call index within file 'Label', % Classification label 'Accepted', % 1=accepted, 0=rejected 'Score', % Neural network confidence 'Begin Time (s)', % Call start time 'End Time (s)', % Call end time 'Call Length (s)', % Duration 'Principal Frequency (kHz)',% Median contour frequency 'Low Freq (kHz)', % Minimum frequency 'High Freq (kHz)', % Maximum frequency 'Delta Freq (kHz)', % Bandwidth 'Frequency Standard Deviation (kHz)', 'Slope (kHz/s)', % Contour slope 'Sinuosity', % Path complexity 'Mean Power (dB/Hz)', % Average power 'Tonality', % Signal-to-noise ratio 'Peak Freq (kHz)' % Frequency at max power }; % Statistics calculated via CalculateStats function stats = CalculateStats(I, windowsize, noverlap, nfft, rate, box, ... handles.data.settings.EntropyThreshold, ... handles.data.settings.AmplitudeThreshold); ``` -------------------------------- ### DeepSqueak JSON Schema Source: https://github.com/drcoffey/deepsqueak/blob/master/Scripts/Readme.md This JSON schema defines the structure and properties for DeepSqueak output files. It specifies data types and descriptions for audio metadata and call annotations. ```JSON Schema { "title": "Data", "description": "A set of labeled calls for DeepQeuak", "type": "object", "properties": { "audiodata": { "description": "The data describing the wav-file", "type": "object", "properties": { "Filename":{ "description": "The full path to the wav-file", "type": "string" }, "CompressionMethod":{ "description": "The method used for the compression", "type": "string" }, "NumChannels":{ "description": "The number of channels", "type": "number" }, "SampleRate":{ "description": "The number of samples per second", "type": "number" }, "TotalSamples":{ "description": "The total number of samples in the file", "type": "number" }, "Duration":{ "description": "The number of seconds the file runs", "type": "number" }, "Title": { "description": "The title of the audio-file", "type": "string" }, "Comment":{ "description": "A comment on the file", "type": "string" }, "Artist":{ "description": "The artist or rodent that produced the file", "type": "string" }, "BitsPerSample":{ "description": "The number of bits per sample", "type": "number" } } }, "Calls":{ "description": "The calls that can be found in the wav-file the properties are 4 colums of a table", "type": "object", "properties": { "Box": { "description": "An array of arrays describing the calls as boxes in a spectrogram", "type": "array", "items":{ "description": "The boxes are described by their lower-corner and size, so first comes the lowest time, then the lowest frequency, then the extent in time than the extent in frequency.", "type":"array", "items":{ "type":"number" } } }, "Score": { "description": "An array describing the confidence that this is a call", "type": "array", "items":{ "type":"number" } }, "Type": { "description": "An array defining the type of the call, these are the labels for the network", "type": "array", "items":{ "type":"string" } }, "Accept": { "description": "An array (presumably) deteriming if the call will be used for training or not", "type": "array", "items":{ "type":"boolean" } } } } } } ``` -------------------------------- ### Define Call Box Dimensions Source: https://github.com/drcoffey/deepsqueak/blob/master/Scripts/Readme.md Represents the temporal and frequency boundaries of a call box. ```text [lower_x, lower_y, extension_x, extension_y] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.