|
104 | 104 | "import seaborn as sns\n",
|
105 | 105 | "import tensorflow as tf\n",
|
106 | 106 | "\n",
|
107 |
| - "from tensorflow.keras.layers.experimental import preprocessing\n", |
108 | 107 | "from tensorflow.keras import layers\n",
|
109 | 108 | "from tensorflow.keras import models\n",
|
110 | 109 | "from IPython import display\n",
|
|
620 | 619 | },
|
621 | 620 | "source": [
|
622 | 621 | "For the model, you'll use a simple convolutional neural network (CNN), since you have transformed the audio files into spectrogram images.\n",
|
623 |
| - "The model also has the following additional preprocessing layers:\n", |
624 |
| - "- A [`Resizing`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/experimental/preprocessing/Resizing) layer to downsample the input to enable the model to train faster.\n", |
625 |
| - "- A [`Normalization`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/experimental/preprocessing/Normalization) layer to normalize each pixel in the image based on its mean and standard deviation.\n", |
| 622 | + "The model also has the following additional Keras preprocessing layers:\n", |
| 623 | + "- `tf.keras.layers.Resizing`: to downsample the input to enable the model to train faster.\n", |
| 624 | + "- `tf.keras.layers.Normalization`: to normalize each pixel in the image based on its mean and standard deviation.\n", |
626 | 625 | "\n",
|
627 | 626 | "For the `Normalization` layer, its `adapt` method would first need to be called on the training data in order to compute aggregate statistics (i.e. mean and standard deviation)."
|
628 | 627 | ]
|
|
640 | 639 | "print('Input shape:', input_shape)\n",
|
641 | 640 | "num_labels = len(commands)\n",
|
642 | 641 | "\n",
|
643 |
| - "norm_layer = preprocessing.Normalization()\n", |
| 642 | + "norm_layer = layers.Normalization()\n", |
644 | 643 | "norm_layer.adapt(spectrogram_ds.map(lambda x, _: x))\n",
|
645 | 644 | "\n",
|
646 | 645 | "model = models.Sequential([\n",
|
647 | 646 | " layers.Input(shape=input_shape),\n",
|
648 |
| - " preprocessing.Resizing(32, 32), \n", |
| 647 | + " layers.Resizing(32, 32), \n", |
649 | 648 | " norm_layer,\n",
|
650 | 649 | " layers.Conv2D(32, 3, activation='relu'),\n",
|
651 | 650 | " layers.Conv2D(64, 3, activation='relu'),\n",
|
|
0 commit comments