2.1. Step 1. Data Management
In this section it is presented how has the data been treated, all the different folders
and files that have been created, and their explanation for better understanding of the
process.
2.1.1. Extracting files and data transformations
In this project, a dataset comprising histopathological images and corresponding an-
notations has been used for classification and detection tasks. The data preparation
involves several steps, including extracting image files from compressed archives, or-
ganizing them into usable directories, and creating annotation files in CSV format.
Below is a detailed explanation of the data we use, how we obtain it, and the purpose
of each data file.
3
Data Files and Their Purpose
1. Compressed Archives (CrossValidation.zip and HoldOut.zip): These ZIP files
contain the raw image data for cross-validation and hold-out testing.
(a) CrossValidation.zip includes either Annotated.zip (patch-level images with
annotations) or Cropped.zip (patient-level images without annotations), de-
pending on the chosen analysis level.
(b) HoldOut.zip contains HoldOut.zip inside it, which further contains images
for final testing.
2. Image Directories (EXTRACT annotated, EXTRACT cropped, EXTRACT holdout):
After extracting the ZIP files, the images are organized into these directories for
further processing.
(a) EXTRACT annotated: Contains patch-level images extracted from Anno-
tated.zip.
(b) EXTRACT cropped: Contains patient-level images extracted from Cropped.zip.
(c) EXTRACT holdout: Contains hold-out images for final model evaluation.
3. Usable Image Directories (USABLE annotated, USABLE cropped): These di-
rectories contain filtered and processed images that are ready for model training.
(a) USABLE annotated: Contains images from EXTRACT annotated that
have corresponding annotations and meet certain criteria.
(b) USABLE cropped: Contains selected images from EXTRACT cropped af-
ter filtering based on specific conditions, such as density.
4. Annotation Files (TRAIN DATA annotated.csv, TRAIN DATA cropped.csv,
TRAIN DATA holdout.csv)
(a) TRAIN DATA annotated.csv: Contains patch-level annotations, including
patient IDs (Pat ID), window IDs (Window ID), and presence values (Pres-
ence), indicating the presence of specific features in the patches.
(b) TRAIN DATA cropped.csv: Contains patient-level annotations with pa-
tient codes (CODI) and density (DENSITAT), which is mapped to binary
values for classification.
(c) TRAIN DATA holdout.csv:
5. Excel Files (HP WSI-CoordAnnotatedPatches.xlsx, PatientDiagnosis cropped.csv,
all annotations with patient diagnosis.csv):
(a) HP WSI-CoordAnnotatedPatches.xlsx: Contains patch-level annotations
that are used to create TRAIN DATA annotated.csv.
(b) PatientDiagnosis cropped.csv: Contains patient-level diagnosis information,
used to create TRAIN DATA cropped.csv.
(c) all annotations with patient diagnosis.csv:
4
Data Preparation Steps
The data preparation workflow begins with the systematic extraction of images
from archival datasets, specifically CrossValidation.zip and HoldOut.zip. Utilizing
Python’s zipfile module ensures efficient and reliable decompression. Depending on
the analytical focusˆawhether at the patch-level or patient-levelˆawe extract either An-
notated.zip or Cropped.zip from the CrossValidation.zip archive. The images are
carefully deposited into designated directories, namely EXTRACT annotated or EX-
TRACT cropped, to streamline subsequent data handling processes. Post-extraction,
the images, initially nested within patient-specific directories, are reorganized to create
a flattened directory structure.
This involves renaming and relocating files, employing a consistent naming conven-
tion that combines patient identifiers with sequence numbers. Flattening the directory
hierarchy is crucial as it facilitates more straightforward data access patterns during
model training, thus enhancing computational efficiency. To curate datasets that are
both relevant and high-quality for training, a rigorous filtering criteria was applied.
For patch-level images, inclusion is ensured by cross-referencing image filenames
with records in HP WSI-CoordAnnotatedPatches.xlsx, thereby guaranteeing that only
images with valid annotations are selected. At the patient-level, density informa-
tion from PatientDiagnosis cropped.csv is used to select patients exhibiting specific
histopathological characteristics, thereby aligning the dataset with the intended diag-
nostic objectives. Annotation files undergo meticulous processing to produce struc-
tured CSV files required for training. In TRAIN DATA annotated.csv, this ensure a
comprehensive mapping between images and their corresponding patch-level annota-
tions. For patient-level data encapsulated in TRAIN DATA cropped.csv, ’DENSITAT’
is transform into a binary labels (0 or 1). This binarization is essential as it refor-
mulates the problem into a binary classification task, simplifying the model’s output
layer design and aligning with binary cross-entropy loss functions.
Recognizing that data quality is paramount, with the implementation of robust
data cleaning and filtering protocols. This includes handling missing values, correct-
ing discrepancies, and ensuring consistency across datasets. For example, we exclude
patch-level images lacking valid ’Presence’ annotations to prevent noise in training.
Additionally, class imbalance is adressed by balancing the dataset concerning the num-
ber of images per patient and class. Balancing is critical as it prevents the model from
becoming biased toward majority classes, ensuring equitable learning across all classes.
Data Exploration
Prior to model development, an in-depth data exploration phase is conducted to
comprehend the intrinsic properties of the dataset. This encompasses assessing the
distribution of classes within both patch-level and patient-level datasets. Understand-
ing class distribution is vital, as significant imbalances can bias the model’s learning
process. Identifying such imbalances informs the decision to adjust loss functions by
incorporating class weights or to employ resampling techniques, thereby enhancing
model fairness and performance. For that reason, since it was found that certain
classes are underrepresented, hyperparameters such as learning rate, batch size, and
the number of epochs were adjusted based on dataset size and complexity to optimize
model training.
5
2.1.2. Load functions and Kfold usage
K-Fold cross-validation is a powerful method for evaluating model performance, es-
pecially in contexts like medical imaging, where avoiding data leakage is crucial. By
implementing it at the patient level, we ensure that all data related to a single patient
is either in the training or validation set, never both. This avoids artificially inflating
performance metrics and better simulates real-world conditions.
The process begins by organizing the data into groups based on unique patient
identifiers such as Pat ID. Each group contains all images for a particular patient,
alongside the corresponding label or diagnosis. To maintain class balance across folds,
a stratified K-Fold splitter is employed. Stratification ensures that each fold has a
similar distribution of classes, which is essential in datasets with class imbalances.
For every fold, the splitter generates two sets of patient IDs: one for training
and the other for validation. These IDs are then used to filter the dataset, creating
training and validation subsets. Only images associated with the selected patient
IDs are included in their respective sets, ensuring the integrity of the patient-level
separation.
Class weights are computed based on the training set’s class distribution for each
fold. These weights are incorporated into the model’s loss function to mitigate the
effects of class imbalance, preventing the model from favoring the majority class.
To manage the iterative nature of K-Fold cross-validation, the indices, patient IDs,
and labels for each fold are saved. This not only ensures reproducibility but also
enables further analysis or experimentation using the same splits.
An appropriate number of folds (3-fold) was chosen based on the dataset size
and computational resources. The model is trained on the data from k-1 folds and
evaluated on the remaining fold. This process repeats for all folds, resulting in k sets
of performance metrics, such as accuracy, precision, recall, and loss. Aggregating these
metrics provides a comprehensive view of the model’s performance and generalizability.

SUMMARIZE THIS INTO 2 MINUTES TALK