Skip to content

Commit

Permalink
Update LA4.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
atticus-carter committed Sep 9, 2024
1 parent 607795f commit 647a6a6
Showing 1 changed file with 174 additions and 21 deletions.
195 changes: 174 additions & 21 deletions book/LA4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,180 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Understanding CV Metrics and Graphs "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"test text"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"print('this is a test')"
"# Understanding CV Metrics and Graphs\n",
"\n",
"In this lesson, we will dive deep into the essential **metrics and graphs** used to evaluate computer vision models during training and after deployment. Understanding these metrics is crucial for diagnosing issues like overfitting and underfitting, as well as improving model performance. We will cover key metrics such as **accuracy**, **precision**, **mAP (mean Average Precision)**, and discuss important concepts like **training loss** and **validation loss**, and their associated graphs.\n",
"\n",
"---\n",
"\n",
"## Learning Objectives\n",
"\n",
"By the end of this section, you will:\n",
"- Understand the importance of key metrics such as **accuracy**, **precision**, **mAP**, and **F1 score** for evaluating model performance.\n",
"- Learn how to interpret graphs for **training loss**, **validation loss**, and accuracy.\n",
"- Recognize the signs of **overfitting** and **underfitting**, and understand how to address these issues.\n",
"- Gain practical knowledge of how these metrics relate to model generalization and performance on unseen data.\n",
"\n",
"---\n",
"\n",
"## Key Metrics in Computer Vision\n",
"\n",
"Computer vision models are evaluated using several metrics that provide insight into how well the model is performing on both training and unseen data. Here, we break down some of the most important metrics used in image classification, object detection, and segmentation tasks.\n",
"\n",
"### Accuracy\n",
"\n",
"**Accuracy** measures the percentage of correct predictions out of the total predictions made by the model.\n",
"\n",
"#### Formula:\n",
"\\[\n",
"\\text{Accuracy} = \\frac{\\text{Correct Predictions}}{\\text{Total Predictions}} \\times 100\n",
"\\]\n",
"\n",
"While accuracy is a good metric when classes are balanced, it can be misleading in cases where the dataset is imbalanced. For example, in a marine species detection task, if 95% of the dataset consists of images without fish, a model that predicts \"no fish\" 100% of the time would still have high accuracy despite being ineffective.\n",
"\n",
"---\n",
"\n",
"### Precision\n",
"\n",
"**Precision** measures how many of the predicted positive instances (e.g., correctly classified images) are actually correct.\n",
"\n",
"#### Formula:\n",
"\\[\n",
"\\text{Precision} = \\frac{\\text{True Positives}}{\\text{True Positives} + \\text{False Positives}}\n",
"\\]\n",
"\n",
"Precision is useful in scenarios where false positives are costly, such as in object detection, where incorrectly classifying background elements as objects would reduce precision.\n",
"\n",
"**Use Case**: In a marine species classification task, high precision ensures that when the model predicts the presence of a species (e.g., fish), it is more likely to be correct.\n",
"\n",
"---\n",
"\n",
"### Recall\n",
"\n",
"**Recall** measures how many of the actual positive instances were correctly identified by the model.\n",
"\n",
"#### Formula:\n",
"\\[\n",
"\\text{Recall} = \\frac{\\text{True Positives}}{\\text{True Positives} + \\text{False Negatives}}\n",
"\\]\n",
"\n",
"**Use Case**: In underwater species detection, recall is crucial if it’s important not to miss any instances of a rare species. High recall ensures the model detects as many true positives as possible, even at the cost of a few false positives.\n",
"\n",
"---\n",
"\n",
"### F1 Score\n",
"\n",
"The **F1 Score** is the harmonic mean of precision and recall. It balances the trade-off between the two metrics, especially when dealing with imbalanced datasets.\n",
"\n",
"#### Formula:\n",
"\\[\n",
"F1 = 2 \\times \\frac{\\text{Precision} \\times \\text{Recall}}{\\text{Precision} + \\text{Recall}}\n",
"\\]\n",
"\n",
"**Use Case**: F1 score is particularly useful in marine imagery with imbalanced datasets, such as detecting small or rare species.\n",
"\n",
"---\n",
"\n",
"### Mean Average Precision (mAP)\n",
"\n",
"In object detection tasks, the **mean Average Precision (mAP)** is a widely used metric that evaluates how well the model predicts the bounding boxes for multiple classes.\n",
"\n",
"#### Formula:\n",
"mAP is calculated by averaging the **Average Precision (AP)** across all classes:\n",
"\\[\n",
"\\text{mAP} = \\frac{1}{n} \\sum_{i=1}^{n} AP_i\n",
"\\]\n",
"\n",
"- **AP** measures the area under the precision-recall curve for each class.\n",
"- **mAP** is the mean of these values across all classes, providing a single metric to evaluate model performance.\n",
"\n",
"**Use Case**: In a marine object detection task where you are detecting multiple species or objects (e.g., fish, crabs, underwater debris), mAP provides a more comprehensive metric than accuracy alone, as it considers both the precision and recall of bounding boxes.\n",
"\n",
"---\n",
"\n",
"## Training and Validation Loss\n",
"\n",
"### Training Loss\n",
"\n",
"**Training loss** measures how well the model is performing on the training data. It is calculated by comparing the model’s predictions to the actual labels and computing a loss function (e.g., **categorical cross-entropy** for classification tasks).\n",
"\n",
"#### Interpretation:\n",
"- **Decreasing Training Loss**: A decreasing training loss indicates that the model is learning from the data.\n",
"- **Low Training Loss**: If the training loss is too low while the validation loss is high, the model may be **overfitting** to the training data.\n",
"\n",
"---\n",
"\n",
"### Validation Loss\n",
"\n",
"**Validation loss** measures how well the model is performing on the validation dataset, which is not seen by the model during training. It is crucial for evaluating the model's ability to generalize to new data.\n",
"\n",
"#### Interpretation:\n",
"- **Increasing Validation Loss**: If the validation loss increases while the training loss decreases, it suggests the model is overfitting.\n",
"- **Balanced Validation Loss**: If the validation loss decreases and converges alongside the training loss, the model is likely generalizing well.\n",
"\n",
"---\n",
"\n",
"### Overfitting and Underfitting\n",
"\n",
"#### Overfitting\n",
"\n",
"**Overfitting** occurs when the model learns too much from the training data, capturing noise and patterns that do not generalize to unseen data. This results in:\n",
"- **Low training loss** but **high validation loss**.\n",
"- Poor performance on the test dataset.\n",
"\n",
"#### How to Address Overfitting:\n",
"- **Early stopping**: Stop training when the validation loss starts increasing.\n",
"- **Data augmentation**: Increase the variety of the training data by applying transformations like rotation, flipping, or scaling.\n",
"- **Regularization**: Techniques like **dropout** or **L2 regularization** can help prevent overfitting by making the model less complex.\n",
"\n",
"---\n",
"\n",
"#### Underfitting\n",
"\n",
"**Underfitting** occurs when the model is too simple and fails to learn the underlying patterns in the data. This results in:\n",
"- **High training loss** and **high validation loss**.\n",
"- Poor performance on both training and test datasets.\n",
"\n",
"#### How to Address Underfitting:\n",
"- **Increase model complexity**: Add more layers or units to the model.\n",
"- **Train for more epochs**: Ensure the model has enough time to learn from the data.\n",
"- **Use better features**: Improve the quality or variety of the training data.\n",
"\n",
"---\n",
"\n",
"## Training and Validation Accuracy\n",
"\n",
"### Training Accuracy\n",
"\n",
"**Training accuracy** refers to the model's accuracy on the training dataset. A high training accuracy means that the model is able to correctly classify a large portion of the training data.\n",
"\n",
"#### Interpretation:\n",
"- **Increasing Training Accuracy**: A steadily increasing training accuracy is a good sign that the model is learning.\n",
"- **Too High Training Accuracy**: If training accuracy becomes very high, but validation accuracy is low, this could indicate **overfitting**.\n",
"\n",
"---\n",
"\n",
"### Validation Accuracy\n",
"\n",
"**Validation accuracy** is the model's accuracy on the validation dataset, which represents its ability to generalize to new, unseen data.\n",
"\n",
"#### Interpretation:\n",
"- **Balanced Training and Validation Accuracy**: If training and validation accuracy rise together, this indicates a well-performing model.\n",
"- **Validation Accuracy Drops**: If validation accuracy decreases while training accuracy increases, this suggests **overfitting**.\n",
"\n",
"---\n",
"\n",
"## Graphs: Training vs Validation Metrics\n",
"\n",
"### Loss Graphs\n",
"\n",
"- **Training Loss vs Validation Loss**: A typical loss graph should show both training and validation loss decreasing over time. If validation loss starts to increase while training loss decreases, it indicates overfitting.\n",
"\n",
"### Accuracy Graphs\n",
"\n",
"- **Training Accuracy vs Validation Accuracy**: The accuracy graph should ideally show both training and validation accuracy increasing. If the gap between training and validation accuracy becomes too large, the model may be overfitting.\n",
"\n",
"---\n"
]
}
],
Expand Down

0 comments on commit 647a6a6

Please sign in to comment.