$$\rightleftharpoonup{xx}$$
$$\longleftharp{xx}$$,
$$\longrightharp{xx}$$,
This section presents a comprehensive approach designed to enhance knee osteoarthritis diagnosis and grading through the use of a modified XceptionNet model. The presented methodology is based on careful data preprocessing, thorough model architecture customization, and strong assessment techniques, all of which are intended to address the complex problems associated with knee OA imaging. In Figure 2, the flow of the model has been illustrated.

Figure 2: Model's workflow. Please click here to view a larger version of this figure.
Dataset description
The dataset used in this research comprises 9,786 X-ray images of the knee from the OAI dataset that have been assigned an OA grade based on the KL grading technique. This dataset, which offers a wide range of instances covering the various phases of KOA, is essential for both training and evaluating the proposed model24. Bilinear interpolation was used to scale all images. This technique was selected because it strikes a compromise between computational effectiveness and maintaining the quality of the image, both of which are essential for maintaining anatomical features important for the categorization of osteoarthritis in the knee. In the dataset, the grades are 0-4, with Grade 0 representing a healthy knee and Grade 4 denoting severe osteoarthritis. This grade offers a complex range of disease evolution, which is essential for the model to understand the minute variations across the stages.
Additionally, the dataset was organized into testing, validation, and training sets. For evaluating the performance of the model and making sure it learns to generalize effectively without overfitting the training set, this split was essential. Testing set offers an objective assessment of the finalized model's efficacy, as it was used for modifying the model's weights as well. Furthermore, a validation set aids in fine-tuning the hyperparameters and assessing models throughout the training stage. A brief summary of data distribution is provided in Table 2, and Figure 3 provides a visual depiction of the same.
| Class | Auto-Test | Test | Train | Val |
| 0 | 604 | 639 | 2286 | 328 |
| 1 | 275 | 296 | 1046 | 153 |
| 2 | 403 | 447 | 1516 | 212 |
| 3 | 200 | 223 | 757 | 106 |
| 4 | 44 | 51 | 173 | 27 |
Table 2: Brief description of dataset.

Figure 3: Dataset distribution. The dataset was organized into testing, validation, and training sets. Please click here to view a larger version of this figure.
Data pre-processing
This step is crucial and aims to improve model performance by improving the quality of the input data. The stages involved in preprocessing are as follow.
Image Resizing: A standard dimension is applied to every X-ray image to provide consistency throughout the entire set of images. This stage is essential for the model to process images consistently and effectively. Equation 1 is used in this process.
New Image Size = Resize (Original Image, Standard Dimension) (1)
Normalization: The pixel values in the images have been standardized to get a mean of zero and a standard deviation of one. This kind of normalization ensures that the input values fall into a similar range, which speeds up the model's convergence during training. Equation 2 is used to carry out this normalizing step.
(2)
Data Augmentation: Data augmentation strategies were employed to address problems due to insufficient data and enhance the model's capacity for generalization. These methods include flips, zooms, rotations, and translations. They introduce new images that are intentionally added to the training dataset. Equation 3 is used in the implementation of this augmentation procedure.
Augmented Image = Apply Transformation (Original Iamge) (3)
A variety of augmentation techniques were employed to provide variability to the training set in order to improve the model's robustness and minimize overfitting. A shear range of 0.2, a zoom range of 0.8 to 1.2 (corresponding to a zoom factor of 0.2), and a random rotation range of -30° to +30° were all included in the training data augmentation. Both horizontal and vertical flipping were allowed with a probability of 0.5 in order to enhance model generalization. For both vertical and horizontal shearing, a shearing factor of 0.1, or ± 10% distortion, was also employed.
Class Balancing: Class weighting algorithms were used because of the dataset's possible class imbalance (with more images of some OA classes than others). In order to prevent the model from showing bias in favor of more common classes, this method gives underrepresented classes larger weights. Equation 4 is utilized in this process. The following values were used to determine the weights: Healthy: 3857, Doubtful: 1770, Minimal: 2578, Moderate: 1286, and Severe: 295 are the class-wise distributions of the 9786 total samples and 5 classes.
(4)
Train-Validation Split: The dataset was organized into validation and training sets using traditional 80:20 ratios. Dividing the data allows the model to learn from the training data and evaluate its performance on a regular basis using the validation set. This allows for identifying overfitting and evaluating the model's generalization ability.
Data Pipeline Optimization: An improved data pipeline was set up to guarantee effective data handling during model training. To reduce input/output bottlenecks and increase computing performance, this pipeline makes use of batching, prefetching, and parallel data extraction techniques. To improve training efficiency and throughput, the input data pipeline was developed. To guarantee balanced memory utilization and computational load, a batch size of 32 were employed. To increase data input efficiency, num_parallel_calls=4 was used in the map function to parallelize data loading and preprocessing. Furthermore, in order to minimize I/O latency, TensorFlow's prefetch(buffer_size=tf.data.AUTOTUNE) has been used to allow automated prefetch buffer size adjustment. This effectively overlapped data pre-processing and model execution
In Figure 4, a few instances of different classes of images have been shown after basic pre-processing.

