<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tanmay P. Tawade</title>
    <description>The latest articles on DEV Community by Tanmay P. Tawade (@tanmayt134).</description>
    <link>https://dev.to/tanmayt134</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3713868%2Fb58c030b-2c62-40dd-8450-213488fac4b8.png</url>
      <title>DEV Community: Tanmay P. Tawade</title>
      <link>https://dev.to/tanmayt134</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tanmayt134"/>
    <language>en</language>
    <item>
      <title>🔍 Understanding Model Predictions with Grad-CAM</title>
      <dc:creator>Tanmay P. Tawade</dc:creator>
      <pubDate>Wed, 19 Aug 2026 14:57:32 +0000</pubDate>
      <link>https://dev.to/tanmayt134/understanding-model-predictions-with-grad-cam-34lk</link>
      <guid>https://dev.to/tanmayt134/understanding-model-predictions-with-grad-cam-34lk</guid>
      <description>&lt;h2&gt;
  
  
  🧠 My Model Could Predict. But Could I Understand Why?
&lt;/h2&gt;

&lt;p&gt;In my previous posts, I focused on building and improving my first CNN for brain tumor classification using MRI images.&lt;/p&gt;

&lt;p&gt;The model could take an MRI image and predict one of four classes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Glioma&lt;/li&gt;
&lt;li&gt;Meningioma&lt;/li&gt;
&lt;li&gt;Pituitary&lt;/li&gt;
&lt;li&gt;No Tumor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But after getting the prediction, I started asking a different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Why did the model make this prediction?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A classification result such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prediction: Glioma
Confidence: 91%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;tells me &lt;strong&gt;what&lt;/strong&gt; the model predicted.&lt;/p&gt;

&lt;p&gt;It doesn't tell me &lt;strong&gt;which part of the MRI influenced that prediction.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That is where &lt;strong&gt;Grad-CAM&lt;/strong&gt; became useful in my project.&lt;/p&gt;




&lt;h2&gt;
  
  
  🤔 Why Is Explainability Important?
&lt;/h2&gt;

&lt;p&gt;For a normal image classification problem, seeing the predicted class might be enough for a basic demonstration.&lt;/p&gt;

&lt;p&gt;But medical imaging is different.&lt;/p&gt;

&lt;p&gt;If a model predicts that an MRI contains a tumor, I don't want to look only at the final class.&lt;/p&gt;

&lt;p&gt;I also want to investigate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where was the model focusing?&lt;/li&gt;
&lt;li&gt;Was it looking at a meaningful region?&lt;/li&gt;
&lt;li&gt;Was it focusing on the suspected tumor area?&lt;/li&gt;
&lt;li&gt;Could the model be using some irrelevant visual pattern?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This doesn't mean that an explanation automatically makes the model correct.&lt;/p&gt;

&lt;p&gt;Instead, it gives us another way to &lt;strong&gt;inspect the model's behavior.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That became an important part of my project.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 What Is Grad-CAM?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Grad-CAM (Gradient-weighted Class Activation Mapping)&lt;/strong&gt; is a technique used to visualize the regions of an image that contributed to a CNN's prediction for a particular class.&lt;/p&gt;

&lt;p&gt;Instead of only getting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input MRI → CNN → Prediction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can visualize something closer to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input MRI
    ↓
CNN prediction
    ↓
Grad-CAM
    ↓
Important regions highlighted
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is usually represented as a &lt;strong&gt;heatmap&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Regions with stronger activation are highlighted more strongly, allowing us to visually inspect where the model was focusing.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ How Grad-CAM Works — Conceptually
&lt;/h2&gt;

&lt;p&gt;The mathematics behind Grad-CAM can become fairly detailed, but the basic idea is easier to understand as a sequence.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 — Give the MRI image to the CNN
&lt;/h3&gt;

&lt;p&gt;The preprocessed MRI image is passed through the trained CNN.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MRI Image
    ↓
Preprocessing
    ↓
CNN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 2 — Get the model's prediction
&lt;/h3&gt;

&lt;p&gt;The CNN produces probabilities for the different classes.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Glioma       → 0.91
Meningioma   → 0.04
Pituitary    → 0.03
No Tumor     → 0.02
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The highest probability becomes the predicted class.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3 — Select the target class
&lt;/h3&gt;

&lt;p&gt;Grad-CAM focuses on the class we want to investigate.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Target class → Glioma
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then examine how the model's internal feature maps contributed to that class.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4 — Calculate gradients
&lt;/h3&gt;

&lt;p&gt;Grad-CAM uses the gradients of the target class with respect to the feature maps of a convolutional layer.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Target class
     ↓
Gradients
     ↓
Feature maps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The gradients indicate how important different feature-map activations are for the selected prediction.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 5 — Create the heatmap
&lt;/h3&gt;

&lt;p&gt;The feature maps are combined using their importance weights to produce a coarse spatial heatmap.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature Maps
      +
Gradient Weights
      ↓
Grad-CAM Heatmap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 6 — Overlay the heatmap
&lt;/h3&gt;

&lt;p&gt;Finally, the heatmap can be resized and overlaid on the original MRI.&lt;/p&gt;

&lt;p&gt;This gives us a visual representation of the regions that were important to the model's prediction.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 The Complete Grad-CAM Pipeline
&lt;/h2&gt;

&lt;p&gt;Here is the complete process I used conceptually in my project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkeojsi6ps3ly5bexmfno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkeojsi6ps3ly5bexmfno.png" alt="Grad-CAM Pipeline" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The important thing to remember is that Grad-CAM comes &lt;strong&gt;after the model has already learned and made a prediction&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It doesn't change the prediction.&lt;/p&gt;

&lt;p&gt;It helps us investigate it.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Grad-CAM in My Brain MRI Project
&lt;/h2&gt;

&lt;p&gt;I applied Grad-CAM to my trained CNN to visualize the regions that contributed to its predictions.&lt;/p&gt;

&lt;p&gt;The basic workflow was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MRI Image
    ↓
Preprocessing
    ↓
Trained CNN
    ↓
Predicted Class
    ↓
Gradients of Target Class
    ↓
Feature Maps
    ↓
Grad-CAM Heatmap
    ↓
Overlay on MRI
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allowed me to move from simply looking at the prediction to actually inspecting the model's focus.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔬 Grad-CAM in Action
&lt;/h2&gt;

&lt;p&gt;The following example shows the idea more clearly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9ofxh4wi9ewo7ct9fx8y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9ofxh4wi9ewo7ct9fx8y.png" alt="Grad-CAM in Action" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The original MRI is passed through the model.&lt;/p&gt;

&lt;p&gt;The model produces a prediction, and Grad-CAM generates a heatmap showing the regions associated with that prediction.&lt;/p&gt;

&lt;p&gt;The final overlay makes the explanation easier to interpret visually.&lt;/p&gt;

&lt;p&gt;One important detail:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The highlighted region represents where the model was focusing for that prediction. It should not be interpreted as an exact tumor boundary.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This distinction is especially important in medical imaging.&lt;/p&gt;




&lt;h2&gt;
  
  
  🖼️ Example 1 — No-Tumor Prediction
&lt;/h2&gt;

&lt;p&gt;Here is an example where the model predicted a no-tumor image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh24cqra7okiu2s3vpwra.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh24cqra7okiu2s3vpwra.png" alt="Grad-CAM No Tumor Example" width="639" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The heatmap provides a visual indication of the regions that contributed to the prediction.&lt;/p&gt;

&lt;p&gt;But it is important not to assume that every highlighted pixel has a direct medical meaning.&lt;/p&gt;

&lt;p&gt;Grad-CAM is showing the model's learned visual associations—not a medically validated segmentation mask.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Example 2 — Tumor Prediction
&lt;/h2&gt;

&lt;p&gt;Now consider an MRI containing a visible tumor region.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5pb1i9xfog14fiojij97.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5pb1i9xfog14fiojij97.png" alt="Grad-CAM Tumor Example" width="639" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, the strongest activation is around the visible abnormal region.&lt;/p&gt;

&lt;p&gt;That is interesting because it suggests that the model was focusing on a region that appears relevant to the classification.&lt;/p&gt;

&lt;p&gt;However, this should still be treated as &lt;strong&gt;model interpretation&lt;/strong&gt;, not proof that the model has correctly identified the tumor.&lt;/p&gt;

&lt;p&gt;That distinction matters.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Why Explainability Matters
&lt;/h2&gt;

&lt;p&gt;This changed how I looked at my CNN project.&lt;/p&gt;

&lt;p&gt;Before using Grad-CAM, I mainly focused on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Accuracy
Precision
Recall
F1-score
Prediction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After exploring explainability, I also started asking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What is the model looking at?
Why might it be making this prediction?
Is the model focusing on a meaningful region?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fggwr2ie9bpih3r2eed1x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fggwr2ie9bpih3r2eed1x.png" alt="Why Explainability Matters" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Grad-CAM doesn't make a model automatically trustworthy.&lt;/p&gt;

&lt;p&gt;Instead, it gives us another tool for &lt;strong&gt;examining model behavior and identifying potential problems.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ What Grad-CAM Can and Cannot Tell Us
&lt;/h2&gt;

&lt;p&gt;This was probably the most important thing I learned.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Grad-CAM can help us:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Visualize important regions for a prediction&lt;/li&gt;
&lt;li&gt;Inspect what the CNN appears to focus on&lt;/li&gt;
&lt;li&gt;Identify potentially suspicious model behavior&lt;/li&gt;
&lt;li&gt;Compare model attention across different images&lt;/li&gt;
&lt;li&gt;Make CNN predictions easier to investigate&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Grad-CAM cannot guarantee:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;That the prediction is correct&lt;/li&gt;
&lt;li&gt;That the highlighted region is the exact tumor boundary&lt;/li&gt;
&lt;li&gt;That the model understands the medical meaning of the highlighted area&lt;/li&gt;
&lt;li&gt;That the model is clinically reliable&lt;/li&gt;
&lt;li&gt;That the explanation itself proves causation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A heatmap is an explanation of model behavior, not a medical diagnosis.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧪 What I Learned From Implementing Grad-CAM
&lt;/h2&gt;

&lt;p&gt;Implementing Grad-CAM taught me something beyond the technique itself.&lt;/p&gt;

&lt;p&gt;Earlier, I thought machine learning was mainly about improving metrics.&lt;/p&gt;

&lt;p&gt;Now I see another important side:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Understanding why a model behaves the way it does is also part of building a good ML system.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The process also made me more careful about how I interpret model results.&lt;/p&gt;

&lt;p&gt;A high-confidence prediction can still be wrong.&lt;/p&gt;

&lt;p&gt;And a visually convincing heatmap does not automatically mean the model has learned the correct reasoning.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 From Building a CNN to Understanding It
&lt;/h2&gt;

&lt;p&gt;This four-part learning journey changed how I approached my first CNN project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Part 1 — Building my first CNN
&lt;/h3&gt;

&lt;p&gt;I learned what changes when CNN theory becomes actual code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Part 2 — Mistakes
&lt;/h3&gt;

&lt;p&gt;I learned that good-looking accuracy doesn't necessarily mean good model performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Part 3 — Building the model
&lt;/h3&gt;

&lt;p&gt;I understood the basic workflow from preprocessing to training and evaluation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Part 4 — Grad-CAM
&lt;/h3&gt;

&lt;p&gt;I learned to look beyond the prediction and investigate &lt;strong&gt;where the model was focusing.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The bigger lesson for me was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Building the model is only one part of machine learning. Understanding its behavior is another.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🚀 What's Next?
&lt;/h2&gt;

&lt;p&gt;This project started as an academic exercise to understand CNN-based image classification.&lt;/p&gt;

&lt;p&gt;It gradually became an opportunity to explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data preprocessing&lt;/li&gt;
&lt;li&gt;CNN architecture&lt;/li&gt;
&lt;li&gt;Model evaluation&lt;/li&gt;
&lt;li&gt;Multi-class classification&lt;/li&gt;
&lt;li&gt;Explainable AI&lt;/li&gt;
&lt;li&gt;Responsible interpretation of AI predictions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is still a lot I want to improve, especially around model evaluation, dataset quality, explainability techniques, and making the overall system more robust.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔗 Explore the Project
&lt;/h2&gt;

&lt;p&gt;The complete implementation is available on GitHub:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/TanmayT134/Explainable-Brain-Tumor-Detection" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also deployed a working demonstration using Streamlit:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://brain-mri-ai.streamlit.app/" rel="noopener noreferrer"&gt;Live Streamlit Demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The project includes the CNN-based classification workflow along with Grad-CAM-based visualization for model interpretation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; This project is an academic decision-support prototype for learning and experimentation. It is &lt;strong&gt;not intended to replace professional medical diagnosis or clinical decision-making.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  💬 Final Thought
&lt;/h2&gt;

&lt;p&gt;My biggest takeaway from this project wasn't simply:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I built a CNN."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"I started learning how to question what my model was doing."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That shift—from &lt;strong&gt;getting a prediction&lt;/strong&gt; to &lt;strong&gt;investigating the prediction&lt;/strong&gt;—was one of the most valuable things I learned while building this project.&lt;/p&gt;




&lt;h2&gt;
  
  
  👨🏻‍💻 Let's Connect
&lt;/h2&gt;

&lt;p&gt;I'm continuing to learn and build projects around &lt;strong&gt;Java, web development, machine learning, and AI/ML&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you're also learning CNNs, computer vision, or explainable AI, I'd be happy to hear about your experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What was the first thing you used to understand what your ML model was actually learning?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's connect and learn together. 🚀&lt;/p&gt;




&lt;h3&gt;
  
  
  👨🏻‍💻 About Me
&lt;/h3&gt;

&lt;p&gt;I'm &lt;strong&gt;Tanmay P. Tawade&lt;/strong&gt;, a Full Stack Developer focused on &lt;strong&gt;Java and web development&lt;/strong&gt;, with an interest in &lt;strong&gt;AI/ML and practical software projects&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I write about what I learn while building projects, experimenting with technologies, and turning concepts into working software.&lt;/p&gt;

