Effective machine learning-based skin disease diagnosis using PyTorch

The application of machine learning in medical diagnosis has become a trend in research. Skin infection is one of the most seen diseases and one of the world’s most infectious diseases, influencing people of all ages. The reason for the explicit attention of the researchers in skin detection is due to the reason that skin disease is more visible compared to any other disease. In the past, varied methods have been proposed, which have rendered remarkable results. However, the presently functional models are trained on specific kinds of diseases and are limited to 4 to 5 classes, which is inefficient in detecting a large set of diseases. The paper offers a weightless model for detecting 23 different kinds of skin diseases. The model is trained on the PyTorch backend, which gives the flexibility of developing an algorithm. The model attained 96.37% accuracy on training data, and 87.75% accuracy on test data, which is expected to improve as the size of the dataset is increased.


Introduction
Skin is an important part of the human body [1].The main functions of the skin are to protect the body against toxins, disease, and injury, and to allow nutrients to enter the body.Throughout human life, skin health is affected by many factors, including sun exposure, smoking, alcohol consumption, sports activities, and viruses [2].These facets not only impact its functional virtue but can also cause damage to the skin, which then affects human health adversely.Skin can suffer from rashes, inflammation, and itchiness among other changes in appearance.Some skin conditions are genetic while others are caused by lifestyle or environmental factors such as poor diet or pollution.To address the problem of diagnosing and treating skin diseases, recent trends have used the computer-aided diagnosis to automatically detect skin diseases based on past images of the same disorders.Medical imaging has become a crucial part of this process, which is attracting attention in fields such as image processing, medical science, and intelligent medicine.Although most skin abnormalities begin with changes in the outer layers of the skin.Such problems are also important factors in the diagnosis of internal diseases.Abnormalities frequently suggest the presence or emergence of metabolic, malignant, and glandular diseases.The most common types of known skin problems include acne (acne vulgaris), atopic dermatitis (AD), psoriasis (Psoriasis Vulgaris), rosacea (Rosacea Vulgaris), etc. Acne is a common skin condition in teenagers, but it can also affect adults.Acne occurs when clogged pores cause blackheads and whiteheads, as well as pimples.It typically causes breakouts on the face, upper back, neck, shoulders, and chest.People with atopic dermatitis have dry patches that often itch and may be painful.Although acne is the most commonly spread skin condition, there is very little research on it.The common issues of the skin are mostly ignored which not only affects the internal metabolism of the body but also hampers individual confidence.The proposed work is made to work efficiently on 23 classes of diseases which therefore make it useful for a broad category of disease identification.Furthermore, the dataset has been significantly increased to extract the maximum features of the disease.The ultimate aim of this work is to contribute to the medical field by enabling the early detection and treatment of skin diseases, potentially saving lives before conditions become severe.

