$$\rightleftharpoonup{xx}$$
$$\longleftharp{xx}$$,
$$\longrightharp{xx}$$,
This study did not involve any direct experimentation on human participants or animals. All work was conducted using the publicly available, anonymized LC25000 dataset of histopathological images, which contained no identifiable patient information or direct handling of human tissue. Institutional Review Board (IRB) or Institutional Animal Care and Use Committee (IACUC) approval was not required. All procedures complied with ethical standards and adhered to the dataset's terms of use for academic research. Figure 2 shows the steps of the workflow diagram.

Figure 2: Workflow of the proposed method. The workflow includes data preprocessing, augmentation, model training, and evaluation. Please click here to view a larger version of this figure.
Dataset description
The LC25000 dataset was utilized for this study. It consisted of 25,000 histopathological images, all uniformly formatted as JPEG files with a resolution of 768 × 768 pixels. The dataset originated from an initial set of 1,250 original images, including 250 benign lung tissue images, 250 lung adenocarcinomas, 250 lung squamous cell carcinomas, 250 benign colon tissue images, and 250 colon adenocarcinomas. The remaining images were generated through data augmentation to expand the dataset, ensuring a diverse and extensive collection for robust model training and validation.
The high-resolution images allowed for detailed examination of cellular structures, which was essential for accurate cancer classification. Data augmentation was necessary due to the limited number of original images; techniques such as rotations, flips, zooms, and shifts were employed to synthetically increase the dataset size and diversity. This process generated an additional 23,750 synthetic images in a class-balanced manner, resulting in a final dataset of 25,000 images, with each class containing 5,000 images post-augmentation.
Data preprocessing
The raw histopathological images within the dataset had a resolution of 768 × 768 pixels. To ensure compatibility with the EfficientNetB7 architecture and to maximize computational efficiency, each image was resized from 768 × 768 to 224 × 224 pixels. This resizing process represented a trade-off between preserving essential histological features and reducing computational overhead. The resizing operation was mathematically represented as shown in
Equation 1:
(1)
where X denoted the original image, Xresized was the resized image, and h and w were the desired height and width, respectively. All pixel values were normalized to a range of 0 to 1, which stabilized and accelerated training by ensuring a consistent input distribution across images. This normalization was mathematically calculated as shown in Equation 2. This step was essential to improve model convergence during training.
(2)
Data augmentation was employed as a critical technique to enhance the robustness and applicability of deep learning models, especially in the context of medical imaging with limited and imbalanced datasets. In this study, a variety of augmentation techniques were applied using the ImageDataGenerator module from TensorFlow to simulate in vivo variation in histopathological images. These techniques included random rotations of up to 20 degrees to simulate tissue orientation variability, horizontal and vertical shifts up to 20% of the image dimensions to mimic position variability during slide preparation, and random zooms up to 20% to reflect variability in magnification levels.
Additionally, horizontal flipping was performed to introduce mirror-image variations, thereby further enriching the training dataset. To manage newly synthesized pixels generated during these transformations, a nearest-neighbor filling strategy was adopted to ensure smooth transitions and preserve the integrity of key histological features. The 2D rotation matrix used for augmentation is represented in Equation 3, and Equation 4 defines a function with an incremental change:
(3)
(4)
These augmentation techniques compensated for challenges such as class imbalance, slight histological variations, and dataset limitations by enabling the model to learn invariant features and reducing the risk of overfitting. By synthetically expanding the dataset and incorporating controlled variability, data augmentation significantly enhanced the model's ability to generalize to new, unseen data, thereby producing a stronger and more robust system for clinical deployment in lung and colon cancer diagnosis.
Model architecture
The model was developed based on the EfficientNetB7 architecture, a state-of-the-art deep learning network renowned for its performance, scalability, and effectiveness in image classification tasks. EfficientNetB7 was constructed using a series of Mobile Inverted Bottleneck Convolution (MBConv) blocks, which incorporated depthwise separable convolutions. This structural design effectively compressed the model, resulting in significant reductions in the number of parameters with minimal loss in performance. Such innovation enabled the model to achieve high accuracy with lower computational costs, making it particularly suitable for computationally intensive applications such as histopathological image analysis. Figure 3 shows the model architecture of the pretrained EfficientNetB7.