&lt;p&gt;🔗 &lt;a href="https://github.com/TanmayT134" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;&lt;br&gt;
🌐 &lt;a href="https://portfolio-tanmay-tawade.vercel.app/" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;br&gt;&lt;br&gt;
💼 &lt;a href="https://www.linkedin.com/in/tanmay-tawade-995829344/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>deeplearning</category>
      <category>cnn</category>
      <category>python</category>
    </item>
    <item>
      <title>⚙️ How I Built My First CNN for Brain Tumor Classification</title>
      <dc:creator>Tanmay P. Tawade</dc:creator>
      <pubDate>Sun, 16 Aug 2026 05:49:20 +0000</pubDate>
      <link>https://dev.to/tanmayt134/how-i-built-my-first-cnn-for-brain-tumor-classification-5kf</link>
      <guid>https://dev.to/tanmayt134/how-i-built-my-first-cnn-for-brain-tumor-classification-5kf</guid>
      <description>&lt;h2&gt;
  
  
  🧠 From "I Know CNNs" to Actually Building One
&lt;/h2&gt;

&lt;p&gt;In my previous two posts, I talked about what I learned and the mistakes I made while working on my first CNN project.&lt;/p&gt;

&lt;p&gt;Now I want to show what I actually built.&lt;/p&gt;

&lt;p&gt;The project is an &lt;strong&gt;MRI-based brain tumor detection and classification system&lt;/strong&gt; using a custom Convolutional Neural Network (CNN).&lt;/p&gt;

&lt;p&gt;The model classifies MRI images into four categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Glioma&lt;/li&gt;
&lt;li&gt;Meningioma&lt;/li&gt;
&lt;li&gt;Pituitary&lt;/li&gt;
&lt;li&gt;No Tumor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The project also integrates &lt;strong&gt;Grad-CAM&lt;/strong&gt; to visualize which regions of an MRI contributed most to a prediction.&lt;/p&gt;

&lt;p&gt;The final system was then wrapped in a &lt;strong&gt;Streamlit web application&lt;/strong&gt; so that the trained model could be used through an interactive interface.&lt;/p&gt;

&lt;p&gt;This post focuses on the implementation pipeline rather than explaining CNN theory from scratch.&lt;/p&gt;




&lt;h2&gt;
  
  
  🗺️ The Overall Pipeline
&lt;/h2&gt;

&lt;p&gt;The system can be thought of as a sequence:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MRI Image&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Image Preprocessing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CNN Classification&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Softmax Probability Distribution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prediction + Confidence Analysis&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Grad-CAM Visualization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Report Generation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Streamlit Interface&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This pipeline helped me understand that a machine learning project is much more than the model itself.&lt;/p&gt;

&lt;p&gt;The model is one component inside a larger system.&lt;/p&gt;




&lt;h2&gt;
  
  
  📊 Step 1 — Understanding the Dataset
&lt;/h2&gt;

&lt;p&gt;The project uses a publicly available brain MRI dataset containing four categories:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Class&lt;/th&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🧠&lt;/td&gt;
&lt;td&gt;Glioma&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🧠&lt;/td&gt;
&lt;td&gt;Meningioma&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🧠&lt;/td&gt;
&lt;td&gt;Pituitary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🧠&lt;/td&gt;
&lt;td&gt;No Tumor&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Before training, the images were organized into training and testing data while maintaining class representation.&lt;/p&gt;

&lt;p&gt;One of the lessons from my previous post became important here:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Don't start with the CNN. Start with the data.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Understanding the labels, class distribution, image quality, and visual characteristics of the dataset gave me a much better starting point.&lt;/p&gt;




&lt;h2&gt;
  
  
  🖼️ Step 2 — Preprocessing the MRI Images
&lt;/h2&gt;

&lt;p&gt;Raw images are not automatically ready to be passed into a CNN.&lt;/p&gt;

&lt;p&gt;The project uses a preprocessing pipeline to make the input more consistent.&lt;/p&gt;

&lt;p&gt;The main steps are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;RGB image conversion&lt;/li&gt;
&lt;li&gt;Brain region extraction&lt;/li&gt;
&lt;li&gt;Contrast enhancement&lt;/li&gt;
&lt;li&gt;Gaussian noise reduction&lt;/li&gt;
&lt;li&gt;Image resizing&lt;/li&gt;
&lt;li&gt;Pixel normalization&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The final input size used by the model is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;224 × 224 pixels&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The purpose wasn't to make the images "perfect."&lt;/p&gt;

&lt;p&gt;It was to provide the model with a more consistent representation of the input data.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Why Preprocessing Matters
&lt;/h2&gt;

&lt;p&gt;This was another area where implementation changed my understanding.&lt;/p&gt;

&lt;p&gt;I initially thought of preprocessing as simply:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Resize the image and normalize it."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But in an image-classification project, preprocessing can influence what information the model actually sees.&lt;/p&gt;

&lt;p&gt;For this project, I wanted to reduce irrelevant variation while preserving useful visual information.&lt;/p&gt;

&lt;p&gt;The preprocessing pipeline therefore became an important part of the overall model design.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Step 3 — Building the CNN
&lt;/h2&gt;

&lt;p&gt;For the classification model, I used a &lt;strong&gt;custom CNN architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The main components are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Convolutional layers&lt;/li&gt;
&lt;li&gt;ReLU activation&lt;/li&gt;
&lt;li&gt;Max pooling&lt;/li&gt;
&lt;li&gt;Dropout regularization&lt;/li&gt;
&lt;li&gt;Fully connected dense layers&lt;/li&gt;
&lt;li&gt;Softmax output layer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The basic idea is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Image&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convolution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feature Extraction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pooling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deeper Feature Extraction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dense Layers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Softmax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4-Class Prediction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The earlier convolutional layers learn lower-level visual patterns, while deeper layers can combine those patterns into more complex representations.&lt;/p&gt;

&lt;p&gt;The final softmax layer produces probabilities across the four classes.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔢 Step 4 — Why Softmax?
&lt;/h2&gt;

&lt;p&gt;Because this is a &lt;strong&gt;four-class classification problem&lt;/strong&gt;, the model needs to produce a probability distribution across all four possible classes.&lt;/p&gt;

&lt;p&gt;For example, an output might look conceptually like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Glioma       → 0.02
Meningioma   → 0.91
Pituitary    → 0.04
No Tumor     → 0.03
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The class with the highest predicted probability becomes the model's predicted class.&lt;/p&gt;

&lt;p&gt;But this is where I had to remember something from Part 2:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A high probability is not the same thing as certainty.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The probability output is useful for understanding the model's prediction, but it should always be interpreted in the context of the model's evaluation and limitations.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Step 5 — Training the Model
&lt;/h2&gt;

&lt;p&gt;Once the preprocessing pipeline and CNN architecture were ready, the next step was training.&lt;/p&gt;

