diff --git a/get_spectrogram.py b/get_spectrogram.py index 8ed5d3501c33a803899fcada1ae637eb5b562a71..69b178ea75d31ced63c85b993896b7c070c1d946 100755 --- a/get_spectrogram.py +++ b/get_spectrogram.py @@ -53,8 +53,8 @@ def main(data, arguments): name = os.path.join(arguments.directory, folder, f'{file}_{offset}') utils.create_spectrogram( - sig, arguments.directory, name, arguments.cmap, window_size=int(arguments.window), - overlap=arguments.hop, vmin=arguments.vmin) + sig, arguments.directory, name, arguments.cmap, arguments.vmin, window_size=int(arguments.window), + overlap=arguments.hop) except Exception as error: folder = 'spectrograms' diff --git a/utils.py b/utils.py index f55344a85f562525f7136e0b2262f68da94e5a0a..14839f1baeb7951192c37e8493a8a1782da94db3 100755 --- a/utils.py +++ b/utils.py @@ -87,15 +87,17 @@ def signal_processing(sig, rf, fs, high=None, low=None): return sig -def create_spectrogram(sig, directory, names, cmap, window_size=1024, overlap=.5, minimum=True): +def create_spectrogram(sig, directory, names, cmap, minimum, window_size=1024, overlap=.5): """ Create a spectrogram STFT with hanning window and save it into a directory :param sig (array): Signal to process. + :param directory (str): Path to save the spectrogram. + :param names (str): Name of the final spectrogram. + :param cmap (str): Name of the colormap for matplotlib. + :param minimum (str): If True minimum of spectrogram imshow will be stft.mean(), else stft.min() :param window_size (int): Number of sample / STFT window. :param overlap (float): Ratio of overlapping samples between each window (default 50%). - :param directory (str): Path to save the spectrogram. - :param filename (str): Name of the final spectrogram. """ if overlap >= 1: print(f'You put a hop value over 1. This has been corrected to have {overlap} as overlap size between window') @@ -107,7 +109,7 @@ def create_spectrogram(sig, directory, names, cmap, window_size=1024, overlap=.5 hop_length=int(overlap_size), window='hann') # Compute the STFT stft = np.log10(np.abs(stft)) # Adapt the Complex-valued matrix fig = plt.figure() - if minimum: + if minimum == 'True': vmin = stft.mean() else: vmin = stft.min() @@ -395,7 +397,7 @@ def detection2time_freq(annotations_folder, duration, outdir, rf, names, wav, ra names = np.arange(0, total+1).tolist() df['species'] = df['class'].apply(lambda x: names[int(x)]) - df['pos'] = (df['x'] * duration) + df['class'].astype(int) + df['pos'] = (df['x'] * duration) + df['offset'].astype(int) df['Low Freq (Hz)'] = (1 - df['y']) * (rf / 2) - (df['h'] * (rf / 2)) / 2 df['High Freq (Hz)'] = (1 - df['y']) * (rf / 2) + (df['h'] * (rf / 2)) / 2 df['Begin Time (s)'] = df['pos'] - (df['w'] * duration) / 2 diff --git a/yolov5/utils/dataloaders.py b/yolov5/utils/dataloaders.py index cbc3738bc75b014636a5c695fda40394cfedbd75..3fbdab5138188e34036093f83c567636d4ff5916 100755 --- a/yolov5/utils/dataloaders.py +++ b/yolov5/utils/dataloaders.py @@ -239,8 +239,8 @@ class LoadScreenshots: return str(self.screen), im, im0, None, s # screen, img, original img, im0s, s class LoadSpectros: - def __init__(self, folder, sampleDur, rf, window, hop, low, high, cmap, img_size, stride=32, auto=True, minimum=True): - self.folder, self.sampleDur, self.rf, self.window, self.hop, self.low, self.high, self.cmap, self.img_size, self.stride, self.auto, self.minimum = folder, sampleDur, rf, window, hop, low, high, cmap, img_size, stride, auto, minimum + def __init__(self, folder, sampleDur, rf, window, hop, low, high, cmap, minimum, img_size, stride=32, auto=True): + self.folder, self.sampleDur, self.rf, self.window, self.hop, self.low, self.high, self.cmap, self.minimum, self.img_size, self.stride, self.auto = folder, sampleDur, rf, window, hop, low, high, cmap, minimum, img_size, stride, auto self.files = os.listdir(folder) self.mode = 'image' self.samples = [] @@ -290,7 +290,7 @@ class LoadSpectros: stft = librosa.stft(sig, n_fft=self.window, hop_length=hop, window='hann') # Compute the STFT stft = np.log10(np.abs(stft)) - if minimum: + if self.minimum == 'True': vmin = stft.mean() else: vmin = stft.min()