This commit is contained in:
Andre Neto
2025-06-01 22:03:09 +01:00
parent 89a63276e5
commit a1c6075008
98 changed files with 12347 additions and 140429 deletions
+51
View File
@@ -0,0 +1,51 @@
\section{Introduction}
Generative machine learning models have recieved significant attention in recent years due to their capability to synthesize realistic and diverse data samples. Such models learn the probability distributions of real-world datasets and generate new instances. These techniques have numerous applications, including data augmentation, anomaly detection, image restoration, and even medical diagnostics~\cite{yi2019generative}.
In the context of medical imaging, generative approaches have the potential to mitigate common challenges such as limited data availability, imbalanced class distribution, and the high costs associated with obtaining labeled medical data. Specifically, generative models like Generative Adversarial Networks~\cite{goodfellow2014generative} (GANs), Variational Autoencoders~\cite{kingma2013auto} (VAEs), and Diffusion Models~\cite{ho2020denoising} have shown great promise in generating realistic medical images.
In this project, I address the task of synthesizing realistic blood cell images from the BloodMNIST dataset~\cite{medmnistv2}. The BloodMNIST dataset comprises RGB images of peripheral blood smear cells, categorized into eight distinct cell types: neutrophils, eosinophils, basophils, lymphocytes, monocytes, immature granulocytes, erythroblasts, and platelets (Fig.~\ref{fig:bloodmnist_examples}).
\begin{figure}
\centering
\begin{minipage}{0.22\textwidth}
\includegraphics[width=\linewidth]{images/bloodmnist_classes/neutrophil.png}
(a) Neutrophil
\end{minipage}
\hfill
\begin{minipage}{0.22\textwidth}
\includegraphics[width=\linewidth]{images/bloodmnist_classes/eosinophil.png}
(b) Eosinophil
\end{minipage}
\hfill
\begin{minipage}{0.22\textwidth}
\includegraphics[width=\linewidth]{images/bloodmnist_classes/basophil.png}
(c) Basophil
\end{minipage}
\hfill
\begin{minipage}{0.22\textwidth}
\includegraphics[width=\linewidth]{images/bloodmnist_classes/lymphocyte.png}
(d) Lymphocyte
\end{minipage}
\\[1em]
\begin{minipage}{0.22\textwidth}
\includegraphics[width=\linewidth]{images/bloodmnist_classes/monocyte.png}
(e) Monocyte
\end{minipage}
\hfill
\begin{minipage}{0.22\textwidth}
\includegraphics[width=\linewidth]{images/bloodmnist_classes/immature_granulocytes.png}
(f) I. Granulocyte
\end{minipage}
\hfill
\begin{minipage}{0.22\textwidth}
\includegraphics[width=\linewidth]{images/bloodmnist_classes/erythroblast.png}
(g) Erythroblast
\end{minipage}
\hfill
\begin{minipage}{0.22\textwidth}
\includegraphics[width=\linewidth]{images/bloodmnist_classes/platelet.png}
(h) Platelet
\end{minipage}
\caption{Examples of each blood cell class from the BloodMNIST dataset.}\label{fig:bloodmnist_examples}
\end{figure}
+3
View File
@@ -0,0 +1,3 @@
\section{Problem Statement}
The primary objective of this study is to implement, train, and comparatively evaluate three prominent generative model classes: GANs, VAEs, and Diffusion Models. We assess their effectiveness quantitatively by computing the Fréchet Inception Distance (FID)~\cite{heusel2017gans}, a robust metric to measure the similarity between generated and real image distributions. Additionally, we discuss qualitative results to highlight each model's strengths and limitations. The ultimate goal is to identify an optimal generative framework capable of producing realistic and diverse synthetic blood cell images.
+13
View File
@@ -0,0 +1,13 @@
\section{Approach}
We implemented and evaluated three classes of generative models. Each model was adapted to generate 28$\times$28 RGB images that resemble the blood cell samples in the BloodMNIST dataset.
For each approach, the model was trained on the entire dataset, combining the original training, validation, and test splits. All images were normalized to the $[-1, 1]$ range. We maintained a batch size of 128 and used the Adam optimizer for all models. Each training was repeated with five random seeds for later evaluation stability.
\textbf{VAE:} The Variational Autoencoder consists of a convolutional encoder that maps the input image into a latent Gaussian distribution, and a decoder that reconstructs the image from sampled latent vectors. The model is trained using a reconstruction loss combined with a Kullback-Leibler divergence term to regularize the latent space~\cite{kingma2013auto}.
\textbf{GAN:} We implemented a Deep Convolutional GAN (DCGAN), with a generator that learns to synthesize realistic images from latent noise vectors, and a discriminator that learns to distinguish between real and generated samples~\cite{goodfellow2014generative}. Both networks use strided convolutions and LeakyReLU activations. The generator is trained to fool the discriminator, while the discriminator is trained to correctly classify real and fake inputs.
\textbf{Diffusion:} The DDPM is a generative model based on a Markovian process that gradually adds noise to images and then learns to reverse this corruption step by step~\cite{ho2020denoising}. The training objective is to predict the added noise at each timestep, enabling the model to sample clean images from pure noise.
To ensure fairness, all models were trained using the same hardware environment and epochs, and evaluated using the Fréchet Inception Distance (FID) as a common metric.
+17
View File
@@ -0,0 +1,17 @@
\section{Experimental Setup}
All code and experiments are documented in the accompanying Jupyter Notebook, developed with Python 3.10.12 and PyTorch 2.1.0, running under CUDA 11.8 on a machine equipped with an NVIDIA GeForce GTX 970 GPU.\@ The BloodMNIST dataset was loaded via the MedMNIST v2 framework, and all images were resized to $28 \times 28$ with three color channels. To simplify the setup, the training, validation, and test splits were merged into a single training set of 17,092 images.
Each generative model was trained for 20 epochs using a batch size of 128. The Adam optimizer was employed with default parameters ($\beta_1=0.9$, $\beta_2=0.999$), and a learning rate of $10^{-3}$ for the VAE and Diffusion models, and $2\times10^{-4}$ for the GAN.\@
During evaluation, each model generated 10,000 synthetic images from latent noise vectors (or denoised noise in the case of the diffusion model). These samples were compared against 10,000 randomly selected real images using FID.\@ To ensure statistical robustness, this evaluation was repeated across five independent runs with different different seeds. The final score for each model is reported as the mean $\mu$ and standard deviation $\sigma$ of the FID values across these runs.
Let $\text{FID}_i$ denote the score obtained in run $i$, for $i = 1, \dots, 5$. The reported result is
\begin{equation}
\text{FID}_{\text{final}} = \mu \pm \sigma
\end{equation}
where
\begin{align}
\mu &= \frac{1}{5} \sum_{i=1}^5 \text{FID}_i \\
\sigma &= \sqrt{\frac{1}{5} \sum_{i=1}^5 {\left(\text{FID}_i - \mu\right)}^2}
\end{align}
+53
View File
@@ -0,0 +1,53 @@
\section{Results and Analysis}
Table~\ref{tab:fid-scores} summarizes the mean and standard deviation of the FID scores obtained for each model across five independent runs.
\begin{table}[h]
\centering
\caption{Fréchet Inception Distance (FID) results over 5 runs. Lower is better.}\label{tab:fid-scores}
\begin{tabular}{lcc}
\toprule
\textbf{Model} & \textbf{Mean} & \textbf{Std. Dev.} \\
\midrule
VAE & 201.73 & 0.23 \\
GAN & 180.57 & 0.71 \\
Diffusion & 423.70 & 0.64 \\
\bottomrule
\end{tabular}
\end{table}
\begin{figure}
\centering
\begin{minipage}[t]{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{images/real.png}
(a) Real Images
\end{minipage}
\hfill
\begin{minipage}[t]{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{images/vae.png}
(b) VAE Samples
\end{minipage}
\vspace{0.5em}
\begin{minipage}[t]{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{images/gan.png}
(c) GAN Samples
\end{minipage}
\hfill
\begin{minipage}[t]{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{images/diffusion.png}
(d) Diffusion Samples
\end{minipage}
\caption{Qualitative comparison of real and generated blood cell images.}\label{fig:model-comparison}
\end{figure}
Figure~\ref{fig:model-comparison} shows both the real images and the visual samples generated by each model. The results reveal clear qualitative differences. The VAE samples exhibit smooth but often blurry outputs due to its probabilistic reconstruction objective. Diffusion models produce a lump of blobs, barely resembling a blood cell. GANs generate highly detailed and diverse samples, closely resembling real blood cells.
Overall, GANs achieve the best quantitative and qualitative performance, indicating superior capability in modeling complex visual structures present in biomedical data.
+9
View File
@@ -0,0 +1,9 @@
\section{Conclusion}
In this study, we implemented and evaluated three prominent classes of generative models, Variational Autoencoders (VAEs), Generative Adversarial Networks (GANs), and Denoising Diffusion Probabilistic Models (DDPMs), on the BloodMNIST dataset. Each model was trained under consistent conditions and assessed using both qualitative visualizations and the Fréchet Inception Distance (FID) metric.
The results revealed clear differences in performance. The VAE produced smooth but blurry reconstructions due to its probabilistic decoder. Diffusion models failed to produce visually coherent images, resulting in noisy outputs that barely resemble blood cells. In contrast, GANs achieved the best visual quality, generating diverse and realistic samples that closely match real data.
These observations align with the FID scores reported in Table~\ref{tab:fid-scores}, where GANs obtained the lowest value (180.57), outperforming both VAEs (201.73) and diffusion models (423.70). This demonstrates the effectiveness of adversarial training for modeling complex biomedical structures.
Overall, GANs offer the best balance of fidelity and diversity for blood cell image synthesis in this context. Future work may explore hybrid or conditional architectures to further improve control over generated samples and class specificity.