&lt;p&gt;This is where the earlier mistakes started becoming useful.&lt;/p&gt;

&lt;p&gt;Instead of treating training as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run → Get Accuracy → Done&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I started paying attention to what was happening during training.&lt;/p&gt;

&lt;p&gt;I looked at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Training loss&lt;/li&gt;
&lt;li&gt;Validation loss&lt;/li&gt;
&lt;li&gt;Training accuracy&lt;/li&gt;
&lt;li&gt;Validation accuracy&lt;/li&gt;
&lt;li&gt;Precision&lt;/li&gt;
&lt;li&gt;Recall&lt;/li&gt;
&lt;li&gt;F1-score&lt;/li&gt;
&lt;li&gt;Confusion matrix&lt;/li&gt;
&lt;li&gt;Changes in performance across experiments&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔄 Training Wasn't Just "Press Run"
&lt;/h3&gt;

&lt;p&gt;One of the biggest changes in my approach was that I stopped treating training as a single event.&lt;/p&gt;

&lt;p&gt;A typical experiment became:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Choose configuration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Train the model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitor training and validation behavior&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Evaluate the results&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Identify problems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Modify the configuration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Train again&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This made the process much more iterative.&lt;/p&gt;

&lt;p&gt;For example, if training performance continued improving while validation performance stopped improving, that raised a question about &lt;strong&gt;overfitting&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of simply celebrating the higher training accuracy, I had to look at what was happening on data the model wasn't directly learning from.&lt;/p&gt;

&lt;h3&gt;
  
  
  ⚙️ What I Experimented With
&lt;/h3&gt;

&lt;p&gt;During development, I experimented with model configuration and training choices such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model architecture&lt;/li&gt;
&lt;li&gt;Learning rate&lt;/li&gt;
&lt;li&gt;Number of epochs&lt;/li&gt;
&lt;li&gt;Batch size&lt;/li&gt;
&lt;li&gt;Regularization&lt;/li&gt;
&lt;li&gt;Data preprocessing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The important lesson wasn't that one particular value was "correct."&lt;/p&gt;

&lt;p&gt;It was that these choices should be treated as &lt;strong&gt;experiments rather than magic numbers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I wanted to understand:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What am I changing?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why am I changing it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What effect should I expect?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Did the result actually improve?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That mindset made training much more meaningful than simply trying different values until the accuracy increased.&lt;/p&gt;




&lt;h2&gt;
  
  
  📈 Step 6 — Evaluating the Model
&lt;/h2&gt;

&lt;p&gt;The final evaluation wasn't based on accuracy alone.&lt;/p&gt;

&lt;p&gt;The project evaluates the model using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accuracy&lt;/li&gt;
&lt;li&gt;Precision&lt;/li&gt;
&lt;li&gt;Recall&lt;/li&gt;
&lt;li&gt;F1-score&lt;/li&gt;
&lt;li&gt;Confusion matrix&lt;/li&gt;
&lt;li&gt;Softmax probability distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The current project documentation reports an overall classification accuracy of approximately &lt;strong&gt;91%&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But the number I found more interesting was not the accuracy itself.&lt;/p&gt;

&lt;p&gt;It was being able to look at the model from multiple perspectives.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Which classes are being confused?&lt;/p&gt;

&lt;p&gt;Is the model performing consistently across classes?&lt;/p&gt;

&lt;p&gt;Are the predictions supported by reasonable confidence values?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Those questions provide much more context than a single accuracy number.&lt;/p&gt;

&lt;h3&gt;
  
  
  📊 Looking Beyond Accuracy
&lt;/h3&gt;

&lt;p&gt;For a multi-class classifier, the confusion matrix can reveal patterns that overall accuracy hides.&lt;/p&gt;

&lt;p&gt;For example, if the model correctly identifies most images from one class but frequently confuses another class with a similar category, the overall accuracy may not immediately communicate how important that problem is.&lt;/p&gt;

&lt;p&gt;This connected directly to the lesson from Part 2:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A model should be evaluated by how it behaves across classes, not just by one overall number.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔥 Step 7 — Adding Grad-CAM
&lt;/h2&gt;

&lt;p&gt;After getting the classifier working, I wanted to answer another question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What part of the MRI is influencing the prediction?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is where &lt;strong&gt;Grad-CAM (Gradient-weighted Class Activation Mapping)&lt;/strong&gt; became part of the project.&lt;/p&gt;

&lt;p&gt;Grad-CAM generates a heatmap showing image regions that contribute most to the model's prediction.&lt;/p&gt;

&lt;p&gt;The workflow becomes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MRI Image&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CNN Prediction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Target Class&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Grad-CAM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Heatmap&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This doesn't give me an exact tumor segmentation.&lt;/p&gt;

&lt;p&gt;Instead, it provides a visual way to inspect the regions that were influential for the model's prediction.&lt;/p&gt;

&lt;p&gt;That distinction is important.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Grad-CAM helps interpret model behavior; it does not prove that the highlighted region is the tumor.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧩 Step 8 — Turning the Model Into an Application
&lt;/h2&gt;

&lt;p&gt;A trained model sitting inside a notebook isn't very useful to someone who wants to interact with it.&lt;/p&gt;

&lt;p&gt;So I built a &lt;strong&gt;Streamlit application&lt;/strong&gt; around the model.&lt;/p&gt;

&lt;p&gt;The application allows a user to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upload an MRI image&lt;/li&gt;
&lt;li&gt;Run the trained CNN&lt;/li&gt;
&lt;li&gt;View the predicted class&lt;/li&gt;
&lt;li&gt;Inspect confidence and probability information&lt;/li&gt;
&lt;li&gt;Generate a Grad-CAM visualization&lt;/li&gt;
&lt;li&gt;Generate a downloadable PDF report&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The application therefore connects the machine learning pipeline to an actual user interface.&lt;/p&gt;

&lt;p&gt;This was an important step for me because it changed the project from:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"I trained a model."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;into:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"I built an application around a trained model."&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 The Final Workflow
&lt;/h2&gt;

&lt;p&gt;The complete system looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              MRI Image
                  │
                  ▼
          Image Preprocessing
                  │
                  ▼
            Custom CNN
                  │
                  ▼
        Softmax Probabilities
                  │
          ┌───────┴───────┐
          ▼               ▼
     Prediction      Confidence
          │               │
          └───────┬───────┘
                  ▼
              Grad-CAM
                  │
                  ▼
          Visual Explanation
                  │
                  ▼
            PDF Report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was one of the most important things I learned from the project:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Building the model is only one part of building a machine learning application.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  📂 How I Structured the Project
&lt;/h2&gt;

&lt;p&gt;I also tried to keep the project separated into meaningful components rather than putting everything into one Python file.&lt;/p&gt;