Figure 4: Instances from the dataset. The figure shows a few instances of different classes of images after basic pre-processing. Please click here to view a larger version of this figure.
Through these meticulous preprocessing steps, the dataset is transformed into a robust foundation for training the modified XceptionNet model, setting the stage for accurate and reliable KOA detection and grading.
Model architecture
Base Model: With its distinct design that uses depth-wise separable convolutions to achieve the best possible balance between computational efficiency and model complexity, the François Chollet-created XceptionNet model stands out25. Equation 5 was utilized to implement the depth-wise separable convolutions.
Depthwise Seperable Convolution(x) = Pointwise(Depthwise(x)) (5)
It is particularly relevant to this study for several reasons. First, its architecture is known for extracting detailed and hierarchical features from images, which is crucial for medical image analysis, where subtle features can indicate different stages of a condition. Secondly, the proposed model is based on the XceptionNet architecture, which has demonstrated outstanding effectiveness across several image classification tasks, aimed at detecting and grading knee osteoarthritis26.
The presented OsteoXceptionNet is a tailored version of the XceptionNet architecture created especially for automatically classifying osteoarthritis in the knee from X-ray images. Important changes include the addition of three more convolutional blocks (filters: 512, 256, and 128) to improve feature extraction specific to knee joint structures, as well as convolutional layers with filter sizes of 3 x 3 and variable filter counts ranging from 32 to 1024 across the entry, middle, and exit flows. Batch normalization and ReLU activation come after each convolutional layer, and dropout layers are added to minimize overfitting. The 224 x 224 pixel standard is used for model inputs.
Fine-tuning and modifications
Modifications: The XceptionNet model has been strategically modified in a few ways to make it suitable for KOA grading and detection.
Fine-tuning: Top layers of pre-trained XceptionNet model were unfrozen, enabling the model to learn high-level features specific to X-ray images of knee. Model fine-tuning was conducted as per Equation 6.
(6)
where θfine-tuned are the parameters after fine-tuning; θpre-trained are the pre-trained parameters; λ is the learning rate; ∇θpre-trainedLoss is the loss function's gradient related to the parameters that were pre-trained.
Additional Convolutional Layers: Additional convolutional layers were introduced in the model's final phase. These layers have a smaller kernel size to focus on extracting finer details pertinent to the different OA grades. It was employed using equation 7.
Convolutional Output = Convolution(Input,Kernel) (7)
Batch Normalization: Following each added convolutional layer, batch normalization is applied to stabilize learning and enhance the convergence speed. It is employed using equation 8.
(8)
where
is the Normalized output; x is the batch normalization layer input; μ is the mean for the batch of input; σ2 is the variance in the batch of input; ϵ is a minimal constant for numerical stability.
Activation Functions: ReLU activation functions are utilized in the supplementary layers to introduce non-linearity, thereby enabling the model to acquire more intricate structures in the data. ReLU is calculated using equation 9.
ReLU(x) = max(0,x) (9)
where, x is the ReLU activation function input.
Dropout: To prevent overfitting, dropout layers are incorporated, particularly after the newly added layers, to ensure generalization of the model even on unseen data. It was done by means of equation 10.
Output = Input × Mask (10)
Output layer configuration
Output Layer: The original XceptionNet model is structured for multi-class classification with Softmax activation function in an output layer. In this adapted model, the output layer is customized to represent the five grades of knee osteoarthritis, spanning from Grade 0 to Grade 4, i.e., from healthy to severe level. Precisely, this layer comprises five neurons, each corresponding to one of the OA grades. Softmax activation function was utilized in this layer to produce a probability distribution across five classes, enabling the proposed model to forecast the appropriate OA grade for a given knee X-ray image. This approach aligns the model's output directly with the clinical grading scale, facilitating an intuitive and practical interpretation of the model's predictions for healthcare professionals.
The XceptionNet architecture is specifically tailored —which was first pre-trained on the ImageNet dataset—for presented study's objective to classify the severity of osteoarthritis in the knee. The model leveraged learnt features from a large and diverse dataset by using the pre-trained weights from ImageNet, which gave it a strong foundation. To customize the fundamental XceptionNet model for proposed research, many new layers were added.
First, 2D convolutional layers were combined with different numbers of filters and kernel sizes, each of which was activated by ReLU and batch normalization to add non-linearity. These extra layers were intended to capture and amplify features related to the severity of osteoarthritis in the knee. The model was then ready for the last classification stage by adding a Global Average Pooling 2D (GAP) layer, which shrinks the feature map while keeping important data. In particular, GAP operation achieves dimensionality reduction with minimal data loss by reducing each feature map's spatial dimensions to a single value while maintaining depth, which could vary from 7 x 7 x 1024 to 1 x 1 x 1024. The GAP layer's output was fed into the Softmax activation function, which enabled multi-class classification by converting logits to probabilities. Equations 11, 12, 13, 14, 15, 16, and 17 are used for the GAP, Softmax Activation, Feature Map Calculation, Learning Rate Reduction, Model Compilation, Class Weight Adjustment, and Multi-Class Classification Loss, respectively.
(11)
where, xi,j is activation of the feature map's i-th row and j-th column; H is the feature-map height; W is the feature-map width.
(12)
where, xi is the input to the Softmax function for class i; n is the number of classes.
Feature Map = σ(Convolution(Input,Kernel) + Bias) (13)
where, Convolution is a convolution operation; i is Activation function; Input is the input tensor to the layer; Kernel is the convolutional kernel; Bias is the bias term.
New Learning Rate = Learning Rate × Factor (14)
Model = Compile(Architecture,Loss,Optimizer,Metrics) (15)
(16)
where, Weightclass is the weight assigned to a class; Total Samples is the dataset's total_number_of_samples; Number_of_Classes is the number of distinctive classes inside the dataset; Sample in Class is the count of samples in a specific class.
(17)
where, yi is the actual probability distribution for class i; pi is the class i probability distribution prediction; N is the number of classes.
Finally, the model, now comprising the modified XceptionNet architecture with the custom layers, was compiled to predict probabilities for each class. Through these modifications, the goal was to augment the model's capability in discerning nuanced features associated with different grades of knee osteoarthritis severity, enhancing its classification performance for the specific task.
For stable and effective convergence, the Adam optimizer was used to train the model with a learning rate of 0.0001, with 0.5 used as the dropout rate to minimize overfitting. To limit model complexity and improve generalization, both L1 and L2 regularization strategies were used. For multi-class classification problems with integer labels, Sparse Categorical Crossentropy was the suitable loss function. Training was conducted for 50 epochs. Softmax, the final activation function, was used for generating class probability distributions. Additionally, a 64-step size was used for training.
Training: The training process was a very important stage. In this stage, the modified XceptionNet model learns accurate detection and grading of KOA in radiographic images. Keras version 2.6.0 and TensorFlow backend version 2.6.0 were used to implement the XceptionNet model. Below are the details of key components of the training phase, including the loss function, optimizer, callbacks, batch size, and epochs.
Loss_Function: For multi-class classification task, categorical cross_entropy was used. This loss function is particularly suited for problems where each instance is expected to be assigned to one and only one label out of a set of categories27. It evaluates the model's performance by producing probability score within zero and one. This loss was used as a gauge to effectively train this model for the accurate prediction of KOA severity since it increases when the predicted probability differs from the actual label.
Optimizer: The Adam optimizer was employed, which is well known for its effectiveness and dynamic learning rate characteristics. Adam amalgamates the advantageous characteristics of the AdaGrad and RMSProp algorithms, furnishing an optimization algorithm adept at managing sparse gradients in noisy problem settings28.
Key parameters for the Adam optimizer
Learning Rate: A learning rate of 0.0001 was employed, enabling the optimizer to make substantial adjustments to the weights initially, thus optimizing the learning process.
Beta1 and Beta2: These parameters regulate the rates at which the squared gradient and moving averages of previous gradients decline, respectively. The default values of 0.9 for beta1 and 0.999 for beta2 are utilized.
Epsilon: This parameter prevents any division by zero in the implementation, set to a small number close to zero.
Callbacks: Callbacks are used during training to monitor the performance of the model and for adjusting. The following callbacks were employed:
Early_Stopping: This is used for monitoring validation loss of the model as well as for stopping training process if loss ceases to decrease for predefined number of epochs (referred to as patience). When validation data no longer shows improvement in the model's performance, it stops training process, which helps to prevent overfitting.
Reduce LROn Plateau: This callback decreases learning rate when validation loss ceases to improve, enabling finer adjustments in the weights, potentially resulting in improved overall model performance29.
Model Checkpoint: This callback saves the model at a certain interval, so that the best version of the model can be retrieved once the training process is completed. Usually, it monitors the validation accuracy or loss and saves the model weight whenever an enhancement is detected.
Batch Size and Epochs:
Batch Size: 32 is the typical batch size that was used in order to balance the requirements for both model convergence stability and computing efficiency. A batch size of 32 strikes a balance, being sufficiently large to leverage computational optimizations and yet small enough to offer a stable estimate of the gradient.
Epochs: The model is set to train for up to 50 epochs, although training may stop early if the EarlyStopping callback is triggered. The 50 epochs provide enough iterations for the weights to adjust and for the model to converge, while EarlyStopping ensures that training does not continue unnecessarily.
By meticulously setting these parameters and utilizing callbacks, the training process was optimized to ensure the model learns effectively and generalizes well to unseen data. In order to guarantee that all classes are fairly and accurately represented in model predictions, a number of approaches were used for addressing the data imbalance problem. First, in order to make up for the underrepresentation of some classes, class weighting was used throughout the training phase. Classes with fewer samples were given larger weights. To further lessen the impacts of class imbalance during training, Keras's ImageDataGenerator was also used to make sure the model was exposed to a variety of classes in each batch30.
Evaluation metrics
In evaluating the efficacy of the developed model, numerous parameters were utilized which are described below.
Accuracy (ACC): Ratio of accurately predicted observations to all observations is quantified by this statistic. When the target classes spread out equally, it is beneficial. Its calculation is based on equation 18.
(18)
Precision (PR): The model's precision measures how well it can distinguish between all of the expected positives and positive cases. In circumstances when rate of false positive are substantial, it is quite important. Its computation is based on equation 19.
(19)
Recall (R): Recall, also known as sensitivity, quantifies the percentage of true positives correctly detected. It is especially important in situations where ignoring a good example might have serious repercussions. Its computation involves equation 20.
(20)
F1_Score: It is harmonic mean of precision (PR) and recall (R), it provides fair evaluation, particularly in the presence of an uneven class distribution. Its calculation involves equation 21.
(21)
ROC AUC: Area Under the Curve for Receiver Operating Characteristics (ROC AUC) quantifies the model's capacity to differentiate between classes. Elevated AUC values signify superior model performance. Its calculation is based on equation 22.
(22)
Cohen's Kappa (CK): This metric assesses concordance between two raters who categorize N items into C mutually exclusive classes. It offers greater robustness compared to accuracy, especially when dealing with imbalanced classes. Its calculation involves equation 23.
(23)
Metrics Mean Absolute Error (MAE), Root Mean Squared Error (RMSE), and Mean Squared Error (MSE): Although commonly employed for regression tasks, these parameters can provide useful revelations in classification scenarios, particularly in ordinal classifications. They calculate the difference between the real and predicted values. These metrics were computed using equations 24, 25, and 26, respectively.
(24)
(25)
(26)
F2 Score: The F2 score prioritizes recall over precision, which is valuable in scenarios where overlooking a positive prediction incurs greater costs than generating a false positive. Its calculation involves equation 27.
(27)
Precision and Recall Curve: This graph shows how recall and accuracy are balanced at various levels. The greater the area under a curve, the higher the levels of both recall and precision.
The above parameters were chosen in order to provide a thorough assessment of the performance of the model on all dimensions, especially in the context of the dataset's imbalance and the importance of accurately identifying the various grades of knee osteoarthritis.