From 2d19dd0b7cd8118cebb72512522109fa90096fb8 Mon Sep 17 00:00:00 2001 From: BrianStucky-USDA Date: Tue, 9 Jan 2024 18:03:43 -0500 Subject: [PATCH 1/4] Edits to notebook 4. --- 03_bees_vs_wasps.ipynb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/03_bees_vs_wasps.ipynb b/03_bees_vs_wasps.ipynb index bc0c596..b9d1fee 100644 --- a/03_bees_vs_wasps.ipynb +++ b/03_bees_vs_wasps.ipynb @@ -259,7 +259,7 @@ "\n", "One hyperparameter to explore is the activation function, which is set when making the model. We start with a ReLU as the default, but you can try others. For simplicity, we will use the same activation function for all but the last layer of the model, but you could change them individually.\n", "\n", - "The last layer will almost always use a Softmax, which makes all the output values between 0 and 1 and sum to 1, transforming them into probabilities of the input belonging to each possible class." + "The last layer will almost always use a Softmax, which makes all the output values between 0 and 1 and sum to 1, transforming them into \"probabilities\" of the input belonging to each possible class." ] }, { @@ -453,14 +453,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "tags": [] }, "outputs": [], "source": [ "def the_whole_shebang(path, batch_size, shape, classes, activation, loss, optimizer, show_pictures=True):\n", - " \n", " X_train, X_test = load_display_data(path, batch_size, shape, show_pictures)\n", " model = make_model(activation=activation, shape=shape, num_classes=classes)\n", " model, history = compile_train_model(X_train, X_test, model, loss=loss,\n", @@ -517,9 +516,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Tensorflow-2.7.0", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "tensorflow-2.7.0" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -531,7 +530,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.10.2" } }, "nbformat": 4, From 5a2d4b4743ffdf6d33dad7db9ecdaa7f22a9bbc0 Mon Sep 17 00:00:00 2001 From: BrianStucky-USDA Date: Tue, 9 Jan 2024 18:04:44 -0500 Subject: [PATCH 2/4] Edits to notebook 3. --- 02.2_mnist_classifier.ipynb | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/02.2_mnist_classifier.ipynb b/02.2_mnist_classifier.ipynb index 47cacd3..fbbaf97 100644 --- a/02.2_mnist_classifier.ipynb +++ b/02.2_mnist_classifier.ipynb @@ -17,11 +17,11 @@ "\n", "While Amelia's data collection process is working for most participants in her study, some do not like using the phone application to submit their survey responses. They keep sending in handwritten responses. Realizing that the data from these study participants is still vital to her research, Dr. Amelia is now looking to automate entering these responses using a program to read the numbers that make up the survey responses.\n", "\n", - "Again, Amelia decides to start with the basics: recognizing handwritten numbers. That's where the MNIST dataset comes in. With its vast collection of handwritten digits, it's the perfect training ground for Amelia's next AI venture.\n", + "Again, Amelia decides to start with the basics: recognizing handwritten numbers. That's where the MNIST dataset comes in. With its vast collection of handwritten digits, it's the perfect training ground for Amelia's next AI adventure.\n", "\n", "**Note:** The cartoon of Dr Amelia's dog was generated with AI's assistance.\n", "\n", - "Training a model on the MNIST dataset is often considered the \"Hello world!\" of AI. It is a commonly used first introduction to image recognition with deep learning.\n", + "Training a model on the MNIST dataset is often considered the \"Hello world!\" of modern computer vision. It is a commonly used first introduction to image recognition with deep learning.\n", "\n", "\n", "![AI Application Development Pathway model](https://github.com/PracticumAI/deep_learning_2_draft/blob/main/M3-AppDev.00_00_22_23.Still001.png?raw=true)\n", @@ -34,7 +34,7 @@ "\n", "The MNIST dataset is frequently used in machine learning research and has become a standard benchmark for image classification models. Top-performing models often achieve a classification accuracy above 99%, with an error rate between 0.4% and 0.2% on the hold-out test dataset.\n", "\n", - "In this exercise, you will implement a deep neural network (multi-layer) capable of classifying these images of handwritten digits into one of 10 classes. \n", + "In this exercise, you will implement a deep (multi-layer) neural network capable of classifying these images of handwritten digits into one of 10 classes. \n", "\n", "Amelia knows that to start any AI project, she'll need the right tools. She begins by importing the necessary libraries to set the stage for her digit-reading neural network.\n", "\n", @@ -69,16 +69,16 @@ "source": [ "## 2. Load the MNIST dataset\n", "\n", - "Amelia will need to import the MNIST dataset from the [Keras module](https://keras.io/api/datasets/mnist/). The `train_features` and `test_features` variables contain the training and test images, while `train_labels` and `test_labels` contain the corresponding labels for each item in those datasets. \n", + "Amelia will need to import the MNIST dataset from the [Keras module](https://keras.io/api/datasets/mnist/). The `train_images` and `test_images` variables contain the training and test images, while `train_labels` and `test_labels` contain the corresponding labels for each item in those datasets. \n", "\n", "```python\n", "# Import the MNIST dataset from TensorFlow's Keras datasets module\n", "mnist = tf.keras.datasets.mnist\n", "\n", "# Load the MNIST dataset: \n", - "# - train_features and train_labels are the training images and their corresponding labels.\n", - "# - test_features and test_labels are the testing images and their corresponding labels.\n", - "(train_features,train_labels), (test_features,test_labels) = mnist.load_data()\n", + "# - train_images and train_labels are the training images and their corresponding labels.\n", + "# - test_images and test_labels are the testing images and their corresponding labels.\n", + "(train_images,train_labels), (test_images,test_labels) = mnist.load_data()\n", "```" ] }, @@ -129,14 +129,14 @@ "# Set line width for numpy array printing\n", "np.set_printoptions(linewidth=150)\n", "\n", - "# Select a random number from train_features\n", - "select = np.random.randint(0,len(train_features))\n", + "# Select a random image from train_images\n", + "select = np.random.randint(0,len(train_images))\n", "\n", "# Print the image array - longer line length above should allow it to have all 28 rows in 1 line\n", - "print(train_features[select])\n", + "print(train_images[select])\n", "\n", "# Display the image as an actual image\n", - "plt.imshow(train_features[select], cmap='gray')\n", + "plt.imshow(train_images[select], cmap='gray')\n", "plt.show()\n", "\n", "# Print the true label for the image from train_labels\n", @@ -149,7 +149,7 @@ "source": [ "The ouptut of the cell above should help clarify how images are encoded in our data. Each pixel has a value from 0 (black) to 255 (white). Since our images are black and white, we only have one grid of pixels. For color images, we would have three: one for each color, red, green, blue.\n", "\n", - "Our datasets have 60,000 images in the `train_features` and 10,000 images in the `test_features`. We will use these data as we move forward." + "Our datasets have 60,000 images in `train_images` and 10,000 images in `test_images`. We will use these data as we move forward." ] }, { @@ -158,7 +158,7 @@ "source": [ "## 4. Normalize the data\n", "\n", - "Before we normalize the data, look to see what the current maximum value is in `train_features`." + "Before we normalize the data, look to see what the current maximum value is in `train_images`." ] }, { @@ -167,7 +167,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Code it! What is the max value of train_features?\n" + "# Code it! What is the max value of train_images?\n" ] }, { @@ -183,7 +183,7 @@ "# Normalize the pixel values of the training and testing images to be between 0 and 1.\n", "# This is done by dividing each pixel value by 255 (the maximum pixel value for an 8-bit image).\n", "# Normalizing improves the training process and convergence.\n", - "train_features, test_features = train_features / 255.0, test_features / 255.0\n", + "train_images, test_images = train_images / 255.0, test_images / 255.0\n", "```" ] }, @@ -209,7 +209,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Code it! After normalization, what is the max value of train_features?\n" + "# Code it! After normalization, what is the max value of train_images?\n" ] }, { @@ -332,13 +332,13 @@ "Now, train the model on the MNIST dataset using the `fit` method. Set the training to run for 10 epochs.\n", "\n", "Train the model using the training data:\n", - "* `train_features`: the input images\n", + "* `train_images`: the input images\n", "* `train_labels`: the true labels for each image\n", "* `epochs=10`: the number of times the model will cycle through the entire dataset\n", "\n", "```python\n", "\n", - "model.fit(train_features, train_labels, epochs=10)\n", + "model.fit(train_images, train_labels, epochs=10)\n", "```" ] }, @@ -361,13 +361,13 @@ "\n", "\n", "Evaluate the model's performance using the testing data:\n", - "* `test_features`: the input images from the testing set\n", + "* `test_images`: the input images from the testing set\n", "* `test_labels`: the true labels for each image in the testing set\n", "\n", "The `evaluate` method returns the loss value and any additional metrics (in this case, accuracy) for the model on the testing data.\n", "\n", "```python\n", - "model.evaluate(test_features, test_labels)\n", + "model.evaluate(test_images, test_labels)\n", "```" ] }, @@ -388,7 +388,7 @@ "\n", "Let's see how the model performs on some randomly selected images. Are its predictions correct? \n", "\n", - "Randomly select an image from the test dataset, in this case, the 200th image.\n", + "Select an image from the test dataset, in this case, the 200th image.\n", "\n", "Select a specific image from the test dataset for examination or prediction.\n", "\n", @@ -397,8 +397,8 @@ "```python\n", "loc = 200\n", "\n", - "# Extract the corresponding image from the test_features array and store it in the 'test_image' variable.\n", - "test_image = test_features[loc]\n", + "# Extract the corresponding image from the test_images array and store it in the 'test_image' variable.\n", + "test_image = test_images[loc]\n", "```" ] }, @@ -541,7 +541,7 @@ " * This helps in visually examining the content of the `test_image` (which is represented as a 28x28 array of pixel values).\n", "\n", "```python\n", - "plt.imshow(test_features[loc])\n", + "plt.imshow(test_images[loc])\n", "```" ] }, @@ -587,9 +587,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Tensorflow-2.7.0", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "tensorflow-2.7.0" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -601,7 +601,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.10.2" } }, "nbformat": 4, From 9a5cdd78e1b36d8293bbf76396ba90f346c1268c Mon Sep 17 00:00:00 2001 From: Heather Savoy Date: Tue, 9 Jan 2024 20:38:35 -0700 Subject: [PATCH 3/4] Notebook 3 fixed old and mistyped variable --- 02.2_mnist_classifier.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/02.2_mnist_classifier.ipynb b/02.2_mnist_classifier.ipynb index fbbaf97..87d6c67 100644 --- a/02.2_mnist_classifier.ipynb +++ b/02.2_mnist_classifier.ipynb @@ -200,7 +200,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Look at the maximum value of `train features` after normalization." + "Look at the maximum value of `train_images` after normalization." ] }, { From 92dc706c67bc505a5b07d77e43dbe12b62b33d1c Mon Sep 17 00:00:00 2001 From: BrianStucky-USDA Date: Tue, 9 Jan 2024 23:11:32 -0500 Subject: [PATCH 4/4] One more edit to notebook 3. --- 02.2_mnist_classifier.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/02.2_mnist_classifier.ipynb b/02.2_mnist_classifier.ipynb index fbbaf97..e8b20c1 100644 --- a/02.2_mnist_classifier.ipynb +++ b/02.2_mnist_classifier.ipynb @@ -175,7 +175,7 @@ "metadata": {}, "source": [ "\n", - "Amelia normalizes the data to ensure her AI model can efficiently process these images. Processing your features so that they are represented by numbers between 0 and 1 is a best practice for AI model development.\n", + "Amelia normalizes the data to ensure her AI model can efficiently process these images. Processing your model inputs so that they are represented by numbers between 0 and 1 is a best practice for AI model development.\n", "\n", "Normalize the data by scaling the images so their values are between 0 and 1.\n", "\n",