Related works
Skin disease detection research based on image analysis has advanced significantly over the years.Several different methods have been considered, including machine learning techniques and pattern recognition algorithms.Skin disease is the fourth most common cause of skin disease in the world and is estimated to affect more than 350 million people worldwide.In this paper, a PyTorch-based EfficientNet model has been discussed which has been used to classify about 23 types of diseases.The previous work conducted by various scholars and researchers all around the globe was taken into consideration to identify potential problems efficiently, work on a remedy for minor problems and develop a model with the highest attained accuracy.Skin treatments are more successful and less complex when detected early but are challenging to study due to similar characteristics.
Rao et al. [3] discussed pre-processing, deep learning methods, model training, validation, and classification.Experiments on 10,000 images showed that a Convolutional Neural Network (CNN) with Keras APIs gave 93% accuracy in classifying seven classes.Yasir et al. [4] dealt with the problem of image feature extraction, which was considered the first step in diagnosing skin diseases.The accuracy of the model increased as more features were extracted from the image.The authors applied this model to nine skin diseases and achieved 90% accuracy for each disease.Melanoma, one of the most common types of skin cancer that can be fatal if not diagnosed and treated early, was one of the primary test subjects.Ahmed et al. [5] described a model based on CNN and Support Vector Machine (SVM) with OpenCV.The trained model was used to classify 300 images with an accuracy of 80 to 90% for six different classes, including fatal skin diseases like cancer, acne, and eczema.Muhaba et al. [6] proposed an automated system for the diagnosis of five common skin diseases that used a pre-trained deeplearning MobileNet-v2 model to classify images of patients with skin diseases.The accuracy of the proposed method was 97.5% and the sensitivity was 97.7%.
Velasco et al. [7] proposed a MobileNet-based model and applied transfer learning to create a skin disease classification system on an Android.A total of 3,406 images of seven skin diseases were collected and achieved an accuracy of 84.28%.Hemat et al. [8] used KNN and Matlab to differentiate between normal skin and malignant skin lesions.The system was further enhanced by an evolutionary learning technique called assembly learning.The accuracy of the model was 90% when tested in real time.
Meeravali et al. [9] proposed a lightweight 2D wavelet-based model using CNN, Keras, and PyCharm to classify several classes of skin diseases.The model effectively used a 2D wavelet for extracting the features from the image.The image is preprocessed using image enhancement and edging techniques before feeding into the actual model.Iyer et al. [10] developed a deep-learning model that could distinguish between healthy skin and skin with abnormalities such as acne, rosacea, and hyperpigmentation.The model suggested products for their treatment.The research yielded a repertoire of 5000 images from dermnet.com and other external sources.Transfer learning extracted image features using a MobileNetV2 model.For easy and convenient use of the proposed model, it was deployed as an Android app via TensorFlow Lite for easy use by end users.Agrahari et al. [11] classified models based on different accuracy levels for skin cancer detection.For example, the model using CNN yielded an accuracy of 65% in training; however, a ResNet-based model trained on the same dataset yielded 82% accuracy in training.In addition to these two models, a pre-trained MobileNet-based model yields a 91.2% testing accuracy.Sharma et al. [12] proposed an application for detecting five different skin diseases using convolutional neural networks.The proposed system attained an accuracy of 70%, but high-dimensional datasets could increase accuracy to above 90%.Rimi et al. [13] proposed a CNN architecture to detect six types of skin diseases: hand dermatitis, subacute eczema, hand eczema, ulcer, lichen simplex, and dermatitis congestive.The model achieved 70.8% accuracy in this task.Hegde et al. [14] used computer vision techniques and a neural network to transform the red, green, and blue components of an image into grayscale.The model was trained using four different methods and found that the neural network produced the best results with an accuracy of 62.9%.The same dataset, when trained using Linear Discriminant Analysis (LDA), yielded an accuracy of 80.9%, while Naïve Bayesian (NB) yielded 67.4%.Among all four models, SVM was concluded as the best model with an accuracy of 81.61%.The comparison between different models gave a clear idea of selecting a model that would work best for future research and studies.Esteva et al. [15] used a model trained on 129,450 clinical images to diagnose the most common and fatal skin cancers and obtained results that were consistent with 21 dermatologists in a validation study.

Data pre-processing
The dataset for the introspection was collected from dermnetnz.com[16], which has a huge collection of images compartmentalized into various kinds of skin diseases.The data can be extracted using web scraping tools like Selenium and can be used for study and other research purposes [17].The images vary in different size and resolution.The first phase of the study was concentrated on preparing the dataset for further studies.To achieve a good result, all the images were resized to 520 x 520 pixels.The collected dataset included images of 23 classes divided into training and testing datasets.Figure 1 shows the distribution of the collected images in various classes.Since the dataset exhibits a skewed distribution due to improper distribution of the images in each class, it needs to be preprocessed.The skewed data might lower the accuracy and cause the model to overfit, resulting in a profound change in training and validation loss.Hence, the dataset was augmented with functions in PyTorch to overcome these issues.The data was rotated and flipped using the functions RandomHorizontalFlip(), RandomVerticalFlip(), RandomRotation (15) and Resize ((512, 512)) to enlarge the dataset size.Apart from these, the WeightedRandomSampler in PyTorch was used to ensure that the data in each batch was in the right proportion in all available classes.The total size of the dataset was 29900, which was then divided into a ratio of 4:1 for training and testing.

