You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @pythonlessons,
I think, Class SpectrogramPadding has a bag.
Original code:
A short spectrogram data is slide to backward(tail) of padded_spectrogram.
But, I want, A short spectrogram data will be slide to forward(head) of padded_spectrogram.
class SpectrogramPadding(Transformer):
"""Pad spectrogram to max_spectrogram_length
Attributes:
max_spectrogram_length (int): Maximum length of spectrogram
padding_value (int): Value to pad
"""
def __init__(
self,
max_spectrogram_length: int,
padding_value: int
) -> None:
self.max_spectrogram_length = max_spectrogram_length
self.padding_value = padding_value
def __call__(self, spectrogram: np.ndarray, label: np.ndarray):
padded_spectrogram = np.pad(spectrogram, ((self.max_spectrogram_length - spectrogram.shape[0], 0),(0,0)), mode="constant", constant_values=self.padding_value)
return padded_spectrogram, label
New code:
class SpectrogramPadding(Transformer):
"""Pad spectrogram to max_spectrogram_length
Attributes:
max_spectrogram_length (int): Maximum length of spectrogram
padding_value (int): Value to pad
"""
def __init__(
self,
max_spectrogram_length: int,
padding_value: int,
append: bool = True
) -> None:
self.max_spectrogram_length = max_spectrogram_length
self.padding_value = padding_value
self.append=append
def __call__(self, spectrogram: np.ndarray, label: np.ndarray):
#print('spectrogram.shape:',spectrogram.shape)
# spectrogram.shape: (1032, 193)
if self.append==False:
padded_spectrogram = np.pad(spectrogram,
((self.max_spectrogram_length - spectrogram.shape[0], 0),(0,0)),mode="constant",constant_values=self.padding_value)
else:
l,h =spectrogram.shape
lng = self.max_spectrogram_length - l
if lng > 0:
a = np.full((lng,h),self.padding_value)
padded_spectrogram = np.append(spectrogram, a, axis=0)
else:
padded_spectrogram = spectrogram
return padded_spectrogram, label
The text was updated successfully, but these errors were encountered:
Hey, thanks. The idea was that it would append the end of the spectrogram by default, not sure how I missed this, but definitely I will fix this in the next release. Thanks!
Your code is a little complicated. Right now it is following:
Hi @pythonlessons,
I think, Class SpectrogramPadding has a bag.
Original code:
A short spectrogram data is slide to backward(tail) of padded_spectrogram.
But, I want, A short spectrogram data will be slide to forward(head) of padded_spectrogram.
New code:
The text was updated successfully, but these errors were encountered: