The code is a Python script for audio event detection using few-shot learning and match template algorithm.

The script starts by importing necessary libraries such as os, librosa, numpy, and csv.

Then, it defines a function called 'fewshot_match_template' that takes a folder path as an argument.

Inside the function, it first gets a list of all sub-folders in the given folder path using 'os.listdir()'.

Then, it initializes a list 'to_write' with the headers of the output CSV file.

For each sub-folder, the function gets a list of all files in the sub-folder and iterates through them. If the file is a '.wav' file, it loads the audio file using 'librosa.load()' and computes its Short-Time Fourier Transform (STFT) using 'librosa.stft()'.

The STFT is then subjected to noise reduction by subtracting the frequency bin median value per bin and time frame median value per time frame.

The code then extracts positive (POS) events from the annotations file, which are to be used as templates for the match template algorithm.

The section of STFT to use for prediction is then defined, which starts after the end time of the last template event.

For each event template, the code calculates the start and end time of the event and extracts the STFT data for that event. Then, the 'match_template()' function is called to compute the similarity between the event template and the section of STFT to use for prediction.

A different prediction threshold is set for each audio file based on the similarity of the 5 templates.

Peak picking is then performed on the 'match_template' result vector to turn peaks into 1 and the rest into 0.

The predictions are then combined by creating segments based on the center of predictions and template length, and then overlapping all predictions.

Finally, the function transforms time frames to seconds in predictions and fills the 'to_write' list with predicted results.

The function then writes the 'to_write' list into a CSV file with the given output file name.

If the script is run as the main program, it parses the command line arguments for the folder path and calls the 'fewshot_match_template' function with the given folder path.

Audio Event Detection using Few-Shot Learning and Match Template Algorithm

原文地址: https://www.cveoy.top/t/topic/nMRy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录