<jupyter_start><jupyter_text>Skin Disease Predictor Using Deep Learning<jupyter_code>#Importing Libraries
from keras.layers import Dense,Flatten
from keras.models import Model
from tensorflow.keras import layers
from keras.applications.inception_v3 import InceptionV3
from keras.preprocessing.image import ImageDataGenerator
import numpy as np
from glob import glob
# re-size all the images to this
IMAGE_SIZE = [224, 224]
# Adding paths of train and test data
train_path = '../input/dermnet/train'
test_path = '../input/dermnet/test'
# add preprocessing layer to the front of Inception
incept = InceptionV3(input_shape=IMAGE_SIZE + [3], weights='imagenet', include_top=False)
# don't train existing weights
for layer in incept.layers:
  layer.trainable = False
#Getting Number of Categories
folders = glob('../input/dermnet/train/*')
# Adding more CNN layers to the output of Inception model
x = Flatten()(incept.output)
x = layers.Dense(256, 'relu', kernel_initializer='he_normal')(x)
x = layers.BatchNormalization()(x)
x = layers.Dropout(0.2)(x)
# Adding softmax as activation layer to prediction value for multi-class classification
prediction = Dense(len(folders), activation='softmax')(x)
# create a model object
model = Model(inputs=incept.input, outputs=prediction)
# view the structure and all the layers present in the CNN model
model.summary()
# Compiling the model
# tell the model what cost and optimization method to use
model.compile(
  loss='categorical_crossentropy',
  optimizer='adam',
  metrics=['accuracy']
)
#Data Augmentation
from keras.preprocessing.image import ImageDataGenerator

# Splitting the data into training(80%) and validation(20%) set using validation_split of ImageDataGenerator
data_datagen = ImageDataGenerator(validation_split=0.2,
                                   rescale = 1./255,
                                   shear_range = 0.2,
                                   zoom_range = 0.2,
                                   horizontal_flip = True)

test_datagen = ImageDataGenerator(rescale = 1./255)


# Generating training_set from data_datagen using subset as training
training_set = data_datagen.flow_from_directory('../input/dermnet/train',
                                                 target_size = (224, 224),
                                                 batch_size = 32,
                                                 class_mode = 'categorical',
                                                 subset="training")
# Generating valid_set from data_datagen using subset as validation
valid_set = data_datagen.flow_from_directory(
    '../input/dermnet/train',
    target_size = (224, 224),
    batch_size = 32,
    class_mode = 'categorical',
    subset="validation"
)

# Generating test_set
test_set = test_datagen.flow_from_directory('../input/dermnet/test',
                                            target_size = (224, 224),
                                            batch_size = 32,
                                            class_mode = 'categorical')
from keras.callbacks import ModelCheckpoint
# Filepath to save the best model with epoch and val_loss
filepath = './my_best_model.epoch{epoch:02d}-loss{val_loss:.2f}.hdf5'
# adding model checkpoint to monitor the val_loss and save the best model based on minimum val_loss to filepath
checkpoint = ModelCheckpoint(filepath=filepath, 
                             monitor='val_loss',
                             verbose=1, 
                             save_best_only=True,
                             mode='min')
# Setting callbacks as checkpoint
callbacks = [checkpoint]
#Fit the model
r = model.fit_generator(
  training_set,
  validation_data=valid_set,
  epochs=15,
  steps_per_epoch=len(training_set),
  validation_steps=len(valid_set),
  callbacks=callbacks
)
# Evaluating the model to get accuracy on test set
model.evaluate(test_set)<jupyter_output>126/126 [==============================] - 53s 418ms/step - loss: 0.3904 - accuracy: 0.9696
{'fraction_non_alphanumeric': 0.09088620342396778, 'fraction_numerical': 0.021399798590130917, 'mean_word_length': 2.6889507892293407, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '77330', 'license': 'MIT', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1075, 'n_words': 307, 'path': 'Skin Disease Predictor/skin-disease-inception.ipynb', 'repo_name': 'umangtank/ML-CaPsule', 'size': '3972'}