Skip to content
Snippets Groups Projects
Commit 91d5394c authored by Stephane Chavin's avatar Stephane Chavin
Browse files

correction dataloader and get time freq offset

parent ae69a8db
Branches
No related tags found
No related merge requests found
......@@ -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'
......
......@@ -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
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment