Skip to content

Commit 1ddc6e6

Browse files
authored
Lint the Transfer Learning with YAMNet tutorial
1 parent 1285360 commit 1ddc6e6

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

site/en/tutorials/audio/transfer_learning_audio.ipynb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"source": [
6565
"# Transfer Learning with YAMNet for environmental sound classification\n",
6666
"\n",
67-
"[YAMNet](https://tfhub.dev/google/yamnet/1) is an audio event classifier that can predict audio events from [521 classes](https://github.com/tensorflow/models/blob/master/research/audioset/yamnet/yamnet_class_map.csv), like laughter, barking, or a siren. \n",
67+
"[YAMNet](https://tfhub.dev/google/yamnet/1) is a pretrained deep neural network that can predict audio events from [521 classes](https://github.com/tensorflow/models/blob/master/research/audioset/yamnet/yamnet_class_map.csv), like laughter, barking, or a siren. \n",
6868
"\n",
6969
" In this tutorial you will learn how to:\n",
7070
"\n",
@@ -130,27 +130,27 @@
130130
"source": [
131131
"## About YAMNet\n",
132132
"\n",
133-
"YAMNet is an audio event classifier that takes audio waveform as input and makes independent predictions for each of 521 audio events from the [AudioSet](https://research.google.com/audioset/) ontology.\n",
133+
"[YAMNet](https://github.com/tensorflow/models/tree/master/research/audioset/yamnet) is a pretrained neural network that employs the [MobileNetV1](https://arxiv.org/abs/1704.04861) depthwise-separable convolution architecture. It can use an audio waveform as input and classify 521 audio events from the [AudioSet](http://g.co/audioset) corpus.\n",
134134
"\n",
135-
"Internally, the model extracts \"frames\" from the audio signal and processes batches of these frames. This version of the model uses frames that are 0.96s long and extracts one frame every 0.48s.\n",
135+
"Internally, the model extracts \"frames\" from the audio signal and processes batches of these frames. This version of the model uses frames that are 0.96 second long and extracts one frame every 0.48 second.\n",
136136
"\n",
137137
"The model accepts a 1-D float32 Tensor or NumPy array containing a waveform of arbitrary length, represented as mono 16 kHz samples in the range `[-1.0, +1.0]`. This tutorial contains code to help you convert a `.wav` file into the correct format.\n",
138138
"\n",
139139
"The model returns 3 outputs, including the class scores, embeddings (which you will use for transfer learning), and the log mel spectrogram. You can find more details [here](https://tfhub.dev/google/yamnet/1), and this tutorial will walk you through using these in practice.\n",
140140
"\n",
141-
"One specific use of YAMNet is as a high-level feature extractor: the `1024-D` embedding output of YAMNet can be used as the input features of another shallow model which can then be trained on a small amount of data for a particular task. This allows the quick creation of specialized audio classifiers without requiring a lot of labeled data and without having to train a large model end-to-end.\n",
141+
"One specific use of YAMNet is as a high-level feature extractor: the 1024-dimensional embedding output of YAMNet can be used as the input features of another shallow model which can then be trained on a small amount of data for a particular task. This allows the quick creation of specialized audio classifiers without requiring a lot of labeled data and without having to train a large model end-to-end.\n",
142142
"\n",
143143
"You will use YAMNet's embeddings output for transfer learning and train one or more [Dense](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense) layers on top of this.\n",
144144
"\n",
145145
"First, you will try the model and see the results of classifying audio. You will then construct the data pre-processing pipeline.\n",
146146
"\n",
147147
"### Loading YAMNet from TensorFlow Hub\n",
148148
"\n",
149-
"You are going to use YAMNet from [Tensorflow Hub](https://tfhub.dev/) to extract the embeddings from the sound files.\n",
149+
"You are going to use a pre-trained YAMNet from [Tensorflow Hub](https://tfhub.dev/) to extract the embeddings from the sound files.\n",
150150
"\n",
151-
"Loading a model from TensorFlow Hub is straightforward: choose the model, copy its URL and use the `load` function.\n",
151+
"Loading a model from TensorFlow Hub is straightforward: choose the model, copy its URL, and use the `load` function.\n",
152152
"\n",
153-
"Note: to read the documentation of the model, you can use the model url in your browser."
153+
"Note: to read the documentation of the model, use the model URL in your browser."
154154
]
155155
},
156156
{
@@ -171,7 +171,7 @@
171171
"id": "GmrPJ0GHw9rr"
172172
},
173173
"source": [
174-
"With the model loaded and following the [models's basic usage tutorial](https://www.tensorflow.org/hub/tutorials/yamnet) you'll download a sample wav file and run the inference.\n"
174+
"With the model loaded, you can follow the [YAMNet basic usage tutorial](https://www.tensorflow.org/hub/tutorials/yamnet) and download a sample WAV file to run the inference.\n"
175175
]
176176
},
177177
{
@@ -196,9 +196,9 @@
196196
"id": "mBm9y9iV2U_-"
197197
},
198198
"source": [
199-
"You will need a function to load the audio files. They will also be used later when working with the training data.\n",
199+
"You will need a function to load audio files, which will also be used later when working with the training data.\n",
200200
"\n",
201-
"Note: The returned `wav_data` from `load_wav_16k_mono` is already normalized to values in `[-1.0, 1.0]` (as stated in the model's [documentation](https://tfhub.dev/google/yamnet/1))."
201+
"Note: The returned `wav_data` from `load_wav_16k_mono` is already normalized to values in the `[-1.0, 1.0]` range (as stated in the model's [documentation](https://tfhub.dev/google/yamnet/1))."
202202
]
203203
},
204204
{
@@ -209,7 +209,7 @@
209209
},
210210
"outputs": [],
211211
"source": [
212-
"# Util functions for loading audio files and ensure the correct sample rate\n",
212+
"# Utility functions for loading audio files and ensure the correct sample rate\n",
213213
"\n",
214214
"@tf.function\n",
215215
"def load_wav_16k_mono(filename):\n",
@@ -248,7 +248,7 @@
248248
"source": [
249249
"### Load the class mapping\n",
250250
"\n",
251-
"It's important to load the class names that YAMNet is able to recognize. The mapping file is present at `yamnet_model.class_map_path()`, in the `csv` format."
251+
"It's important to load the class names that YAMNet is able to recognize. The mapping file is present at `yamnet_model.class_map_path()` in the CSV format."
252252
]
253253
},
254254
{
@@ -275,7 +275,7 @@
275275
"source": [
276276
"### Run inference\n",
277277
"\n",
278-
"YAMNet provides frame-level class-scores (i.e., 521 scores for every frame). In order to determine clip-level predictions, the scores can be aggregated per-class across frames (e.g., using mean or max aggregation). This is done below by `scores_np.mean(axis=0)`. Finally, in order to find the top-scored class at the clip-level, we take the maximum of the 521 aggregated scores.\n"
278+
"YAMNet provides frame-level class-scores (i.e., 521 scores for every frame). In order to determine clip-level predictions, the scores can be aggregated per-class across frames (e.g., using mean or max aggregation). This is done below by `scores_np.mean(axis=0)`. Finally, to find the top-scored class at the clip-level, you take the maximum of the 521 aggregated scores.\n"
279279
]
280280
},
281281
{
@@ -301,7 +301,7 @@
301301
"id": "YBaLNg5H5IWa"
302302
},
303303
"source": [
304-
"Note: The model correctly inferred an animal sound. Your goal is to increase accuracy for specific classes. Also, notice that the the model generated 13 embeddings, 1 per frame."
304+
"Note: The model correctly inferred an animal sound. Your goal in this tutorial is to increase the model's accuracy for specific classes. Also, notice that the the model generated 13 embeddings, 1 per frame."
305305
]
306306
},
307307
{
@@ -312,9 +312,9 @@
312312
"source": [
313313
"## ESC-50 dataset\n",
314314
"\n",
315-
"The [ESC-50 dataset](https://github.com/karolpiczak/ESC-50#repository-content), well described [here](https://www.karolpiczak.com/papers/Piczak2015-ESC-Dataset.pdf), is a labeled collection of 2000 environmental audio recordings (each 5 seconds long). The data consists of 50 classes, with 40 examples per class.\n",
315+
"The [ESC-50 dataset](https://github.com/karolpiczak/ESC-50#repository-content) - described in detail [here](https://www.karolpiczak.com/papers/Piczak2015-ESC-Dataset.pdf) - is a labeled collection of 2,000 five-second long environmental audio recordings. The data consists of 50 classes, with 40 examples per class.\n",
316316
"\n",
317-
"Next, you will download and extract it. \n"
317+
"Download the dataset and extract it. \n"
318318
]
319319
},
320320
{
@@ -344,7 +344,7 @@
344344
"\n",
345345
"and all the audio files are in `./datasets/ESC-50-master/audio/`\n",
346346
"\n",
347-
"You will create a pandas dataframe with the mapping and use that to have a clearer view of the data.\n"
347+
"You will create a pandas DataFrame with the mapping and use that to have a clearer view of the data.\n"
348348
]
349349
},
350350
{
@@ -370,11 +370,11 @@
370370
"source": [
371371
"### Filter the data\n",
372372
"\n",
373-
"Given the data on the dataframe, you will apply some transformations:\n",
373+
"Now that the data is tored in the DataFrame, apply some transformations:\n",
374374
"\n",
375-
"- filter out rows and use only the selected classes (dog and cat). If you want to use any other classes, this is where you can choose them.\n",
376-
"- change the filename to have the full path. This will make loading easier later.\n",
377-
"- change targets to be within a specific range. In this example, dog will remain 0, but cat will become 1 instead of its original value of 5."
375+
"- Filter out rows and use only the selected classes - `dog` and `cat`. If you want to use any other classes, this is where you can choose them.\n",
376+
"- Amend the filename to have the full path. This will make loading easier later.\n",
377+
"- Change targets to be within a specific range. In this example, `dog` will remain at `0`, but `cat` will become `1` instead of its original value of `5`."
378378
]
379379
},
380380
{
@@ -418,9 +418,9 @@
418418
"id": "AKDT5RomaDKO"
419419
},
420420
"source": [
421-
"Your model will use each frame as one input so you need to to create a new column that has one frame per row. You also need to expand the labels and fold column to proper reflect these new rows.\n",
421+
"Your model will use each frame as one input. Therefore, you need to create a new column that has one frame per row. You also need to expand the labels and fold column to proper reflect these new rows.\n",
422422
"\n",
423-
"The expanded fold column keeps the original value. You cannot mix frames because, when doing the splits, you might end with parts of the same audio on different splits and that would make our validation and test steps less effective."
423+
"The expanded fold column keeps the original value. You cannot mix frames because, when performing the splits, you might end up having parts of the same audio on different splits - that would make your validation and test steps less effective."
424424
]
425425
},
426426
{
@@ -525,7 +525,7 @@
525525
"## Create your model\n",
526526
"\n",
527527
"You did most of the work!\n",
528-
"Next, define a very simple Sequential Model to start with -- one hiden layer and 2 outputs to recognize cats and dogs.\n"
528+
"Next, define a very simple Sequential model with one hidden layer and two outputs to recognize cats and dogs.\n"
529529
]
530530
},
531531
{
@@ -641,15 +641,15 @@
641641
"id": "k2yleeev645r"
642642
},
643643
"source": [
644-
"## Save a model that can directly take a wav file as input\n",
644+
"## Save a model that can directly take a WAV file as input\n",
645645
"\n",
646646
"Your model works when you give it the embeddings as input.\n",
647647
"\n",
648-
"In a real situation you'll want to give it the sound data directly.\n",
648+
"In a real-world scenario, you'll want to use audio data as a direct input.\n",
649649
"\n",
650-
"To do that you will combine YAMNet with your model into one single model that you can export for other applications.\n",
650+
"To do that, you will combine YAMNet with your model into a single model that you can export for other applications.\n",
651651
"\n",
652-
"To make it easier to use the model's result, the final layer will be a `reduce_mean` operation. When using this model for serving, as you will see bellow, you will need the name of the final layer. If you don't define one, TF will auto define an incremental one that makes it hard to test as it will keep changing everytime you train the model. When using a raw tf operation you can't assign a name to it. To address this issue, you'll create a custom layer that just apply `reduce_mean` and you will call it 'classifier'.\n"
652+
"To make it easier to use the model's result, the final layer will be a `reduce_mean` operation. When using this model for serving, as you will see bellow, you will need the name of the final layer. If you don't define one, TensorFlow will auto-define an incremental one that makes it hard to test, as it will keep changing every time you train the model. When using a raw tf operation you can't assign a name to it. To address this issue, you'll create a custom layer that just apply `reduce_mean` and you will call it 'classifier'.\n"
653653
]
654654
},
655655
{
@@ -828,9 +828,9 @@
828828
"source": [
829829
"## Next steps\n",
830830
"\n",
831-
"You just created a model that can classify sounds from dogs or cats. With the same idea and proper data you could, for example, build a bird recognizer based on their singing.\n",
831+
"You have created a model that can classify sounds from dogs or cats. With the same idea and a different dataset you can try, for example, building an [acoustic identifier of birds](https://www.kaggle.com/c/birdclef-2021/) based on their singing.\n",
832832
"\n",
833-
"Let us know what you come up with! Share your project with us on social media.\n"
833+
"Share your project with the TensorFlow team on social media!\n"
834834
]
835835
}
836836
],

0 commit comments

Comments
 (0)