From d3082f81686617a9af603a94cacfb2c98806b1e4 Mon Sep 17 00:00:00 2001 From: pritesh2000 Date: Fri, 30 Aug 2024 02:11:10 +0530 Subject: [PATCH 1/7] how's it going to function? - typos --- 09_pytorch_model_deployment.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/09_pytorch_model_deployment.ipynb b/09_pytorch_model_deployment.ipynb index 6eca3bf..8a968aa 100644 --- a/09_pytorch_model_deployment.ipynb +++ b/09_pytorch_model_deployment.ipynb @@ -205,10 +205,10 @@ "\n", "These two scenarios are generally referred to as:\n", "\n", - "* **Online (real-time)** - Predicitions/inference happen **immediately**. For example, someone uploads an image, the image gets transformed and predictions are returned or someone makes a purchase and the transaction is verified to be non-fradulent by a model so the purchase can go through.\n", + "* **Online (real-time)** - Predictions/inference happen **immediately**. For example, someone uploads an image, the image gets transformed and predictions are returned or someone makes a purchase and the transaction is verified to be non-fraudulent by a model so the purchase can go through.\n", "* **Offline (batch)** - Predictions/inference happen **periodically**. For example, a photos application sorts your images into different categories (such as beach, mealtime, family, friends) whilst your mobile device is plugged into charge.\n", "\n", - "> **Note:** \"Batch\" refers to inference being performed on multiple samples at a time. However, to add a little confusion, batch processing can happen immediately/online (multiple images being classified at once) and/or offline (mutliple images being predicted/trained on at once). \n", + "> **Note:** \"Batch\" refers to inference being performed on multiple samples at a time. However, to add a little confusion, batch processing can happen immediately/online (multiple images being classified at once) and/or offline (multiple images being predicted/trained on at once). \n", "\n", "The main difference between each being: predictions being made immediately or periodically.\n", "\n", From ad4ca29cd3144128686e0fc09cebd9cba6cb5836 Mon Sep 17 00:00:00 2001 From: pritesh2000 Date: Fri, 30 Aug 2024 02:50:37 +0530 Subject: [PATCH 2/7] ouput -typos --- 09_pytorch_model_deployment.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/09_pytorch_model_deployment.ipynb b/09_pytorch_model_deployment.ipynb index 8a968aa..67424ab 100644 --- a/09_pytorch_model_deployment.ipynb +++ b/09_pytorch_model_deployment.ipynb @@ -631,7 +631,7 @@ "source": [ "Excellent! To change the classifier head to suit our own problem, let's replace the `out_features` variable with the same number of classes we have (in our case, `out_features=3`, one for pizza, steak, sushi).\n", "\n", - "> **Note:** This process of changing the output layers/classifier head will be dependent on the problem you're working on. For example, if you wanted a different *number* of outputs or a different *kind* of ouput, you would have to change the output layers accordingly. " + "> **Note:** This process of changing the output layers/classifier head will be dependent on the problem you're working on. For example, if you wanted a different *number* of outputs or a different *kind* of output, you would have to change the output layers accordingly. " ] }, { @@ -3816,7 +3816,7 @@ " \n", "Nice!\n", "\n", - "See how just like our EffNetB2 model for FoodVision Mini the base layers are frozen (these are pretrained on ImageNet) and the outer layers (the `classifier` layers) are trainble with an ouput shape of `[batch_size, 101]` (`101` for 101 classes in Food101). \n", + "See how just like our EffNetB2 model for FoodVision Mini the base layers are frozen (these are pretrained on ImageNet) and the outer layers (the `classifier` layers) are trainble with an output shape of `[batch_size, 101]` (`101` for 101 classes in Food101). \n", "\n", "Now since we're going to be dealing with a fair bit more data than usual, how about we add a little data augmentation to our transforms (`effnetb2_transforms`) to augment the training data.\n", "\n", From c91af9505265dcb3b726ff61201268df4bb6890d Mon Sep 17 00:00:00 2001 From: pritesh2000 Date: Fri, 30 Aug 2024 03:05:29 +0530 Subject: [PATCH 3/7] assosciated -typos --- 09_pytorch_model_deployment.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/09_pytorch_model_deployment.ipynb b/09_pytorch_model_deployment.ipynb index 67424ab..12bfbbf 100644 --- a/09_pytorch_model_deployment.ipynb +++ b/09_pytorch_model_deployment.ipynb @@ -663,7 +663,7 @@ "\n", "We'll call it `create_effnetb2_model()` and it'll take a customizable number of classes and a random seed parameter for reproducibility.\n", "\n", - "Ideally, it will return an EffNetB2 feature extractor along with its assosciated transforms." + "Ideally, it will return an EffNetB2 feature extractor along with its associated transforms." ] }, { @@ -3069,7 +3069,7 @@ "* `app.py` contains our Gradio app (similar to the code that launched the app).\n", " * **Note:** `app.py` is the default filename used for Hugging Face Spaces, if you deploy your app there, Spaces will by default look for a file called `app.py` to run. This is changable in settings.\n", "* `examples/` contains example images to use with our Gradio app.\n", - "* `model.py` contains the model defintion as well as any transforms assosciated with the model.\n", + "* `model.py` contains the model defintion as well as any transforms associated with the model.\n", "* `requirements.txt` contains the dependencies to run our app such as `torch`, `torchvision` and `gradio`.\n", "\n", "Why this way?\n", @@ -4448,7 +4448,7 @@ "* `app.py` contains our FoodVision Big Gradio app.\n", "* `class_names.txt` contains all of the class names for FoodVision Big.\n", "* `examples/` contains example images to use with our Gradio app.\n", - "* `model.py` contains the model defintion as well as any transforms assosciated with the model.\n", + "* `model.py` contains the model defintion as well as any transforms associated with the model.\n", "* `requirements.txt` contains the dependencies to run our app such as `torch`, `torchvision` and `gradio`." ] }, From 71679e570845f8b8cf9dce7f03ab530f59534d47 Mon Sep 17 00:00:00 2001 From: pritesh2000 Date: Fri, 30 Aug 2024 03:36:24 +0530 Subject: [PATCH 4/7] fix typos --- 09_pytorch_model_deployment.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/09_pytorch_model_deployment.ipynb b/09_pytorch_model_deployment.ipynb index 12bfbbf..ab8ff29 100644 --- a/09_pytorch_model_deployment.ipynb +++ b/09_pytorch_model_deployment.ipynb @@ -1573,7 +1573,7 @@ "2. Create an empty list to store prediction dictionaries (we want the function to return a list of dictionaries, one for each prediction).\n", "3. Loop through the target input paths (steps 4-14 will happen inside the loop).\n", "4. Create an empty dictionary for each iteration in the loop to store prediction values per sample.\n", - "5. Get the sample path and ground truth class name (we can do this by infering the class from the path).\n", + "5. Get the sample path and ground truth class name (we can do this by inferring the class from the path).\n", "6. Start the prediction timer using Python's [`timeit.default_timer()`](https://docs.python.org/3/library/timeit.html#timeit.default_timer).\n", "7. Open the image using [`PIL.Image.open(path)`](https://pillow.readthedocs.io/en/stable/reference/Image.html#functions).\n", "8. Transform the image so it's capable of being used with the target model as well as add a batch dimension and send the image to the target device.\n", @@ -1611,7 +1611,7 @@ " class_names: List[str], \n", " device: str = \"cuda\" if torch.cuda.is_available() else \"cpu\") -> List[Dict]:\n", " \n", - " # 2. Create an empty list to store prediction dictionaires\n", + " # 2. Create an empty list to store prediction dictionaries\n", " pred_list = []\n", " \n", " # 3. Loop through target paths\n", From db7fea212cf4e5333eb6cd52811265e4abf92328 Mon Sep 17 00:00:00 2001 From: pritesh2000 Date: Fri, 30 Aug 2024 03:46:09 +0530 Subject: [PATCH 5/7] corrected some sentences --- 09_pytorch_model_deployment.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/09_pytorch_model_deployment.ipynb b/09_pytorch_model_deployment.ipynb index ab8ff29..9adfed8 100644 --- a/09_pytorch_model_deployment.ipynb +++ b/09_pytorch_model_deployment.ipynb @@ -2298,7 +2298,7 @@ "\n", "To do so, let's turn our `effnetb2_stats` and `vit_stats` dictionaries into a pandas DataFrame.\n", "\n", - "We'll add a column to view the model names as well as the convert the test accuracy to a whole percentage rather than decimal." + "We'll add a column to view the model names as well as convert the test accuracy to a whole percentage rather than decimal." ] }, { @@ -2598,7 +2598,7 @@ "\n", "Why create a demo of your models?\n", "\n", - "Because metrics on the test set look nice but you never really know how you're model performs until you use it in the wild.\n", + "Because metrics on the test set look nice but you never really know how your model performs until you use it in the wild.\n", "\n", "So let's get deploying!\n", "\n", @@ -2700,7 +2700,7 @@ "\n", "We created a function earlier called `pred_and_store()` to make predictions with a given model across a list of target files and store them in a list of dictionaries.\n", "\n", - "How about we create a similar function but this time focusing on a making a prediction on a single image with our EffNetB2 model?\n", + "How about we create a similar function but this time focusing on making a prediction on a single image with our EffNetB2 model?\n", "\n", "More specifically, we want a function that takes an image as input, preprocesses (transforms) it, makes a prediction with EffNetB2 and then returns the prediction (pred or pred label for short) as well as the prediction probability (pred prob).\n", "\n", @@ -3511,7 +3511,7 @@ "\n", "Feel free to read the documentation on both options but we're going to go with option two.\n", "\n", - "> **Note:** To host anything on Hugging Face, you will to [sign up for a free Hugging Face account](https://huggingface.co/join). " + "> **Note:** To host anything on Hugging Face, you will need to [sign up for a free Hugging Face account](https://huggingface.co/join). " ] }, { @@ -4907,7 +4907,7 @@ "4. Select a license (I used [MIT](https://opensource.org/licenses/MIT)).\n", "5. Select Gradio as the Space SDK (software development kit). \n", " * **Note:** You can use other options such as Streamlit but since our app is built with Gradio, we'll stick with that.\n", - "6. Choose whether your Space is it's public or private (I selected public since I'd like my Space to be available to others).\n", + "6. Choose whether your Space is public or private (I selected public since I'd like my Space to be available to others).\n", "7. Click \"Create Space\".\n", "8. Clone the repo locally by running: `git clone https://huggingface.co/spaces/[YOUR_USERNAME]/[YOUR_SPACE_NAME]` in terminal or command prompt.\n", " * **Note:** You can also add files via uploading them under the \"Files and versions\" tab.\n", From 26372b2e8d33871c1665f4f160501f0b818c5f2e Mon Sep 17 00:00:00 2001 From: pritesh2000 Date: Fri, 30 Aug 2024 03:57:51 +0530 Subject: [PATCH 6/7] some more typos --- 09_pytorch_model_deployment.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/09_pytorch_model_deployment.ipynb b/09_pytorch_model_deployment.ipynb index 9adfed8..836b544 100644 --- a/09_pytorch_model_deployment.ipynb +++ b/09_pytorch_model_deployment.ipynb @@ -3067,9 +3067,9 @@ "Where:\n", "* `09_pretrained_effnetb2_feature_extractor_pizza_steak_sushi_20_percent.pth` is our trained PyTorch model file.\n", "* `app.py` contains our Gradio app (similar to the code that launched the app).\n", - " * **Note:** `app.py` is the default filename used for Hugging Face Spaces, if you deploy your app there, Spaces will by default look for a file called `app.py` to run. This is changable in settings.\n", + " * **Note:** `app.py` is the default filename used for Hugging Face Spaces, if you deploy your app there, Spaces will by default look for a file called `app.py` to run. This is changeable in settings.\n", "* `examples/` contains example images to use with our Gradio app.\n", - "* `model.py` contains the model defintion as well as any transforms associated with the model.\n", + "* `model.py` contains the model definition as well as any transforms associated with the model.\n", "* `requirements.txt` contains the dependencies to run our app such as `torch`, `torchvision` and `gradio`.\n", "\n", "Why this way?\n", @@ -3657,7 +3657,7 @@ "source": [ "### 9.3 Uploading to Hugging Face\n", "\n", - "We've verfied our FoodVision Mini app works locally, however, the fun of creating a machine learning demo is to show it to other people and allow them to use it.\n", + "We've verified our FoodVision Mini app works locally, however, the fun of creating a machine learning demo is to show it to other people and allow them to use it.\n", "\n", "To do so, we're going to upload our FoodVision Mini demo to Hugging Face. \n", "\n", From efe3af41bfbb0f5d2a00203cd34a156ef90a1bdd Mon Sep 17 00:00:00 2001 From: pritesh2000 Date: Fri, 30 Aug 2024 04:13:19 +0530 Subject: [PATCH 7/7] all typos done --- 09_pytorch_model_deployment.ipynb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/09_pytorch_model_deployment.ipynb b/09_pytorch_model_deployment.ipynb index 836b544..d6f7085 100644 --- a/09_pytorch_model_deployment.ipynb +++ b/09_pytorch_model_deployment.ipynb @@ -3747,7 +3747,7 @@ "\n", "We'll go from three classes to 101!\n", "\n", - "From pizza, steak, sushi to pizza, steak, sushi, hot dog, apple pie, carrot cake, chocolate cake, french fires, garlic bread, ramen, nachos, tacos and more!\n", + "From pizza, steak, sushi to pizza, steak, sushi, hot dog, apple pie, carrot cake, chocolate cake, french fries, garlic bread, ramen, nachos, tacos and more!\n", "\n", "How?\n", "\n", @@ -3816,7 +3816,7 @@ " \n", "Nice!\n", "\n", - "See how just like our EffNetB2 model for FoodVision Mini the base layers are frozen (these are pretrained on ImageNet) and the outer layers (the `classifier` layers) are trainble with an output shape of `[batch_size, 101]` (`101` for 101 classes in Food101). \n", + "See how just like our EffNetB2 model for FoodVision Mini the base layers are frozen (these are pretrained on ImageNet) and the outer layers (the `classifier` layers) are trainable with an output shape of `[batch_size, 101]` (`101` for 101 classes in Food101). \n", "\n", "Now since we're going to be dealing with a fair bit more data than usual, how about we add a little data augmentation to our transforms (`effnetb2_transforms`) to augment the training data.\n", "\n", @@ -4371,7 +4371,7 @@ "\n", "Our FoodVision Big model is capable of classifying 101 classes versus FoodVision Mini's 3 classes, a 33.6x increase!\n", "\n", - "How does this effect the model size?\n", + "How does this affect the model size?\n", "\n", "Let's find out." ] @@ -4448,7 +4448,7 @@ "* `app.py` contains our FoodVision Big Gradio app.\n", "* `class_names.txt` contains all of the class names for FoodVision Big.\n", "* `examples/` contains example images to use with our Gradio app.\n", - "* `model.py` contains the model defintion as well as any transforms associated with the model.\n", + "* `model.py` contains the model definition as well as any transforms associated with the model.\n", "* `requirements.txt` contains the dependencies to run our app such as `torch`, `torchvision` and `gradio`." ] }, @@ -4521,7 +4521,7 @@ "source": [ "### 11.2 Saving Food101 class names to file (`class_names.txt`)\n", "\n", - "Because there are so many classes in the Food101 dataset, instead of storing them as a list in our `app.py` file, let's saved them to a `.txt` file and read them in when necessary instead.\n", + "Because there are so many classes in the Food101 dataset, instead of storing them as a list in our `app.py` file, let's save them to a `.txt` file and read them in when necessary instead.\n", "\n", "We'll just remind ourselves what they look like first by checking out `food101_class_names`." ] @@ -4708,7 +4708,7 @@ "1. **Imports and class names setup** - The `class_names` variable will be a list for all of the Food101 classes rather than pizza, steak, sushi. We can access these via `demos/foodvision_big/class_names.txt`.\n", "2. **Model and transforms preparation** - The `model` will have `num_classes=101` rather than `num_classes=3`. We'll also be sure to load the weights from `\"09_pretrained_effnetb2_feature_extractor_food101_20_percent.pth\"` (our FoodVision Big model path).\n", "3. **Predict function** - This will stay the same as FoodVision Mini's `app.py`.\n", - "4. **Gradio app** - The Gradio interace will have different `title`, `description` and `article` parameters to reflect the details of FoodVision Big.\n", + "4. **Gradio app** - The Gradio interface will have different `title`, `description` and `article` parameters to reflect the details of FoodVision Big.\n", "\n", "We'll also make sure to save it to `demos/foodvision_big/app.py` using the `%%writefile` magic command." ] @@ -4962,7 +4962,7 @@ } ], "source": [ - "# IPython is a library to help work with Python iteractively \n", + "# IPython is a library to help work with Python interactively\n", "from IPython.display import IFrame\n", "\n", "# Embed FoodVision Big Gradio demo as an iFrame\n", @@ -5024,7 +5024,7 @@ " * What model architecture does it use?\n", "6. Write down 1-3 potential failure points of our deployed FoodVision models and what some potential solutions might be.\n", " * For example, what happens if someone was to upload a photo that wasn't of food to our FoodVision Mini model?\n", - "7. Pick any dataset from [`torchvision.datasets`](https://pytorch.org/vision/stable/datasets.html) and train a feature extractor model on it using a model from [`torchvision.models`](https://pytorch.org/vision/stable/models.html) (you could use one of the model's we've already created, e.g. EffNetB2 or ViT) for 5 epochs and then deploy your model as a Gradio app to Hugging Face Spaces. \n", + "7. Pick any dataset from [`torchvision.datasets`](https://pytorch.org/vision/stable/datasets.html) and train a feature extractor model on it using a model from [`torchvision.models`](https://pytorch.org/vision/stable/models.html) (you could use one of the models we've already created, e.g. EffNetB2 or ViT) for 5 epochs and then deploy your model as a Gradio app to Hugging Face Spaces. \n", " * You may want to pick smaller dataset/make a smaller split of it so training doesn't take too long.\n", " * I'd love to see your deployed models! So be sure to share them in Discord or on the [course GitHub Discussions page](https://github.com/mrdbourke/pytorch-deep-learning/discussions)." ] @@ -5043,7 +5043,7 @@ " * The [Gradio Blocks API](https://gradio.app/docs/#blocks) for more advanced workflows.\n", " * The Hugging Face Course chapter on [how to use Gradio with Hugging Face](https://huggingface.co/course/chapter9/1).\n", "* Edge devices aren't limited to mobile phones, they include small computers like the Raspberry Pi and the PyTorch team have a [fantastic blog post tutorial](https://pytorch.org/tutorials/intermediate/realtime_rpi.html) on deploying a PyTorch model to one.\n", - "* For a fanstastic guide on developing AI and ML-powered applications, see [Google's People + AI Guidebook](https://pair.withgoogle.com/guidebook). One of my favourites is the section on [setting the right expectations](https://pair.withgoogle.com/guidebook/patterns#set-the-right-expectations).\n", + "* For a fantastic guide on developing AI and ML-powered applications, see [Google's People + AI Guidebook](https://pair.withgoogle.com/guidebook). One of my favourites is the section on [setting the right expectations](https://pair.withgoogle.com/guidebook/patterns#set-the-right-expectations).\n", " * I covered more of these kinds of resources, including guides from Apple, Microsoft and more in the [April 2021 edition of Machine Learning Monthly](https://zerotomastery.io/blog/machine-learning-monthly-april-2021/) (a monthly newsletter I send out with the latest and greatest of the ML field).\n", "* If you'd like to speed up your model's runtime on CPU, you should be aware of [TorchScript](https://pytorch.org/tutorials/beginner/Intro_to_TorchScript_tutorial.html), [ONNX](https://pytorch.org/docs/stable/onnx.html) (Open Neural Network Exchange) and [OpenVINO](https://docs.openvino.ai/latest/notebooks/102-pytorch-onnx-to-openvino-with-output.html). Going from pure PyTorch to ONNX/OpenVINO models I've seen a ~2x+ increase in performance.\n", "* For turning models into a deployable and scalable API, see the [TorchServe library](https://pytorch.org/serve/).\n",