Proposed model
A pre-trained/Transfer Learning (TL) model from PyTorch was used for training.The EfficientNet B0 architecture wasn't forged by engineers but by the neural network itself.This model was devised using a multi-objective neural architecture search that optimizes both accuracy and floating-point functions [18].Taking B0 as a baseline prototype, a robust family of EfficientNets from B1 to B7 perpetrated state-of-the-art precision on ImageNet.EfficientNet can take images with lower pixel count as input yet give good results.EfficientNets are advisable to use for intricate datasets.The proposed model consists of nine layers, as shown in Table 1.The architecture uses 7 inverted residual blocks [19].Each block has a different setting, using squeeze and excitation blocks along with swish activation.Swish is a multiplication of a linear and sigmoid activation which is represented below: where sigmoid(x) =     Swish activation function is useful since it leads to quicker convergence and learning.It also solves the vanishing gradient problem.
The MBConv block takes two intakes, which are data and block arguments.The data is output from the previous layer.A block argument is a collection of attributes used inside the MBConv block such as input filters, output filters, expansion ratio, squeeze ratio, etc.For the specific purpose of disease detection, only seven layers were frozen at this stage; the rest of the layers were trained on the data.Stochastic Gradient Descent (SGD) was used as an optimizer with a learning rate of 0.01 and a momentum of 0.9; this was done to increase model efficiency.

Results and discussion
The model was trained for 615 minutes and 41 seconds on an Nvidia GeForce GTX 1050 GPU.In the initial phase, the model was overfitted due to the improper distribution of the number of images across the dataset.The dataset was hence increased using data augmentation techniques like rotation and resizing.After the increase in dataset, the model yielded an accuracy of 96.37% on the training set and 87.75% accuracy on unlabeled/testing data without any overfitting issues.The results were compared with those of other previous works, as shown in Table 2.The results of the proposed model were compared to those of other models used in previous research, as shown in Table 2.The table lists seven different models, including the proposed model, and their respective testing accuracies.The proposed model outperformed several models in terms of testing accuracy.However, it should be noted that the results of the other models listed in the table may not be directly comparable to those of the proposed model due to differences in the datasets and evaluation methods used.The dataset was fetched using the web scraping tool Selenium.Since the data was unequally distributed, data augmentation was used to increase the size of the dataset.Previous research works focused on some major skin diseases, like skin cancer and acne.In contrast, the proposed model combined the data to form a large dataset consisting of 23 different classes of skin diseases with 29900 images.The test data were collected randomly from different sources and used to test the proposed model.Thus, the test results were not affected by the training set as oversampling and overfitting were removed.This accounts for the improved performance of our proposed model.

Conclusion
This paper presents a novel deep learning-based approach for detecting skin diseases.The model uses EfficientNet B0 architecture for processing the input image.A huge dataset containing approximately around 29,900 different skin disease images was used for training the model.As a backend, PyTorch was provided to the model.During the initial phase of training, the model was found to be overfitted because of the skew in data distribution.After processing the dataset and fixing the image size to 520 x 520 pixels and again training the model, it performed exceptionally well.Another advantage of this model is that it is lightweight and can be deployed on low-end devices, which makes its implementation in real-time to be cost-efficient and easy.The model was able to identify infected/damaged portions of skin with great accuracy.The overall result of the model was compared with other approaches and performance was found to be better.However, the model is in the testing phase and possesses a great potential to reach far better accuracy and perform even better when trained with a larger amount of properly processed data.

Figure 1 .
Figure 1.Data distribution among different classes.
shows a block diagram of the proposed model.It is trained using EfficientNet B0 through transfer learning with images converted into tensors loaded into it using predefined data loader functions.Training began initially on 25 epochs and was then increased to 50 epochs.Each epoch was evaluated based on 4 metrics: training accuracy, training loss, validation accuracy, and validation loss.

Table 1 .
The model architecture of EfficientNet B0.

Table 2 .
Comparison of accuracy of different models used for the related works.