Figure 3: Model architecture of EfficientNetB7. This figure shows the detailed structure of the EfficientNetB7 model, illustrating its main layers and functional blocks used for image classification. Please click here to view a larger version of this figure.
The model accepted preprocessed histopathological images that had been resized from their original dimensions of 768 × 768 pixels down to 224 × 224 pixels to match the input requirements of EfficientNetB7. Each image underwent several processes within the network, including batch normalization, Swish activation functions, and convolution operations. Batch normalization was calculated as shown in Equation 5. The Swish activation function introduced non-linearity and enabled faster, more efficient training compared to traditional functions like ReLU. These layers were designed to extract and enhance hierarchical features, allowing the model to learn progressively from low-level to high-level patterns as the images propagated through the network.
(5)
The convolutional backbone of EfficientNetB7, pretrained on the ImageNet dataset, provided a highly generalizable set of feature detectors effective across a broad range of image domains. The pretrained base played a key role in capturing subtle yet informative patterns in histopathological images, which are often characterized by high intra-class variability and fine-grained features. The output from the convolutional layers was passed to a global average pooling layer, which reduced the spatial dimensions to a single feature vector for each image. This vector, encapsulating the most relevant features learned by the convolutional layers, was then flattened into a one-dimensional array for compatibility with fully connected layers. The algorithm for enhanced detection of lung and colon cancer is provided in Supplementary File 1.
The subsequent network architecture included two dense (fully connected) layers with 128 and 64 units, respectively. Both layers utilized the Rectified Linear Unit (ReLU) activation function to introduce additional non-linearity and to fine-tune the extracted features, enabling the model to recognize more precise patterns and relationships within the data. The final layer of the model was a SoftMax output layer with five neurons, each representing one of the five classes in the dataset. The SoftMax function produced a probability distribution across the classes, which reflected the model's prediction for each input image, as described in Equation 6:
(6)
The combination of state-of-the-art convolutional techniques, robust regularization, and effective optimization strategies resulted in a deep learning model well-suited for high-stakes medical image classification. The model achieved precision, scalability, and operational efficiency, demonstrating strong potential for clinical application in lung and colon cancer diagnosis. Within this framework, regularization was primarily accomplished through advanced data augmentation and the use of early stopping; no explicit dropout or weight decay was applied to the dense layers.
Training and validation
The validation and pretraining pipeline of the convolutional neural network (CNN) for LC25000 histopathological image classification was designed to optimize model performance and ensure good generalization. The pipeline began with comprehensive preprocessing, which included reducing the original 768 × 768-pixel images to 224 × 224 pixels to match the input requirements of the EfficientNetB7 architecture. Pixel intensities were normalized to the range [0, 1] to stabilize and accelerate training, and data augmentation techniques, including random rotations, shifts, zooms, and horizontal flips -- were applied to introduce variability and mitigate overfitting. These preprocessing operations ensured that the model learned invariant features and generalized well to new data.
The EfficientNetB7 model, pretrained on the ImageNet dataset, was employed as the base, providing a robust feature detector set capable of identifying subtle histological patterns. The model was subsequently fine-tuned with two dense layers (128 and 64 units) activated by the Rectified Linear Unit (ReLU) function, followed by a SoftMax output layer for five-class classification. This architecture was optimized for both precision and computational efficiency, making it well-suited for medical image analysis. The Adam optimizer update rule for θ is shown in Equation 7.
(7)
Model training was performed in batches of 128 images using the Adam optimizer, which adaptively scaled the learning rate to promote effective convergence. An early stopping criterion was implemented to monitor validation loss and halt training if no improvement was observed, thus preventing overfitting and optimizing computational resources. Throughout training, key performance metrics -- including accuracy, loss, precision, and recall -- were tracked using a hold-out validation set comprising 20% of the data. The hold-out set provided critical insights into the model's generalization capabilities and mitigated the risk of overfitting to unseen data.
The integration of advanced preprocessing, data augmentation, and optimization strategies resulted in excellent model accuracy and robustness, demonstrating strong potential for clinical application in lung and colon cancer detection. All experiments were conducted on an NVIDIA Tesla P100 GPU with 16 GB memory and 64 GB system RAM. The full training pipeline -- including preprocessing, augmentation, and model optimization -- required approximately three hours to complete ten epochs with a batch size of 128. This computational infrastructure was selected to efficiently manage the large, augmented dataset while maintaining reasonable training times appropriate for clinical research environments.
For reproducibility, all critical hyperparameters were explicitly specified. The model was trained using the Adam optimizer with a constant learning rate of 0.001. Training was carried out for a maximum of 10 epochs, with early stopping based on validation loss and a patience of three epochs to prevent overfitting. A batch size of 128 was utilized for both training and validation phases. To ensure consistent results, the random seed was set to 42 at all stages of data loading and model training. No learning rate decay schedule was applied during training.
The protocol combined systematic preprocessing, well-calibrated hyperparameters, rigorous validation schemes, and an open computational environment to promote both accuracy and reproducibility. The workflow, by integrating robust deep learning architecture, effective optimization, and reproducible experimental design, established a solid foundation for histopathological image classification. In addition to demonstrating strong performance on lung and colon cancer detection, the protocol defined a scalable framework that could be extended to similar biomedical imaging challenges in future research.
During model development, several practical adjustments were implemented to achieve reliable and reproducible results. Early stopping and advanced data augmentation were used to address class imbalance and overfitting. High memory usage during training was mitigated by resizing images to 224 × 224 pixels and using a batch size of 128. When slow convergence was encountered, the learning rate was empirically set to 0.001. Manual verification of the image directory structure was performed to prevent data loading errors, and random seeds were fixed to ensure reproducibility. These strategies can serve as practical guidance for researchers facing analogous challenges in training deep learning models with large histopathological image datasets.
Statistical analysis
Statistical modeling of the model's performance was conducted using a comprehensive set of metrics to assess accuracy, stability, and generalizability. Key evaluation measures included precision, recall, F1-score, and accuracy to quantify classification performance. The confusion matrix was utilized to report class-specific error metrics, calculated according to Equations 8-10:
(8)
(9)
(10)
Additionally, measures of error such as Mean Squared Error (MSE), Root Mean Squared Error (RMSE), and Mean Absolute Error (MAE) were evaluated to assess prediction accuracy, calculated using Equations 11-13:
(11)
(12)
(13)
The Receiver Operating Characteristic (ROC) curve and Area Under the Curve (AUC) were employed to evaluate the model's ability to discriminate between classes at various thresholds. The AUC was calculated as shown in Equation 14:
(14)
These statistical analyses provided a thorough assessment of the model's classification performance, robustness, and generalization to unseen data.
Ablation study
To further assess the contribution of each component within the classification framework, an ablation study was conducted by selectively omitting or modifying specific architectural elements of the final model. Specifically, two alternative experimental configurations were evaluated: one configuration included both the Global Average Pooling and Flatten layers, followed by two dense layers (128 and 64 units, respectively); the other configuration omitted both the Flatten layer and the 128-unit dense layer, leaving only the Global Average Pooling layer and a single 64-unit dense layer.
The complete architecture, as reported in the main results, achieved a validation accuracy of approximately 96%. When the Flatten layer was excluded, and only the 128- and 64-unit dense layers were used after Global Average Pooling, the validation accuracy dropped to 81.6%. Conversely, when the 128-unit dense layer was excluded, and the Flatten layer was retained, the validation accuracy decreased to 88%. These results indicated the necessity of including both the extra dense layer and the appropriate architectural components to achieve optimal classification performance. The findings from the ablation experiments consistently demonstrated that the combination of Global Average Pooling, Flattening, and two fully connected layers enabled a more expressive feature representation, resulting in more robust and accurate histopathological image classification.