&lt;p&gt;The repository currently has areas for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Explainable-Brain-Tumor-Detection/
│
├── assets/
├── dataset/
├── docs/
├── model/
├── utils/
│   ├── gradcam.py
│   ├── preprocess.py
│   └── report.py
│
├── app.py
├── requirements.txt
└── README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The separation helped me understand the difference between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model loading&lt;/li&gt;
&lt;li&gt;Preprocessing&lt;/li&gt;
&lt;li&gt;Explainability&lt;/li&gt;
&lt;li&gt;Report generation&lt;/li&gt;
&lt;li&gt;Application logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That became increasingly important as the project grew.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 What I Learned From Building the Entire Pipeline
&lt;/h2&gt;

&lt;p&gt;After completing the project, I don't think the biggest lesson was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I know how to build a CNN."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It was more like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"I understand how many different pieces have to work together for a CNN project to become an actual application."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I learned about:&lt;/p&gt;

&lt;h3&gt;
  
  
  Data
&lt;/h3&gt;

&lt;p&gt;How important it is to understand and prepare the dataset before training.&lt;/p&gt;

&lt;h3&gt;
  
  
  Models
&lt;/h3&gt;

&lt;p&gt;How architecture decisions affect what the network can learn.&lt;/p&gt;

&lt;h3&gt;
  
  
  Training
&lt;/h3&gt;

&lt;p&gt;How training is an iterative process rather than simply running a model once and checking the accuracy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Evaluation
&lt;/h3&gt;

&lt;p&gt;Why accuracy alone isn't enough.&lt;/p&gt;

&lt;h3&gt;
  
  
  Explainability
&lt;/h3&gt;

&lt;p&gt;How Grad-CAM can help inspect model behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment
&lt;/h3&gt;

&lt;p&gt;How a trained model can be turned into an interactive application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Engineering
&lt;/h3&gt;

&lt;p&gt;How project structure becomes important once the codebase grows.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Important Limitations
&lt;/h2&gt;

&lt;p&gt;This project is an &lt;strong&gt;academic and learning project&lt;/strong&gt;, not a clinical diagnostic system.&lt;/p&gt;

&lt;p&gt;There are several limitations.&lt;/p&gt;

&lt;p&gt;The model was trained on a limited publicly available dataset, so its performance may not generalize to real-world clinical data.&lt;/p&gt;

&lt;p&gt;Performance can also depend on MRI image quality and differences between datasets.&lt;/p&gt;

&lt;p&gt;Grad-CAM provides an interpretation of influential regions, but it is &lt;strong&gt;not a precise tumor segmentation method&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For these reasons, the application should not be used as a substitute for professional medical diagnosis.&lt;/p&gt;

&lt;p&gt;These limitations are part of the project itself, not something I want to hide behind the model's accuracy.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 What I Would Improve Next
&lt;/h2&gt;

&lt;p&gt;If I continued developing this system, some areas I'd explore are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Larger and more diverse datasets&lt;/li&gt;
&lt;li&gt;Transfer learning with stronger architectures&lt;/li&gt;
&lt;li&gt;More rigorous validation&lt;/li&gt;
&lt;li&gt;3D MRI analysis&lt;/li&gt;
&lt;li&gt;Tumor segmentation&lt;/li&gt;
&lt;li&gt;Multi-modal MRI support&lt;/li&gt;
&lt;li&gt;Better inference performance&lt;/li&gt;
&lt;li&gt;More robust deployment architecture&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal would not simply be to make the model bigger.&lt;/p&gt;

&lt;p&gt;It would be to make the entire system &lt;strong&gt;more reliable, interpretable, and generalizable&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔗 Try the Project
&lt;/h2&gt;

&lt;p&gt;The complete implementation is available on GitHub:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/TanmayT134/Explainable-Brain-Tumor-Detection" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub Repository&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also try the deployed Streamlit application:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://brain-mri-ai.streamlit.app/" rel="noopener noreferrer"&gt;&lt;strong&gt;Live Demo — Streamlit&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This application is intended for educational and research purposes only. It is not a medical diagnostic tool.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔗 Part of My CNN Learning Series
&lt;/h2&gt;

&lt;p&gt;This is the third post in my CNN learning series.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧠 Part 1 — What My First CNN Project Taught Me
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/tanmayt134/what-my-first-cnn-project-taught-me-3om7"&gt;Read Part 1 →&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ⚠️ Part 2 — 5 Mistakes I Made in My First CNN Project
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/tanmayt134/5-mistakes-i-made-in-my-first-cnn-project-that-ruined-my-results-4ial"&gt;Read Part 2 →&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ⚙️ Part 3 — How I Built the CNN Model
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;You're reading this one.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔍 Part 4 — Understanding Model Predictions with Grad-CAM
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Coming next.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  👋 Let's Connect
&lt;/h2&gt;

&lt;p&gt;I'm continuing to learn by building practical software and machine learning projects.&lt;/p&gt;

&lt;p&gt;If you're interested in &lt;strong&gt;CNNs, computer vision, deep learning, or building ML applications&lt;/strong&gt;, I'd be happy to hear what you're working on.&lt;/p&gt;

&lt;p&gt;🌐 &lt;a href="https://portfolio-tanmay-tawade.vercel.app/" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;💻 &lt;a href="https://github.com/TanmayT134" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;💼 &lt;a href="https://www.linkedin.com/in/tanmay-tawade-995829344/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>deeplearning</category>
      <category>cnn</category>
      <category>python</category>
    </item>
    <item>
      <title>🚀 5 Mistakes I Made in My First CNN Project (That Ruined My Results)</title>
      <dc:creator>Tanmay P. Tawade</dc:creator>
      <pubDate>Mon, 23 Mar 2026 13:48:43 +0000</pubDate>
      <link>https://dev.to/tanmayt134/5-mistakes-i-made-in-my-first-cnn-project-that-ruined-my-results-4ial</link>
      <guid>https://dev.to/tanmayt134/5-mistakes-i-made-in-my-first-cnn-project-that-ruined-my-results-4ial</guid>
      <description>&lt;h1&gt;
  
  
  🚀 5 Mistakes I Made in My First CNN Project
&lt;/h1&gt;

&lt;h1&gt;
  
  
  machinelearning #deeplearning #cnn #ai
&lt;/h1&gt;

&lt;h2&gt;
  
  
  😅 I Thought My Model Was Working... Until I Looked Closer
&lt;/h2&gt;

&lt;p&gt;When I built my first CNN model for &lt;strong&gt;brain tumor classification using MRI images&lt;/strong&gt;, I initially felt pretty confident.&lt;/p&gt;

&lt;p&gt;The code was running.&lt;/p&gt;

&lt;p&gt;The model was training.&lt;/p&gt;

&lt;p&gt;The accuracy looked reasonable.&lt;/p&gt;

&lt;p&gt;And predictions were being generated.&lt;/p&gt;

&lt;p&gt;The model was classifying images into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Glioma&lt;/li&gt;
&lt;li&gt;Meningioma&lt;/li&gt;
&lt;li&gt;Pituitary&lt;/li&gt;
&lt;li&gt;No Tumor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I assumed everything was working.&lt;/p&gt;

&lt;p&gt;Then I started looking beyond the overall accuracy.&lt;/p&gt;

&lt;p&gt;That's when I realized:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A model can appear to work while still having important problems underneath.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here are five mistakes that taught me more than simply getting the model to train.&lt;/p&gt;




&lt;h2&gt;
  
  
  ❌ Mistake 1: Not Understanding Class Distribution
&lt;/h2&gt;

&lt;p&gt;One of the first things I should have checked more carefully was the distribution of images across the four classes.&lt;/p&gt;

&lt;p&gt;I should have asked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How many images are available for each class?&lt;/li&gt;
&lt;li&gt;Are the classes reasonably balanced?&lt;/li&gt;
&lt;li&gt;Are some classes significantly underrepresented?&lt;/li&gt;
&lt;li&gt;Could class distribution affect the metrics I'm seeing?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead, I focused on getting the CNN running.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I learned
&lt;/h3&gt;

&lt;p&gt;If one class has substantially more samples than another, overall accuracy may not tell the complete story.&lt;/p&gt;

&lt;p&gt;A model can perform well overall while performing poorly on a less represented class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1l0a13a8kfhzwx5qm27d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1l0a13a8kfhzwx5qm27d.png" alt="Class Imbalance Problem" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Lesson
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Understand the distribution of your data before interpreting your model's performance.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  ❌ Mistake 2: Increasing Model Complexity Without a Clear Reason
&lt;/h2&gt;

&lt;p&gt;I initially had a simple assumption:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"More layers should give the model more ability to distinguish all four classes."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I experimented with increasing the model's complexity.&lt;/p&gt;

&lt;p&gt;The problem wasn't experimenting.&lt;/p&gt;

&lt;p&gt;The problem was &lt;strong&gt;adding complexity without a clear hypothesis about what I was trying to improve&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I observed
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Training performance improved&lt;/li&gt;
&lt;li&gt;Validation performance did not improve accordingly&lt;/li&gt;
&lt;li&gt;The gap between training and validation became more noticeable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That was a sign that the model could fit the training data better without necessarily generalizing better.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3793oiq28jqke7q9vt8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3793oiq28jqke7q9vt8d.png" alt="Overfitting in model" width="640" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Lesson
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A more complex model isn't automatically a better model.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Architecture changes should have a reason behind them.&lt;/p&gt;




&lt;h2&gt;
  
  
  ❌ Mistake 3: Trusting Overall Accuracy Too Much
&lt;/h2&gt;

&lt;p&gt;This was probably one of my biggest mistakes.&lt;/p&gt;

&lt;p&gt;When I saw a decent overall accuracy, my first reaction was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"The model is working well."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But I wasn't asking enough questions about &lt;em&gt;how&lt;/em&gt; that accuracy was achieved.&lt;/p&gt;

&lt;p&gt;I needed to look at things such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class-wise performance&lt;/li&gt;
&lt;li&gt;Confusion matrix&lt;/li&gt;
&lt;li&gt;Precision&lt;/li&gt;
&lt;li&gt;Recall&lt;/li&gt;
&lt;li&gt;F1-score&lt;/li&gt;
&lt;li&gt;Which classes were being confused&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, the model showed confusion between some of the tumor categories.&lt;/p&gt;

&lt;p&gt;That made me realize that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Overall accuracy is only one view of model performance.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Lesson
&lt;/h3&gt;

&lt;p&gt;For a multi-class classification problem, don't stop at:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"What percentage did the model get correct?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Also ask:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Which classes is the model getting wrong, and how often?"&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ❌ Mistake 4: Choosing Hyperparameters Without Understanding Them
&lt;/h2&gt;

&lt;p&gt;Another mistake was treating hyperparameters almost like fixed values that could simply be copied from another implementation.&lt;/p&gt;

&lt;p&gt;I experimented with things such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learning rate&lt;/li&gt;
&lt;li&gt;Batch size&lt;/li&gt;
&lt;li&gt;Number of epochs&lt;/li&gt;
&lt;li&gt;Model architecture&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But initially, I didn't understand enough about &lt;strong&gt;why&lt;/strong&gt; I was choosing those values.&lt;/p&gt;

&lt;h3&gt;
  
  
  What changed
&lt;/h3&gt;

&lt;p&gt;I started treating each experiment as something I should be able to explain.&lt;/p&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"This configuration worked for someone else, so I'll use it."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I started thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What am I changing, why am I changing it, and what effect should I expect?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Lesson
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Don't copy hyperparameters blindly. Understand what you're changing and evaluate the result.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There isn't one universally correct learning rate, batch size, or number of epochs for every CNN project.&lt;/p&gt;




&lt;h2&gt;
  
  
  ❌ Mistake 5: Not Visualizing the MRI Data Early Enough
&lt;/h2&gt;

&lt;p&gt;This sounds simple, but it was one of the most useful lessons.&lt;/p&gt;

&lt;p&gt;I should have spent more time looking at the actual images before focusing on the model.&lt;/p&gt;

&lt;p&gt;I wanted the CNN to discover the patterns.&lt;/p&gt;

&lt;p&gt;But first, &lt;strong&gt;I needed to understand the data myself.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I started looking more closely at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Differences between classes&lt;/li&gt;
&lt;li&gt;Image quality&lt;/li&gt;
&lt;li&gt;Visual patterns&lt;/li&gt;
&lt;li&gt;Tumor locations&lt;/li&gt;
&lt;li&gt;Similarities between categories&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 What I Should Have Observed Earlier
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsrcuia8rxwlvhstavkhv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsrcuia8rxwlvhstavkhv.png" alt="Original Dataset vs Improved Dataset" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flypxxz4xc1bth7zaxq29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flypxxz4xc1bth7zaxq29.png" alt="Tumor Locations" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some categories can contain visually similar patterns.&lt;/p&gt;

&lt;p&gt;That doesn't mean a human can simply look at an MRI and make the correct classification.&lt;/p&gt;

&lt;p&gt;It means that &lt;strong&gt;the visual characteristics of the dataset matter when you're trying to understand where a model may struggle.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Lesson
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Visualize your data before asking your model to learn from it.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧠 What Changed After These Mistakes
&lt;/h2&gt;

&lt;p&gt;The biggest change wasn't one particular model architecture.&lt;/p&gt;

&lt;p&gt;It was my approach to experimentation.&lt;/p&gt;

&lt;p&gt;I started doing more of this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understand → Experiment → Evaluate → Question → Improve&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Build → Train → Check Accuracy → Done&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I became more interested in questions like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why did validation performance change?&lt;/li&gt;
&lt;li&gt;Which class is causing the problem?&lt;/li&gt;
&lt;li&gt;Is the model overfitting?&lt;/li&gt;
&lt;li&gt;Did the preprocessing actually help?&lt;/li&gt;
&lt;li&gt;Did the architectural change improve generalization?&lt;/li&gt;
&lt;li&gt;What does the confusion matrix tell me that accuracy doesn't?&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 My Biggest Takeaway
&lt;/h2&gt;

&lt;p&gt;Multi-class classification isn't simply:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"Binary classification + more classes."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Each additional class introduces more opportunities for confusion and makes evaluation more important.&lt;/p&gt;

&lt;p&gt;And perhaps the most useful lesson from this project was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A model doesn't become reliable just because it trains successfully.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Training is only the beginning.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔗 Part of My CNN Learning Series
&lt;/h2&gt;

&lt;p&gt;This is the second post in my CNN learning series.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧠 Part 1 — What My First CNN Project Taught Me
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/tanmayt134/what-my-first-cnn-project-taught-me-3om7"&gt;Read Part 1 →&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ⚠️ Part 2 — 5 Mistakes I Made in My First CNN Project
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;You're reading this one.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ⚙️ Part 3 — How I Built the CNN Model
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Coming next.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🔍 Part 4 — Understanding Model Predictions with Grad-CAM
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Coming later.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🔗 Project Reference
&lt;/h2&gt;

&lt;p&gt;The project discussed in this article is part of my brain tumor detection and classification project.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;a href="https://github.com/TanmayT134/Explainable-Brain-Tumor-Detection" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;a href="https://brain-mri-ai.streamlit.app/" rel="noopener noreferrer"&gt;Live Demo — Streamlit&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The project includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MRI image preprocessing&lt;/li&gt;
&lt;li&gt;CNN-based classification&lt;/li&gt;
&lt;li&gt;Binary and multi-class experiments&lt;/li&gt;
&lt;li&gt;Model evaluation&lt;/li&gt;
&lt;li&gt;Grad-CAM explainability&lt;/li&gt;
&lt;li&gt;Streamlit interface&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This project is an academic/learning project and is not intended to replace professional medical diagnosis.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  👋 Let's Connect
&lt;/h2&gt;

&lt;p&gt;I'm continuing to learn machine learning by building practical projects and documenting what I learn along the way.&lt;/p&gt;

&lt;p&gt;If you're also working with &lt;strong&gt;CNNs, computer vision, or deep learning&lt;/strong&gt;, I'd be interested to hear about your experience.&lt;/p&gt;

&lt;p&gt;🌐 &lt;a href="https://portfolio-tanmay-tawade.vercel.app/" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;br&gt;&lt;br&gt;
💻 &lt;a href="https://github.com/TanmayT134" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;&lt;br&gt;
💼 &lt;a href="https://www.linkedin.com/in/tanmay-tawade-995829344/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for Reading!&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>deeplearning</category>
      <category>cnn</category>
      <category>ai</category>
    </item>
    <item>
      <title>🚀 What My First CNN Project Taught Me About Brain Tumor Detection</title>
      <dc:creator>Tanmay P. Tawade</dc:creator>
      <pubDate>Fri, 16 Jan 2026 11:25:22 +0000</pubDate>
      <link>https://dev.to/tanmayt134/what-my-first-cnn-project-taught-me-3om7</link>
      <guid>https://dev.to/tanmayt134/what-my-first-cnn-project-taught-me-3om7</guid>
      <description>&lt;h2&gt;
  
  
  🧠 From Theory to Actually Building a CNN
&lt;/h2&gt;

&lt;p&gt;My first real experience with a Convolutional Neural Network (CNN) came through a brain tumor detection and classification project using MRI images.&lt;/p&gt;

&lt;p&gt;I had already studied the theory.&lt;/p&gt;

&lt;p&gt;I knew what convolution, pooling, activation functions, epochs, loss, and accuracy meant.&lt;/p&gt;

&lt;p&gt;At least, I thought I did.&lt;/p&gt;

&lt;p&gt;Once I started implementing the model, I realized that understanding a concept theoretically and understanding how it behaves in a real project are two very different things.&lt;/p&gt;

&lt;p&gt;This isn't a CNN tutorial.&lt;/p&gt;

&lt;p&gt;Instead, I want to share some of the things that confused me, the mistakes I made, and what changed in my understanding after actually building the project.&lt;/p&gt;




&lt;h2&gt;
  
  
  🤔 Why I Chose This Project
&lt;/h2&gt;

&lt;p&gt;I wanted a project that was:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Academically meaningful&lt;/li&gt;
&lt;li&gt;Related to deep learning&lt;/li&gt;
&lt;li&gt;Practical enough to connect theory with a real problem&lt;/li&gt;
&lt;li&gt;Challenging enough to make me learn beyond the classroom&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Medical image analysis stood out to me because it combines computer vision, deep learning, and a problem where model evaluation and interpretability matter.&lt;/p&gt;

&lt;p&gt;That made it a good learning problem.&lt;/p&gt;




&lt;h2&gt;
  
  
  📊 The Dataset Was More Important Than I Expected
&lt;/h2&gt;

&lt;p&gt;One of my first mistakes was focusing on the model before fully understanding the dataset.&lt;/p&gt;

&lt;p&gt;I should have asked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What exactly do the labels represent?&lt;/li&gt;
&lt;li&gt;How many samples are available for each class?&lt;/li&gt;
&lt;li&gt;Are the classes balanced?&lt;/li&gt;
&lt;li&gt;How were the images collected?&lt;/li&gt;
&lt;li&gt;Are the images already preprocessed?&lt;/li&gt;
&lt;li&gt;Could there be differences between the training and evaluation data?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead, I was initially more interested in getting the CNN running.&lt;/p&gt;

&lt;p&gt;That created problems later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My biggest dataset lesson:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before building the model, understand the data you're giving it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A sophisticated model cannot compensate for poorly understood data.&lt;/p&gt;




&lt;h2&gt;
  
  
  🖼️ Looking at the Images Changed My Perspective
&lt;/h2&gt;

&lt;p&gt;Visualizing sample MRI images before training might seem obvious now.&lt;/p&gt;

&lt;p&gt;But doing it made me realize how much information can be missed when you immediately jump into code.&lt;/p&gt;

&lt;p&gt;Even a basic inspection helped me think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Image dimensions&lt;/li&gt;
&lt;li&gt;Visual differences between classes&lt;/li&gt;
&lt;li&gt;Background information&lt;/li&gt;
&lt;li&gt;Image quality&lt;/li&gt;
&lt;li&gt;Preprocessing requirements&lt;/li&gt;
&lt;li&gt;Possible sources of variation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That made the dataset feel less like a folder of files and more like actual data that needed to be understood.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ CNNs Made More Sense Once I Implemented One
&lt;/h2&gt;

&lt;p&gt;I had studied CNN architecture before.&lt;/p&gt;

&lt;p&gt;But implementing one changed how I thought about it.&lt;/p&gt;

&lt;p&gt;I started understanding that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Convolution layers learn spatial features from images&lt;/li&gt;
&lt;li&gt;Pooling layers reduce spatial dimensions and can help make representations more compact&lt;/li&gt;
&lt;li&gt;Activation functions introduce non-linearity&lt;/li&gt;
&lt;li&gt;The architecture affects what patterns the model can learn&lt;/li&gt;
&lt;li&gt;Adding more layers does not automatically mean better performance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of my biggest realizations was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Small architectural changes can have a noticeable effect on model behavior.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reading about CNNs gave me the terminology.&lt;/p&gt;

&lt;p&gt;Building one gave those concepts context.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 A Simple CNN Structure
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyp30nn0yvn9h70b0wzkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyp30nn0yvn9h70b0wzkg.png" alt="CNN Architecture" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8ro2kysoqd0azl1apy7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8ro2kysoqd0azl1apy7.png" alt="Block diagram of CNN" width="432" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The diagrams made something that initially felt abstract much easier to reason about.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ The Part That Actually Challenged Me
&lt;/h2&gt;

&lt;p&gt;Getting the model to train wasn't the difficult part.&lt;/p&gt;

&lt;p&gt;Understanding whether it was actually learning something useful was.&lt;/p&gt;

&lt;p&gt;Some of the challenges I encountered included:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Overfitting&lt;/li&gt;
&lt;li&gt;Interpreting validation results&lt;/li&gt;
&lt;li&gt;Choosing hyperparameters&lt;/li&gt;
&lt;li&gt;Understanding why performance changed between experiments&lt;/li&gt;
&lt;li&gt;Figuring out whether a change actually improved the model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At one point, I genuinely thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"If the accuracy is high, the model must be good."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That turned out to be an incomplete way of looking at model performance.&lt;/p&gt;

&lt;p&gt;Accuracy is useful, but it doesn't tell the whole story.&lt;/p&gt;

&lt;p&gt;Depending on the dataset and problem, metrics such as precision, recall, F1-score, confusion matrices, and ROC-AUC can provide additional information about model behavior.&lt;/p&gt;

&lt;p&gt;That was an important shift in how I evaluated my experiments.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Why Explainability Became Important
&lt;/h2&gt;

&lt;p&gt;As I worked more with the project, another question became interesting to me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Why is the model making this prediction?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For an image classification model, getting a class prediction is only part of the story.&lt;/p&gt;

&lt;p&gt;I started exploring Grad-CAM to visualize which regions of an image were contributing to a model's prediction.&lt;/p&gt;

&lt;p&gt;This was particularly interesting in the context of medical imaging because it gave me a way to inspect the model's spatial focus instead of looking only at the final classification output.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Model Interpretation Example
&lt;/h2&gt;

&lt;p&gt;Here are examples from my experiments:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ktrmfloykokizfiva61.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ktrmfloykokizfiva61.png" alt="Grad-CAM Output (No Tumor Image)" width="639" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frvkmwrvk8ex9367odcmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frvkmwrvk8ex9367odcmt.png" alt="Grad-CAM Output (Tumor Image)" width="639" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The heatmaps made the predictions more interesting to investigate because I could visually examine which regions were highlighted by the model.&lt;/p&gt;

&lt;p&gt;But this also taught me an important lesson:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;An explanation visualization is a tool for interpreting model behavior, not proof that the model is correct.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That distinction is important, especially for sensitive applications such as medical imaging.&lt;/p&gt;




&lt;h2&gt;
  
  
  📈 What This Project Actually Taught Me
&lt;/h2&gt;

&lt;p&gt;The biggest lessons weren't specific to CNNs.&lt;/p&gt;

&lt;p&gt;They were about the process of building machine learning systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Machine learning is iterative
&lt;/h3&gt;

&lt;p&gt;My first approach wasn't my final approach.&lt;/p&gt;

&lt;p&gt;Training, evaluating, changing, and testing again became part of the process.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Debugging is part of learning
&lt;/h3&gt;

&lt;p&gt;When something doesn't work, reading logs, checking inputs, inspecting outputs, and questioning assumptions are often more valuable than immediately searching for a solution.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Data deserves as much attention as the model
&lt;/h3&gt;

&lt;p&gt;A model is only learning from the data you provide.&lt;/p&gt;

&lt;p&gt;Understanding that data should come before obsessing over architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Metrics need context
&lt;/h3&gt;

&lt;p&gt;A single number doesn't completely describe model performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Implementation exposes gaps in understanding
&lt;/h3&gt;

&lt;p&gt;I could explain CNN concepts on paper.&lt;/p&gt;

&lt;p&gt;But building one showed me exactly which parts I actually understood and which parts I had only memorized.&lt;/p&gt;

&lt;p&gt;And probably the biggest lesson was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Copying a solution is easy. Understanding why it works is the real learning.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔧 What I Want to Improve Next
&lt;/h2&gt;

&lt;p&gt;This project also showed me where I need to improve.&lt;/p&gt;

&lt;p&gt;My next areas of focus are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better evaluation and experiment tracking&lt;/li&gt;
&lt;li&gt;Stronger understanding of model architecture&lt;/li&gt;
&lt;li&gt;More rigorous dataset analysis&lt;/li&gt;
&lt;li&gt;Improved project structure&lt;/li&gt;
&lt;li&gt;Deeper exploration of explainable AI&lt;/li&gt;
&lt;li&gt;Better understanding of how models behave outside controlled experiments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal isn't just to make the model produce a better number.&lt;/p&gt;

&lt;p&gt;It's to understand why the system behaves the way it does.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔗 Project Reference
&lt;/h2&gt;

&lt;p&gt;You can explore the complete implementation and documentation here:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/TanmayT134/Explainable-Brain-Tumor-Detection" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also try the deployed Streamlit application:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://brain-mri-ai.streamlit.app/" rel="noopener noreferrer"&gt;Live Demo - Streamlit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The repository includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CNN model implementation&lt;/li&gt;
&lt;li&gt;MRI image preprocessing&lt;/li&gt;
&lt;li&gt;Model evaluation&lt;/li&gt;
&lt;li&gt;Grad-CAM explainability&lt;/li&gt;
&lt;li&gt;Experimentation and results&lt;/li&gt;
&lt;li&gt;Streamlit application&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💬 Final Thought
&lt;/h2&gt;

&lt;p&gt;This was one of those projects where I started with:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"I know how CNNs work."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and ended with:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"I understand how much more there is to learn."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And honestly, I think that's a good outcome.&lt;/p&gt;

&lt;p&gt;Building the project exposed the gap between knowing a concept and being able to reason about it when things don't go as expected.&lt;/p&gt;

&lt;p&gt;That's probably one of the most valuable things I've learned from working on machine learning projects.&lt;/p&gt;

&lt;p&gt;If you've built your first CNN or machine learning project, what was the first thing that made more sense only after you actually implemented it?&lt;/p&gt;




&lt;h2&gt;
  
  
  👋 Let's Connect
&lt;/h2&gt;

&lt;p&gt;I'm continuing to explore machine learning by building practical projects and sharing what I learn along the way.&lt;/p&gt;

&lt;p&gt;If you're also learning CNNs, computer vision, or deep learning, feel free to connect or share what you're working on.&lt;/p&gt;

&lt;p&gt;🌐 &lt;a href="https://portfolio-tanmay-tawade.vercel.app/" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;br&gt;&lt;br&gt;
💻 &lt;a href="https://github.com/TanmayT134" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;&lt;br&gt;
💼 &lt;a href="https://www.linkedin.com/in/tanmay-tawade-995829344/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>deeplearning</category>
      <category>cnn</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
