<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Maryamrafaqat on Medium]]></title>
        <description><![CDATA[Stories by Maryamrafaqat on Medium]]></description>
        <link>https://medium.com/@maryamrafaqat88?source=rss-7495c01ff595------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*t9XTxJeI_R3xG61ognrZ8w.jpeg</url>
            <title>Stories by Maryamrafaqat on Medium</title>
            <link>https://medium.com/@maryamrafaqat88?source=rss-7495c01ff595------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 14:43:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maryamrafaqat88/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From Microscopic Images to Medical Reports: A Pipeline for Breast Cancer Diagnosis Using CNNs and…]]></title>
            <link>https://medium.com/@maryamrafaqat88/from-microscopic-images-to-medical-reports-a-pipeline-for-breast-cancer-diagnosis-using-cnns-and-7ea6a7fe567f?source=rss-7495c01ff595------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ea6a7fe567f</guid>
            <category><![CDATA[ai-assistant]]></category>
            <category><![CDATA[malignant]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[breast-cancer]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Maryamrafaqat]]></dc:creator>
            <pubDate>Mon, 26 May 2025 02:18:28 GMT</pubDate>
            <atom:updated>2025-05-26T02:42:34.476Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Microscopic Images to Medical Reports: A Pipeline for Breast Cancer Diagnosis Using CNNs and LLMs</h3><p><strong>By Maryam Rafaqat</strong></p><h3>Introduction</h3><p>Breast cancer diagnosis through histopathological images is a critical component of early detection and treatment planning. While convolutional neural networks (CNNs) have significantly improved image classification, their lack of interpretability poses challenges for real-world clinical integration.</p><p>This project proposes a novel pipeline that combines CNN-based subtype classification with a Large Language Model (LLM), Mistral-7B, to generate comprehensive, human-readable diagnostic reports. The goal is to create an automated system that not only classifies cancer subtypes but also produces structured medical reports that align with clinical expectations.</p><h3>Project Overview</h3><p>This project was executed in two major stages:</p><ol><li>Classification of breast cancer subtypes using CNNs trained on the BreakHis dataset.</li><li>Report generation using Mistral-7B LLM, based on CNN outputs formatted in text.</li></ol><p>The pipeline concludes with an evaluation of generated reports using ROUGE and BERT-Score metrics.</p><h3>Dataset Preparation and Preprocessing</h3><p>The dataset used in this project was the BreakHis dataset, available on Kaggle. It comprises 9,109 RGB histopathological images collected from 82 patients. The images are captured at four different magnification levels: 40X, 100X, 200X, and 400X. Each image is labeled as either benign or malignant, further divided into eight distinct subtypes. The benign subtypes include Fibroadenoma, Tubular Adenoma, Phyllodes Tumor, and Adenosis, while the malignant subtypes consist of Ductal Carcinoma, Lobular Carcinoma, Mucinous Carcinoma, and Papillary Carcinoma.</p><p>Preprocessing steps were applied to ensure the dataset was ready for model training. All images were resized to a standard resolution of 224x224 pixels to fit the input requirements of the CNN architecture. CLAHE (Contrast Limited Adaptive Histogram Equalization) was used to enhance contrast in the histopathological images, especially helpful in highlighting structural details. Data augmentation techniques such as rotation, flipping, and zooming were also applied to increase dataset diversity and reduce overfitting. Finally, the dataset was normalized and split into training, validation, and test sets using a stratified approach to preserve the class distribution across all subsets.</p><h3>CNN-Based Classification</h3><p>For the classification task, a CNN-based architecture was employed using DenseNet121. This model was pretrained on the ImageNet dataset and fine-tuned separately for classifying benign and malignant subtypes. The classification problem was tackled at two levels: binary classification to distinguish between benign and malignant samples, and multi-class classification to identify the specific subtype within each category.</p><p>The implementation involved training two separate models, each saved in the form of .h5 files: one for benign subtype classification (benign_subtype_model.h5) and another for malignant subtypes (malignant_subtype_model.h5). The architecture consisted of DenseNet121 as a feature extractor, followed by a global average pooling layer, and a fully connected softmax output layer for final predictions.</p><p>The results were promising. The binary classification model achieved an accuracy of approximately 93 percent. For multi-class classification, the benign subtype model reached around 90 percent accuracy, while the malignant subtype model achieved about 88 percent. Additionally, macro-averaged F1-scores were high across all subtype classes, indicating robust performance across imbalanced categories.</p><h3>Architecture Diagram</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SIiP5qs6HDirHr7swNHdGQ.jpeg" /><figcaption>Architecture Diagram for breast cancer diagnosis using deep learning and a Large Language Model (LLM). The pipeline includes image preprocessing, classification using DenseNet121, prompt formatting, and report generation via Mistral-7</figcaption></figure><h3>Providing Classification Output to Mistral-7B</h3><p>Once the CNN models trained on the BreakHis dataset performed classification, their output consisted of simple diagnostic labels. Specifically, the binary classification model identified whether a test image was benign or malignant. Based on this result, the corresponding subtype classification model was invoked — either benign or malignant subtype classifier — and the predicted subtype label was retrieved. For example, if the binary classifier identified the image as benign, the benign subtype model would predict labels such as “Fibroadenoma” or “Adenosis.”</p><p>These final classification outputs — such as “Benign: Fibroadenoma” or “Malignant: Ductal Carcinoma” — were then passed directly to the language model as input prompts. No structured formatting or inclusion of metadata like patient ID or confidence scores was used. This approach focused on simplicity, feeding the pure diagnosis result into the language model to drive the next phase: medical report generation.</p><h3>Medical Report Generation Using Mistral-7B</h3><p>The Large Language Model used for generating medical reports was Mistral-7B, accessed through the Hugging Face Transformers library. This model was loaded into a GPU-enabled environment and prompted using the direct classification output of the CNN models.</p><p>The prompt given to the model was a short, diagnosis-specific phrase such as “Benign: Fibroadenoma” or “Malignant: Ductal Carcinoma.” Based on this minimal yet informative input, Mistral-7B generated a comprehensive, human-readable medical report. For instance, if the input to the model was “Malignant: Ductal Carcinoma,” the generated report would describe the nature of the disease, its pathological implications, potential treatment paths, and diagnostic recommendations.</p><h3>Evaluation of Generated Reports</h3><p>A crucial part of this project was evaluating the <strong>accuracy and clinical relevance</strong> of the generated reports. Two advanced metrics were used:</p><ul><li><strong>ROUGE</strong>, which measures the overlap of words and phrases between generated reports and reference reports.</li><li><strong>BERT-Score</strong>, which assesses <strong>semantic similarity</strong> by comparing the meaning of generated and reference texts using contextual embeddings.</li></ul><p>Together, these metrics validated both the structure and meaning of the generated outputs. The results were promising: the reports demonstrated strong alignment with real clinical documents and maintained high readability and interpretability.</p><h3>Code and Implementation</h3><p>This project is implemented across two complete Kaggle notebooks that demonstrate both the image classification pipeline and the report generation using a large language model (LLM).</p><h3>Breast Cancer Classification and Model Saving</h3><p><strong>Notebook link</strong>: <a href="https://www.kaggle.com/code/maryamrafaqat/breast-cancer-binary-and-multi-classification">Breast Cancer Binary and Multi-Class Classification</a></p><p>This notebook covers:</p><ul><li>Loading and preprocessing the <strong>BreakHis dataset</strong></li><li><strong>Image augmentation and normalization</strong></li><li>Training a <strong>DenseNet121 model</strong> for:</li><li>Binary classification (benign vs. malignant)</li><li>Multi-class classification (tumor subtypes)</li><li><strong>Saving trained models (.h5 format)</strong> for downstream LLM input</li></ul><h3>LLM-Based Medical Report Generation</h3><p><strong>Notebook link</strong>: <a href="https://www.kaggle.com/code/maryamrafaqat7813/llm-bio-mistral-7b-backup">LLM + Bio + Mistral-7B — Full Pipeline</a></p><p>This notebook demonstrates:</p><ul><li>Formatting classification predictions into <strong>medical prompt templates</strong></li><li>Fine-tuning the <strong>Mistral-7B LLM</strong></li><li>Generating <strong>subtype-specific diagnostic reports</strong></li><li>Evaluating report quality using <strong>ROUGE</strong> and <strong>BERT-Score</strong></li></ul><p>The combination of these notebooks showcases a complete end-to-end system from raw image to interpretable clinical report. Key Advantages of This Approach</p><p>The integrated system offers multiple advantages over traditional methods:</p><ul><li><strong>Clinical interpretability</strong>: Doctors receive structured, readable reports, not just raw predictions.</li><li><strong>Subtype-specific insights</strong>: Instead of general labels, the system generates tailored narratives for each type of tumor.</li><li><strong>Scalability</strong>: Once trained, the pipeline can be adapted to other datasets and medical domains with minimal changes.</li></ul><p>This fusion of vision and language allows AI to behave more like a clinical assistant than just a classification engine.</p><h3>Future Potential</h3><p>While this project focused on breast cancer, the methodology is applicable to many other types of diseases and imaging modalities. With more advanced datasets and fine-tuned models, future systems could be developed to support a wide range of <strong>radiology, pathology, and even genomics-based diagnostics</strong>.</p><p>There is also room for enhancing <strong>real-time deployment</strong>, adding <strong>feedback loops</strong> for clinical correction, and improving <strong>user interface design</strong> for medical practitioners.</p><h3>Conclusion</h3><p>This project demonstrates that the combination of <strong>deep learning for medical image analysis</strong> with <strong>Large Language Models (LLMs) for report generation</strong> can produce diagnostic tools that are not only highly accurate but also genuinely interpretable. By converting raw classification outputs into detailed, subtype-specific medical reports, the system bridges the gap between AI predictions and clinical decision-making. Rather than replacing doctors, this approach is designed to <strong>augment and support clinical workflows</strong>, offering clear, narrative explanations that improve diagnostic confidence. The ability to transform model outputs into human-readable medical language makes this solution particularly valuable for <strong>radiologists, clinicians, and medical researchers</strong> seeking transparency and insight from AI-driven tools.</p><p>This is not just about detecting disease — it’s about communicating it clearly, accurately, and responsibly.</p><h3>About the Author</h3><p><strong>Maryam Rafaqat</strong><br> <em>MS Computer Science</em><br> <strong>National University of Computer and Emerging Sciences (FAST-NUCES)</strong></p><ul><li>🔗 <a href="https://www.linkedin.com/in/maryamrafaqat30/">LinkedIn</a></li><li>💻 <a href="https://github.com/mary270">GitHub</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ea6a7fe567f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>