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
I am in the process of implementing an audio classifier intended for production use. However, I am encountering challenges with the logic, as I am relatively new to AutoML and MLOps. I would greatly appreciate any tips or guidance on the following code. Please excuse any inconsistencies in the logic, as I am still learning and refining the implementation.
importautokerasasakimporttrain_utilsascbfromtrain_utilsimport (
stereo_to_mono_converter,
squeeze,
get_spectrogram
)
classSoundClf():
defbuild(self,hp,inputs):
# Apply your data processing pipeline to the inputsx, y=inputsx=stereo_to_mono_converter(x, y)
x=squeeze(x, y)
x=get_spectrogram(x)
input=ak.ImageInput()
resize=cb.ResizingBlock()(input)
norm_layer=ak.Normalization()(resize)
conv1=ak.ConvBlock()(norm_layer)
conv2=ak.ConvBlock()(conv1)
conv3=ak.ConvBlock()(conv2)
res=ak.ResNetBlock(version="v2")(norm_layer)
merge=ak.Merge()[conv3,res]
conv4=ak.ConvBlock()(merge)
output=ak.ClassificationHead()(conv4)
auto_model=ak.AutoModel(
inputs=input, outputs=output, overwrite=True, max_trials=1
)
returnauto_model(x)
the functions from my custom module train_utils are as follows:
Resizing Block
classResizingBlock(ak.Block):
""" Resizing Block implemented from keras.layers.Resizing """defbuild(self, hp, inputs=None):
# Get the input_node from inputs.input_node=inputs[0]
layer=keras.layers.Resizing(
target_height=hp.Int("height", min_value=32, max_value=1024, step=16),
target_width=hp.Int("width", min_value=32, max_value=1024, step=16)
)
output_node=layer(input_node)
returnoutput_node
The rest of the functions
seed=42tf.random.set_seed(seed)
np.random.seed(seed)
defstereo_to_mono_converter(example,labels):
audio=example# If it has multiple channels, take the mean to convert to monoaudio=tf.reduce_mean(audio, axis=-1, keepdims=True)
# Add any additional preprocessing steps herereturnaudio,labelsdefsqueeze(audio, labels):
audio=tf.squeeze(audio, axis=-1)
returnaudio, labelsdefget_spectrogram(waveform):
spectrogram=tf.signal.stft(
waveform, frame_length=255, frame_step=128)
spectrogram=tf.abs(spectrogram)
spectrogram=spectrogram[..., tf.newaxis]
returnspectrogramdefmake_spec_ds(ds):
returnds.map(
map_func=lambdaaudio,label: (get_spectrogram(audio), label),
num_parallel_calls=tf.data.AUTOTUNE)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I am in the process of implementing an audio classifier intended for production use. However, I am encountering challenges with the logic, as I am relatively new to AutoML and MLOps. I would greatly appreciate any tips or guidance on the following code. Please excuse any inconsistencies in the logic, as I am still learning and refining the implementation.
the functions from my custom module
train_utils
are as follows:Resizing Block
The rest of the functions
Beta Was this translation helpful? Give feedback.
All reactions