Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Errors in two_phase_predictions.ipynb #33

Open
matthewdrees opened this issue Jun 6, 2022 · 1 comment
Open

Errors in two_phase_predictions.ipynb #33

matthewdrees opened this issue Jun 6, 2022 · 1 comment

Comments

@matthewdrees
Copy link

matthewdrees commented Jun 6, 2022

  • "audio" path should be "audio_spectros".
  • "image_batch" variable not found.
  • fit_generator() method deprecated, prefer fit().
  • The spectrometer png files get moved, so need to redownload or copy them.
@matthewdrees
Copy link
Author

matthewdrees commented Jun 6, 2022

This fixed it for me. Give me (limited) permission and I can create a PR.

Author: Matt Drees <[email protected]>  2022-06-06 12:21:58
Committer: Matt Drees <[email protected]>  2022-06-06 12:21:58
Parent: 060eb9f9be1d7f7e2d7e103a29a01386723c22fe (Merge pull request #28 from robertlacok/patch-1)
Child:  0000000000000000000000000000000000000000 (Local uncommitted changes, not checked in to index)
Branch: fix_two_phase_predictions_ipynb
Follows: 
Precedes: 

    Fixes for two_phase_predictions.ipynb.
    
    Fixes:
    * "audio" -> "audio_spectros" path
    * "image_batch" variable not found.
    * fit_generator() method deprecated, prefer fit().
    * Moved the *.png files so redownload them.
    
    Tested by re-running the notebook from scratch.

------------------ 05_resilience/two_phase_predictions.ipynb ------------------
index dbd3383..fb3243d 100644
@@ -701,7 +701,7 @@
    },
    "outputs": [],
    "source": [
-    "data_dir = pathlib.Path(os.getcwd() + '/audio')\n",
+    "data_dir = pathlib.Path(os.getcwd() + '/audio_spectros')\n",
     "class_names = ['not_instrument', 'instrument']"
    ]
   },
@@ -897,7 +897,7 @@
    },
    "outputs": [],
    "source": [
-    "feature_batch = mobilenet(image_batch)"
+    "feature_batch = mobilenet(val_image)"
    ]
   },
   {
@@ -1045,9 +1045,9 @@
    },
    "outputs": [],
    "source": [
-    "model.fit_generator(train_data_gen, \n",
-    "                    validation_data=val_data_gen,\n",
-    "                    steps_per_epoch=STEPS_PER_EPOCH, epochs=10)"
+    "model.fit(train_data_gen,\n",
+    "          validation_data=val_data_gen,\n",
+    "          steps_per_epoch=STEPS_PER_EPOCH, epochs=10)"
    ]
   },
   {
@@ -1366,6 +1366,24 @@
     "Create directories for each instrument label. We'll use this later when we load our images with Keras's `ImageDataGenerator` class."
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "colab": {
+     "base_uri": "https://localhost:8080/",
+     "height": 1000
+    },
+    "colab_type": "code",
+    "id": "IsipOIHWaFQW",
+    "outputId": "76542e83-ec27-4dfd-c3f9-d3402faf99e2"
+   },
+   "outputs": [],
+   "source": [
+    "# Moved them so have to download them again.\n",
+    "!gsutil -m cp -r gs://ml-design-patterns/audio_train_spectro ."
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": 299,
@@ -1512,7 +1530,7 @@
     }
    ],
    "source": [
-    "feature_batch = vgg_model(image_batch)\n",
+    "feature_batch = vgg_model(image_instrument_train)\n",
     "global_avg_layer = tf.keras.layers.GlobalAveragePooling2D()\n",
     "feature_batch_avg = global_avg_layer(feature_batch)\n",
     "print(feature_batch_avg.shape)"
@@ -1604,7 +1622,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "instrument_model.fit_generator(\n",
+    "instrument_model.fit(\n",
     "    train_data_instrument, \n",
     "    validation_data=val_data_instrument,\n",
     "    steps_per_epoch=STEPS_PER_EPOCH, epochs=10)"
@@ -1694,4 +1712,4 @@
  },
  "nbformat": 4,
  "nbformat_minor": 4
-}
\ No newline at end of file
+}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant