LiteFeatNet: A parameter-efficient and performance-centric deep learning model for multi-ocular disease identification using intermediate feature reduction from fundus images.
The 3 matches
- [1] § 3. Materials and methods › 3.8. Experimental setup ↔ kerasMods.ipynb, lines 559–574 · score 0.68 · ReduceLROnPlateau, TensorFlow, Keras, scheduler, epochs, validation
- [2] § 3. Materials and methods › 3.8. Experimental setup ↔ code-nb-p.ipynb, lines 312–316 · score 0.62 · Cross Entropy, learning rate scheduler, Adam, optimizer, loss, train
- [3] § 3. Materials and methods › 3.8. Experimental setup ↔ kerasMods.ipynb, lines 559–574 · score 0.53 · ReduceLROnPlateau, Keras, schedulers, trained, model
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Jupyter notebook · 617 lines · 21 KB · MIT · 2 matches
- # %%
- # libraries
- import os
- import cv2
- import numpy as np
- import pandas as pd
- import tensorflow as tf
- from tensorflow.keras import backend as K
- from sklearn.preprocessing import LabelEncoder
- from tensorflow.keras.utils import to_categorical
- from tensorflow.keras.applications import MobileNet,MobileNetV2, VGG16, Xception, NASNetMobile, DenseNet121, EfficientNetB5,EfficientNetB0,EfficientNetV2B0
- from tensorflow.keras import Input, Model
- from tensorflow.keras.layers import Conv2D, MaxPooling2D,ReLU,SeparableConv2D,Conv2DTranspose,GlobalAveragePooling2D,GlobalMaxPooling2D,Add,Activation, Dense, Dropout, Flatten, BatchNormalization, Concatenate, Activation
- from tensorflow.keras.optimizers import Adam, SGD
- from tensorflow.keras.regularizers import l2
- from tensorflow.keras.preprocessing.image import ImageDataGenerator
- import time
- import gc
- import matplotlib.pyplot as plt
- import seaborn as sns
- from tensorflow.keras.models import load_model
- from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix
- # %%
- # initial
- K.clear_session()
- gc.collect()
- imgSize = (224,224)
- inputShape = tuple(list(imgSize) + [3])
- batchSize = 32
- print(inputShape)
- # %%
- # I/O paths
- outPath = '/kaggle/working/'
- trainImagesPath = '/kaggle/input/dataset/training/images/'
- trainLabelsPath = '/kaggle/input/dataset/training/labels.xlsx'
- testImagesPath = '/kaggle/input/dataset/testing/images/'
- testLabelsPath = '/kaggle/input/dataset/testing/labels.xlsx'
- valImagesPath = '/kaggle/input/dataset/validation/images/'
- valLabelsPath = '/kaggle/input/dataset/validation/labels.xlsx'
- # %%
- # model handling
- def saveModel(model,savePath,modName):
- model.save(savePath + modName + '.h5')
- def printModelSummary(model):
- print(model.summary())
- # %%
- # time information
- def saveTime(time1,time2,savePath):
- time_data = {'Training_Time': [time1],'Testing_Time': [time2]}
- time_df = pd.DataFrame(time_data)
- time_df.to_excel(savePath + 'time.xlsx',index=False)
- # %%
- # epch vs. accuracy
- def plotAccuracy(hist,savePath):
- epochs = range(1, len(hist.history['accuracy']) + 1)
- plt.figure(figsize=(8,6))
- plt.plot(epochs, hist.history['accuracy'], label='Train Accuracy')
- plt.plot(epochs, hist.history['val_accuracy'], label='Validation Accuracy')
- plt.xlabel('Epoch', fontsize=12)
- plt.ylabel('Accuracy', fontsize=12)
- plt.xticks(ticks=range(0, len(epochs)+1, 5))
- plt.grid(True,linestyle='--', linewidth=0.5, color='gray')
- plt.legend()
- plt.savefig(savePath + 'accuracy_plot.png', dpi=1200)
- plt.show()
- # %%
- # epoch vs. loss
- def plotLoss(hist,savePath):
- epochs = range(1, len(hist.history['loss']) + 1)
- plt.figure(figsize=(8,6))
- plt.plot(epochs, hist.history['loss'], label='Train Loss')
- plt.plot(epochs, hist.history['val_loss'], label='Validation Loss')
- plt.xlabel('Epoch',fontsize=12)
- plt.ylabel('Loss', fontsize=12)
- plt.xticks(ticks=range(0, len(epochs)+1, 5))
- plt.grid(True,linestyle='--', linewidth=0.5, color='gray')
- plt.legend()
- plt.savefig(savePath + 'loss_plot.png', dpi=1200)
- plt.show()
- # %%
- # model history
- def saveModelRunHistory(hist,savePath):
- epochs = list(range(1, len(hist.history['accuracy']) + 1))
- train_acc = hist.history['accuracy']
- val_acc = hist.history['val_accuracy']
- train_loss = hist.history['loss']
- val_loss = hist.history['val_loss']
- modelHistory_df = pd.DataFrame({
- 'Epoch': epochs,
- 'Training Accuracy': train_acc,
- 'Validation Accuracy': val_acc,
- 'Training Loss': train_loss,
- 'Validation Loss': val_loss
- })
- modelHistory_df.to_excel(savePath + 'history_file.xlsx', index=False)
- # %%
- # calculate metrics (overall)
- def testMetricsOverall(Ypred,Yact,savePath):
- accuracy = accuracy_score(Yact, Ypred)
- precision = precision_score(Yact, Ypred, average='weighted', zero_division=0)
- recall = recall_score(Yact, Ypred, average='weighted', zero_division=0)
- f1 = f1_score(Yact, Ypred, average='weighted', zero_division=0)
- print(f"Accuracy: {accuracy}")
- print(f"Precision: {precision}")
- print(f"Recall: {recall}")
- print(f"F1-Score: {f1}")
- metrics = {'Metric': ['Accuracy', 'Precision', 'Recall', 'F1-Score'],
- 'Score': [accuracy, precision, recall, f1]
- }
- overallMetrics_df = pd.DataFrame(metrics)
- overallMetrics_df.to_excel(savePath + 'overall_metrics.xlsx', index=False)
- # %%
- # calculate metrics (class-wise breakdown)
- def testMetricsClassWise(Ypred,Yact,classEncoding,savePath):
- classLabels = list(classEncoding.keys())
- accuracy_list = []
- precision_list = []
- recall_list = []
- f1_list = []
- TP_list = []
- TN_list = []
- FP_list = []
- FN_list = []
- TPR_list = []
- TNR_list = []
- FPR_list = []
- FNR_list = []
- for label in classLabels:
- encoded_label = classEncoding[label]
- TP = np.sum((Ypred == encoded_label) & (Yact == encoded_label))
- TP_list.append(TP)
- FN = np.sum((Ypred != encoded_label) & (Yact == encoded_label))
- FN_list.append(FN)
- FP = np.sum((Ypred == encoded_label) & (Yact != encoded_label))
- FP_list.append(FP)
- TN = np.sum((Ypred != encoded_label) & (Yact != encoded_label))
- TN_list.append(TN)
- accuracy = (TP + TN) / (TP + TN + FP + FN)
- accuracy_list.append(accuracy)
- precision = precision_score(Yact, Ypred, labels=[encoded_label], average='macro', zero_division=0)
- precision_list.append(precision)
- recall = recall_score(Yact, Ypred, labels=[encoded_label], average='macro', zero_division=0)
- recall_list.append(recall)
- f1 = f1_score(Yact, Ypred, labels=[encoded_label], average='macro', zero_division=0)
- f1_list.append(f1)
- TPR = TP / (TP + FN) if (TP + FN) != 0 else 0
- TPR_list.append(TPR)
- TNR = TN / (TN + FP) if (TN + FP) != 0 else 0
- TNR_list.append(TNR)
- FPR = 1 - TNR
- FPR_list.append(FPR)
- FNR = 1 - TPR
- FNR_list.append(FNR)
- classwiseMetrics_df = pd.DataFrame({
- 'Class': classLabels,
- 'TP':TP_list,
- 'TN':TN_list,
- 'FP':FP_list,
- 'FN':FN_list,
- 'Accuracy': accuracy_list,
- 'Precision': precision_list,
- 'Recall': recall_list,
- 'F1-Score': f1_list,
- 'TPR': TPR_list,
- 'TNR': TNR_list,
- 'FPR': FPR_list,
- 'FNR': FNR_list})
- classwiseMetrics_df.to_excel(savePath + 'classwise_metrics.xlsx', index=False)
- # %%
- # create confusion matrix
- def createConfusionMatrix(Ypred,Yact,classEncoding,savePath):
- classLabels = list(classEncoding.keys())
- conf_matrix = confusion_matrix(Yact, Ypred)
- plt.figure(figsize=(12, 10))
- ax = sns.heatmap(conf_matrix, annot=False, fmt='d', cmap='Blues',cbar=True,
- linewidths=0.5, linecolor='gray',
- xticklabels=classLabels, yticklabels=classLabels)
- for i in range(conf_matrix.shape[0]):
- for j in range(conf_matrix.shape[1]):
- ax.text(j + 0.5, i + 0.5, str(conf_matrix[i, j]), ha="center", va="center",
- color="black", fontsize=12)
- cbar = ax.collections[0].colorbar
- cbar.ax.yaxis.set_major_formatter(plt.ScalarFormatter())
- cbar.ax.yaxis.set_tick_params(labelsize=14)
- plt.title('Confusion Matrix', fontsize=16)
- plt.xlabel('Predicted Label', fontsize=14)
- plt.ylabel('True Label', fontsize=14)
- plt.xticks(fontsize=12)
- plt.yticks(fontsize=12)
- plt.savefig(savePath + 'confusion_matrix.png', dpi=1200)
- plt.show()
- # %%
- # pre-process images
- def preProcess(input_img):
- output_img = cv2.cvtColor(input_img,cv2.COLOR_BGR2RGB)
- output_img = output_img.astype(np.float32) / 255.0
- return output_img
- # %%
- # read images and labels
- def readData(imageFolderPath,labelFilePath):
- images = []
- labels = []
- labels_df = pd.read_excel(labelFilePath)
- for idx, row in labels_df.iterrows():
- img_path = os.path.join(imageFolderPath, row['imageID'])
- image = cv2.imread(img_path)
- image = cv2.resize(image, imgSize)
- image = preProcess(image)
- images.append(image)
- labels.append(row['disease'])
- return np.array(images),np.array(labels)
- # %%
- def getTotalLabels(trainLabels,testLabels,valLabels):
- totalLabels = 0
- totalTrainLabels = len(set(list(trainLabels)))
- totalTestLabels = len(set(list(testLabels)))
- totalValLabels = len(set(list(valLabels)))
- if (totalTrainLabels == totalTestLabels and totalTrainLabels == totalValLabels):
- totalLabels = totalTrainLabels
- else:
- print('Total Labels Mismatch in Dataset Splits')
- return totalLabels
- # %%
- def oneHotEncoder(trainLabels, testLabels, valLabels,numLabels):
- label_encoder = LabelEncoder()
- all_labels = np.concatenate([trainLabels, testLabels, valLabels])
- label_encoder.fit(all_labels)
- trainLabels_encoded = label_encoder.transform(trainLabels)
- testLabels_encoded = label_encoder.transform(testLabels)
- valLabels_encoded = label_encoder.transform(valLabels)
- class_names = label_encoder.classes_
- class_to_encoder = {class_name: idx for idx, class_name in enumerate(class_names)}
- trainLabels_1Hot = to_categorical(trainLabels_encoded,num_classes=numLabels)
- testLabels_1Hot = to_categorical(testLabels_encoded,num_classes=numLabels)
- valLabels_1Hot = to_categorical(valLabels_encoded,num_classes=numLabels)
- return trainLabels_1Hot, testLabels_1Hot, valLabels_1Hot,class_to_encoder
- # %%
- # read images and labels
- Xtrain, Ytrain = readData(trainImagesPath,trainLabelsPath)
- Xtest, Ytest = readData(testImagesPath,testLabelsPath)
- Xval, Yval = readData(valImagesPath,valLabelsPath)
- totalLabels = getTotalLabels(Ytrain, Ytest, Yval)
- Ytrain, Ytest, Yval, class_encoding = oneHotEncoder(Ytrain, Ytest, Yval,totalLabels)
- print(Xtrain.shape)
- print(Xtest.shape)
- print(Xval.shape)
- print(class_encoding)
- # %%
- # comparison model
- def compMod1(inputShape,numLabels):
- inp = Input(shape = inputShape)
- baseModel = NASNetMobile(include_top=False, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- baseModel_output = baseModel.output
- x = GlobalAveragePooling2D()(baseModel_output)
- x = Flatten()(x)
- x = Dense(1024,activation='relu')(x)
- x = Dropout(0.3)(x)
- output = Dense(numLabels,activation='softmax')(x)
- model = Model(inp,output,name='compMod1')
- opt = Adam(learning_rate=0.001)
- model.compile(optimizer = opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # reference model
- def ltftnet(inputShape,numLabels):
- inp = Input(shape = inputShape)
- baseModel = NASNetMobile(include_top=False, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- baseModel_output = baseModel.get_layer('normal_concat_12').output
- x = Conv2D(512,(1,1),activation='relu')(baseModel_output)
- x = GlobalAveragePooling2D()(x)
- x = BatchNormalization(name='head-batchnorm-1')(x)
- x = Dense(512, activation='relu',name='head-dense-2')(x)
- x = Dropout(0.3,name='head-dropout-1')(x)
- x = Dense(256, activation='relu',name='head-dense-4')(x)
- output = Dense(numLabels, activation='softmax',name='class')(x)
- model = Model(inp,output,name='usmanrafi')
- opt = Adam(learning_rate=1e-4)
- model.compile(optimizer = opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # comparison model
- def compMod2(inputShape,numLabels):
- inp = Input(shape = inputShape)
- x = Conv2D(32,(3,3),activation='relu',strides=1)(inp)
- x = MaxPooling2D((2,2))(x)
- x = Conv2D(64,(3,3),activation='relu',strides=1)(x)
- x = MaxPooling2D((2,2))(x)
- x = Conv2D(128,(3,3),activation='relu',strides=1)(x)
- x = MaxPooling2D((2,2))(x)
- x = Conv2D(256,(3,3),activation='relu',strides=1)(x)
- x = MaxPooling2D((2,2))(x)
- x = Flatten()(x)
- x = Dropout(0.4)(x)
- output = Dense(numLabels, activation='softmax',name='class')(x)
- model = Model(inp,output,name='compMod2')
- opt = Adam(learning_rate=0.001)
- model.compile(optimizer = opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # comparison model
- def compMod3(inputShape,numLabels):
- inp = Input(shape=inputShape)
- baseModel1 = DenseNet121(include_top=False, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel1.trainable = False
- baseModel1_output = baseModel1.output
- baseModel2 = EfficientNetB5(include_top=False, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel2.trainable = False
- baseModel2_output = baseModel2.output
- f = Concatenate()([baseModel1_output,baseModel2_output])
- gap = GlobalAveragePooling2D()(f)
- gmp = GlobalMaxPooling2D()(f)
- x = Add()([gap,gmp])
- x = Flatten()(x)
- x = BatchNormalization()(x)
- x = Dropout(0.25)(x)
- x = Dense(512,activation='relu')(x)
- x = BatchNormalization()(x)
- x = Dropout(0.25)(x)
- output = Dense(numLabels,activation='softmax')(x)
- model = Model(inp,output,name='compMod3')
- opt = Adam(learning_rate=0.001)
- model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # comparison model
- def transBlock(x):
- x = SeparableConv2D(64, (1, 1), padding='same')(x)
- x = BatchNormalization()(x)
- x = ReLU()(x)
- x = SeparableConv2D(128, (3, 3), padding='same')(x)
- x = BatchNormalization()(x)
- x = ReLU()(x)
- x = SeparableConv2D(256, (1, 1), padding='same')(x)
- x = BatchNormalization()(x)
- x = ReLU()(x)
- x = Conv2DTranspose(256, (3, 3), strides=(2, 2), padding='same')(x)
- x = MaxPooling2D((2, 2))(x)
- return x
- def addLayer(x):
- x = SeparableConv2D(256, (1, 1), padding='same')(x)
- x = BatchNormalization()(x)
- return x
- def compMod4(inputShape, numLabels):
- inp = Input(shape=inputShape)
- vgg_input = Input(shape=inputShape)
- vgg_base = VGG16(include_top=False, input_tensor=vgg_input, weights='imagenet')
- vgg_base.trainable = False
- leftOut = vgg_base.output
- leftOut_TransBlock = transBlock(leftOut)
- leftOut_Addl = addLayer(leftOut)
- leftF = Add()([leftOut_TransBlock, leftOut_Addl])
- vgg_model = Model(vgg_input, leftF)
- xcep_input = Input(shape=inputShape)
- xcep_base = Xception(include_top=False, input_tensor=xcep_input, weights='imagenet')
- xcep_base.trainable = False
- rightOut = xcep_base.output
- rightOut_TransBlock = transBlock(rightOut)
- rightOut_Addl = addLayer(rightOut)
- rightF = Add()([rightOut_TransBlock, rightOut_Addl])
- xcep_model = Model(xcep_input, rightF)
- leftF_out = vgg_model(inp)
- rightF_out = xcep_model(inp)
- f = Add()([leftF_out, rightF_out])
- x = Flatten()(f)
- x = Dense(256)(x)
- x = Dropout(0.2)(x)
- x = Dense(128)(x)
- x = Dropout(0.3)(x)
- x = Dense(64)(x)
- output = Dense(numLabels, activation='softmax')(x)
- model = Model(inp, output,name='compMod4')
- opt = Adam(learning_rate=0.001)
- model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
- return model
- # %%
- # Fine-tuned transfer learning model
- def ftmod1(inputShape,numLabels):
- inp = Input(shape=inputShape)
- baseModel = NASNetMobile(include_top=True, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- baseModel_secondLastLayer = baseModel.layers[-2].output
- output = Dense(numLabels,activation='softmax')(baseModel_secondLastLayer)
- model = Model(inp,output,name='ftmod1')
- opt = Adam(0.001)
- model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # Fine-tuned transfer learning model
- def ftmod2(inputShape,numLabels):
- inp = Input(shape=inputShape)
- baseModel = MobileNet(include_top=True, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- baseModel_secondLastLayer = baseModel.layers[-2].output
- output = Dense(numLabels,activation='softmax')(baseModel_secondLastLayer)
- model = Model(inp,output,name='ftmod2')
- opt = Adam(0.001)
- model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # Fine-tuned transfer learning model
- def ftmod3(inputShape,numLabels):
- inp = Input(shape=inputShape)
- baseModel = MobileNetV2(include_top=True, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- baseModel_secondLastLayer = baseModel.layers[-2].output
- output = Dense(numLabels,activation='softmax')(baseModel_secondLastLayer)
- model = Model(inp,output,name='ftmod3')
- opt = Adam(0.001)
- model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # Fine-tuned transfer learning model
- def ftmod4(inputShape,numLabels):
- inp = Input(shape=inputShape)
- baseModel = DenseNet121(include_top=True, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- baseModel_secondLastLayer = baseModel.layers[-2].output
- output = Dense(numLabels,activation='softmax')(baseModel_secondLastLayer)
- model = Model(inp,output,name='ftmod4')
- opt = Adam(0.001)
- model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # Fine-tuned transfer learning model
- def ftmod5(inputShape,numLabels):
- inp = Input(shape=inputShape)
- baseModel = EfficientNetB0(include_top=True, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- #baseModel_secondLastLayer = baseModel.layers[-2].output
- baseModel_secondLastLayer = baseModel.get_layer('top_dropout').output
- output = Dense(numLabels,activation='softmax')(baseModel_secondLastLayer)
- model = Model(inp,output,name='ftmod5')
- opt = Adam(0.001)
- model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # Fine-tuned transfer learning model
- def ftmod6(inputShape,numLabels):
- inp = Input(shape=inputShape)
- baseModel = EfficientNetV2B0(include_top=True, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- #baseModel_secondLastLayer = baseModel.layers[-2].output
- baseModel_secondLastLayer = baseModel.get_layer('top_dropout').output
- output = Dense(numLabels,activation='softmax')(baseModel_secondLastLayer)
- model = Model(inp,output,name='ftmod6')
- opt = Adam(0.001)
- model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # comparison model
- def compMod5(inputShape,numLabels):
- inp = Input(shape=inputShape)
- baseModel = NASNetMobile(include_top=False, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- baseModel_output = baseModel.output
- x = GlobalAveragePooling2D()(baseModel_output)
- output = Dense(numLabels,activation='softmax')(x)
- model = Model(inp,output,name="compMod5")
- opt = Adam(learning_rate=0.001)
- model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # comparison model
- def compMod6(inputShape,numLabels):
- inp = Input(shape=inputShape)
- baseModel = NASNetMobile(include_top=False, input_shape=inputShape, weights='imagenet',input_tensor=inp)
- baseModel.trainable = False
- baseModel_output = baseModel.output
- x = Flatten()(baseModel_output)
- x = Dense(256,activation='relu')(x)
- x = Dropout(0.35)(x)
- x = Dense(128,activation='relu')(x)
- x = Dropout(0.35)(x)
- output = Dense(numLabels,activation='softmax')(x)
- model = Model(inp,output,name="compMod6")
- opt = Adam(learning_rate=0.001)
- model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
- return model
- # %%
- # Get Model for training
- myModel = ltftnet((Xtrain[0].shape),totalLabels)
- printModelSummary(myModel)
- # %%
- # image augmentation
- train_datagen = ImageDataGenerator(
- rotation_range=30,
- width_shift_range=0.2,
- height_shift_range=0.2,
- shear_range=0.2,
- zoom_range=0.2,
- horizontal_flip=True,
- fill_mode='nearest'
- )
- train_generator = train_datagen.flow(
- Xtrain,
- Ytrain,
- batch_size=batchSize
- )
- # %%
- # LR Scheduler
- reduce_lr = tf.keras.callbacks.ReduceLROnPlateau(
- monitor='val_accuracy',
- factor=0.5,
- patience=3,
- verbose=1,
- min_lr=1e-7
- )
- # training loop
- trainingTime = 0
- numEpochs = 30
- start = time.time()
- history = myModel.fit(train_generator,steps_per_epoch=len(train_generator),epochs=numEpochs,validation_data=(Xval,Yval),shuffle=True,verbose=1,callbacks=[reduce_lr])
- end = time.time()
- trainingTime = end - start
- # %%
- # Loading models with saved weights and biases for generalizability
- modelPath = 'path/modName.h5'
- myModel = load_model(modelPath)
- print(myModel.summary())
- # %%
- # Warmup model
- dummy_input = np.random.rand(1, 224, 224, 3).astype(np.float32)
- _ = myModel.predict(dummy_input, batch_size=1)
- # test
- testingTime = 0
- start = time.time()
- Ypred = myModel.predict(Xtest)
- end = time.time()
- testingTime = end - start
- Ypred = np.argmax(Ypred, axis=1)
- Yact = np.argmax(Ytest, axis=1)
- # %%
- # Print total number of actual labels and model's predicted labels
- print(len(Ypred))
- print(len(Yact))
- # %%
- # results
- saveTime(trainingTime,testingTime,outPath)
- saveModelRunHistory(history,outPath)
- saveModel(myModel,outPath,'modelName')
- # %%
- # results
- plotAccuracy(history,outPath)
- plotLoss(history,outPath)
- # %%
- # results
- testMetricsOverall(Ypred,Yact,outPath)
- testMetricsClassWise(Ypred,Yact,class_encoding,outPath)
- createConfusionMatrix(Ypred,Yact,class_encoding,outPath)
kerasMods.ipynb at commit de72ecc, under MIT · at the source
Overview
- Department of Computer Science, Faculty of Sciences, University of Agriculture, Faisalabad, Punjab, Pakistan
- Department of Pathology, Faculty of Veterinary Science, University of Agriculture, Faisalabad, Punjab, Pakistan
Abstract
Convolutional Neural Networks (CNNs) require a larger amount of input samples and computing resources to learn discriminative features for accurate identification of multiple retinal conditions, making the development and deployment of such models challenging on limited computing resources. This study presents a robust CNN (called LiteFeatNet) that requires fewer trainable parameters, computational resources, and processing time for accurate prediction. To enhance robustness and reduce computational time, a pre-trained NASNetMobile backbone is employed, and a method for time-efficient discriminative feature extraction from deep intermediate layers is proposed. The extracted features are refined using a spatially-aware feature map reduction module and classified using a custom classification module with fewer number of trainable parameters, reduced computational resource requirements, and computational time. Experiments are conducted using 1824 images from three distinct class labels in the Retinal Fundus Multi-Disease Image Dataset (RFMiD), with a 60:20:20 train-validation-test split. The LiteFeatNet architecture has a compact size (19.87 MB) and was trained using a standard pre-processing pipeline and training configurations. It outperformed twelve state-of-the-art models, achieving the highest testing accuracy of 90.33%, precision of 90.69%, recall of 90.33%, and F1-score of 90.27%, with a fast, impressive inference time of 4 milliseconds per image. Further, a generalizability study was also conducted using an external dataset, RFMiD 2.0, and the LiteFeatNet achieved competitive performance with quicker testing time compared to other architectures. To evaluate the scalability and adaptability of our proposed integrated framework for larger multi-class problems, we assessed the scalability by increasing class label complexity using two additional disease categories. Results validated the effectiveness and computational efficiency of this integrated framework compared with 9 baseline architectures. An ablation study was also conducted using the LiteFeatNet and two top-performing transfer learning architectures to validate that the synergistic combination of deep feature extraction and feature map refinement is the primary design decision behind the success of the LiteFeatNet architecture. The evaluation metrics, thus obtained, strongly suggest that the proposed LiteFeatNet is lightweight, fast, and robust, rendering it suitable for deployment in low-resource clinical settings.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 3 matches between paragraphs and lines of code.
usmanrafics/LTFTNET
de72ecc81c4be3bb15f7468cfb0d50aa766d7999, 10 August 2026Availability: 1 check, the latest on 28 September 2026: the link answers
- 28 September 2026: the link answers
5 files
- code-nb-k.ipynb, Jupyter, 876 lines
- code-nb-p.ipynb, Jupyter, 481 lines, 1 match
- kerasMods.ipynb, Jupyter, 617 lines, 2 matches
- LICENSE, License, 21 lines
- README.md, Text, 45 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 3 scripts, each with its path and the digest of its content;
- 3 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- data.mendeley.com/
datasets/ , at Mendeley Data; found in the referencess9bfhswzjb - kaggle.com/
datasets/ , at Kaggle; found in the referencesandrewmvd - kaggle.com/
datasets/ , at Kaggle; found in the referenceslinabennaa - zenodo:7505822, at Zenodo; found in the references
Data Availability
All three datasets can be found at the following recommended repositories. Dataset1 - RFMiD 1: https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 28 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 7 MeSH terms, 47 references.
Cite
This paper
Rafi, U., Nawaz, Q., Latif, M. A., & Khatoon, A. (2026). LiteFeatNet: A parameter-efficient and performance-centric deep learning model for multi-ocular disease identification using intermediate feature reduction from fundus images. PloS one, 21(5), e0347867. https://
BibTeX
@article{rafi2026litefea
author = {Rafi, Usman and Nawaz, Qamar and Latif, Muhammad Ahsan and Khatoon, Aisha},
title = {{LiteFeatNet: A parameter-efficient and performance-centric deep learning model for multi-ocular disease identification using intermediate feature reduction from fundus images}},
journal = {PloS one},
year = {2026},
month = may,
volume = {21},
number = {5},
pages = {e0347867},
publisher = {PLOS},
issn = {1932-6203},
doi = {10.1371/
url = {https://
pmid = {42113782},
pmcid = {PMC13160359}
}
RIS
TY - JOUR
AU - Rafi, Usman
AU - Nawaz, Qamar
AU - Latif, Muhammad Ahsan
AU - Khatoon, Aisha
TI - LiteFeatNet: A parameter-efficient and performance-centric deep learning model for multi-ocular disease identification using intermediate feature reduction from fundus images
T2 - PloS one
J2 - PLoS One
PY - 2026
DA - 2026/
VL - 21
IS - 5
SP - e0347867
SN - 1932-6203
PB - PLOS
DO - 10.1371/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1371/
"type": "article-journal",
"title": "LiteFeatNet: A parameter-efficient and performance-centric deep learning model for multi-ocular disease identification using intermediate feature reduction from fundus images",
"container-title": "PloS one",
"author": [
{
"family": "Rafi",
"given": "Usman"
},
{
"family": "Nawaz",
"given": "Qamar"
},
{
"family": "Latif",
"given": "Muhammad Ahsan"
},
{
"family": "Khatoon",
"given": "Aisha"
}
],
"container-title-short":
"volume": "21",
"issue": "5",
"page": "e0347867",
"DOI": "10.1371/
"PMID": "42113782",
"PMCID": "PMC13160359",
"ISSN": "1932-6203",
"publisher": "PLOS",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
11
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1038/s41597-025-05174-7 [code]
- A large-scale MEG and EEG dataset for object recognition in naturalistic scenesJournal: n/aIn common: Keras, TensorFlow, OpenCV, 7 other tools, methods / tools
- [2] doi:10.1126/sciadv.aed3650 [code]
- Truthful visualizations for mass spectrometry imaging enable high-spatial-resolution interactive &
lt;i& gt;m/ z& lt;/ i& gt; mapping and exploration. Journal: Science advancesIn common: Keras, TensorFlow, OpenCV, 6 other tools, other, methods / tools - [3] doi:10.1038/s42003-026-10957-8 [code]
- Brain defence by the extracellular matrix protein Cochlin.Journal: Communications biologyIn common: Keras, TensorFlow, OpenCV, 7 other tools
- [4] doi:10.1371/journal.pcbi.1014571 [code]
- SynAPSeg: A novel dataset and image analysis framework for deep learning-based synapse detection and quantification.Journal: PLoS computational biologyIn common: Keras, TensorFlow, OpenCV, 7 other tools
- [5] doi:10.1364/boe.605322 [code]
- Generalized plaque digitization framework for multi-dimensional mesoscopic images.Journal: Biomedical optics expressIn common: Keras, TensorFlow, OpenCV, 7 other tools
- [6] doi:10.1038/s41467-026-72057-9 [code]
- Sex-specific behavioral feedback modulates sensorimotor processing and drives flexible social behavior.Journal: Nature communicationsIn common: Keras, TensorFlow, OpenCV, 7 other tools
- [7] doi:10.1038/s41598-026-48475-6 [code]
- Optimized U-net model for precise retinal blood vessel segmentation from colour fundus images.Journal: Scientific reportsIn common: Keras, TensorFlow, OpenCV, 5 other tools, other, methods / tools
- [8] doi:10.1038/s41592-026-03057-2 [code]
- CREsted: modeling genomic and synthetic cell-type-specific enhancers across tissues and species.Journal: Nature methodsIn common: Keras, TensorFlow, Pillow, 6 other tools, methods / tools
- [9] doi:10.1126/sciadv.aee6952 [code]
- Wafer-scale SOT-MRAM for analog crossbar array applications.Journal: Science advancesIn common: Keras, TensorFlow, OpenCV, 6 other tools
- [10] doi:10.1093/jnen/nlaf152 [code]
- Clinical and pathologic correlations of machine learning quantification of Aβ deposits across 3 brain regions of decedents with Alzheimer disease.Journal: Journal of neuropathology and experimental neurologyIn common: Keras, TensorFlow, OpenCV, 6 other tools
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 3 scripts, and 3 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:b5a433c2aae207c8…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
