Skip to content

Commit

Permalink
Merge pull request #427 from the-silent-geek/Railway_Track_Fault_dete…
Browse files Browse the repository at this point in the history
…ction

Track fault detection using DL
  • Loading branch information
abhisheks008 authored Jan 8, 2024
2 parents 9fa1b72 + 7a9dc16 commit 7ec6d84
Show file tree
Hide file tree
Showing 12 changed files with 2,782 additions and 80 deletions.
160 changes: 80 additions & 80 deletions Railway Track Fault Detection/Model/conv.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
# A Python script to change the size of images and save them inside a new directory
# The script contains two functions:
# 1. To change the names of current images to standard number labels.
# 2. To convert the images of random sizes to a fixed size 200X200 resolution.
# This makes the further process of training the model easy as dimensions of each image
# are the same


# Import all the necessary modules
import cv2
import glob
import os


# Source folder location of images
defective = "D://ML DL AI DSBDA//Railway Track Fault Detection//archive//images//Defective"
nonDefective = "D://ML DL AI DSBDA//Railway Track Fault Detection//archive//images//Non Defective"
# Create a separate directory to store processed images



def changeNames(path: str) -> None:
'Change the naming conventions of images:'
k = 0
location = os.chdir(path)
for old_file_name in os.listdir(location):
new_file_name = '{}.jpg'.format(k)
os.rename(old_file_name, new_file_name)
k += 1


def changeDimensionsForDefectiveImages(width: int, height: int) -> None:
'Change the random dimensions of all images to a fixed resolution and then insert into a new folder'
i = 0
for img in glob.glob(defective + '//*.jpg'):
image = cv2.imread(img)
imageResized = cv2.resize(image, (width, height))

# cv2.imshow('frame', image)

cv2.imwrite(
"D://ML DL AI DSBDA//Railway Track Fault Detection//Processed Images//Defective//000{}.jpg".format(i), imageResized)
cv2.waitKey(0)
i += 1

# if i == 2:
# break

cv2.destroyAllWindows()

def changeDimensionsForNonDefectiveImages(width: int, height: int) -> None:
'Change the random dimensions of all images to a fixed resolution and then insert into a new folder'
i = 0
for img in glob.glob(nonDefective + '//*.jpg'):
image = cv2.imread(img)
imageResized = cv2.resize(image, (width, height))

# cv2.imshow('frame', image)
cv2.imwrite(
"D://ML DL AI DSBDA//Railway Track Fault Detection//Processed Images//Non Defective//000{}.jpg".format(i), imageResized)
cv2.waitKey(0)
i += 1

# if i == 2:
# break

cv2.destroyAllWindows()


def main():
defectiveImagePath = 'D://ML DL AI DSBDA//Railway Track Fault Detection//archive//Images//Defective'
nonDefectivePath = 'D://ML DL AI DSBDA//Railway Track Fault Detection//archive//Images//Non Defective'
changeNames(defectiveImagePath)
changeNames(nonDefectivePath)
changeDimensionsForDefectiveImages(256, 256)
changeDimensionsForNonDefectiveImages(256, 256)


if __name__ == '__main__':
main()
# A Python script to change the size of images and save them inside a new directory
# The script contains two functions:
# 1. To change the names of current images to standard number labels.
# 2. To convert the images of random sizes to a fixed size 200X200 resolution.
# This makes the further process of training the model easy as dimensions of each image
# are the same


# Import all the necessary modules
import cv2
import glob
import os


# Source folder location of images
defective = "D://ML DL AI DSBDA//Railway Track Fault Detection//archive//images//Defective"
nonDefective = "D://ML DL AI DSBDA//Railway Track Fault Detection//archive//images//Non Defective"
# Create a separate directory to store processed images



def changeNames(path: str) -> None:
'Change the naming conventions of images:'
k = 0
location = os.chdir(path)
for old_file_name in os.listdir(location):
new_file_name = '{}.jpg'.format(k)
os.rename(old_file_name, new_file_name)
k += 1


def changeDimensionsForDefectiveImages(width: int, height: int) -> None:
'Change the random dimensions of all images to a fixed resolution and then insert into a new folder'
i = 0
for img in glob.glob(defective + '//*.jpg'):
image = cv2.imread(img)
imageResized = cv2.resize(image, (width, height))

# cv2.imshow('frame', image)

cv2.imwrite(
"D://ML DL AI DSBDA//Railway Track Fault Detection//Processed Images//Defective//000{}.jpg".format(i), imageResized)
cv2.waitKey(0)
i += 1

# if i == 2:
# break

cv2.destroyAllWindows()

def changeDimensionsForNonDefectiveImages(width: int, height: int) -> None:
'Change the random dimensions of all images to a fixed resolution and then insert into a new folder'
i = 0
for img in glob.glob(nonDefective + '//*.jpg'):
image = cv2.imread(img)
imageResized = cv2.resize(image, (width, height))

# cv2.imshow('frame', image)
cv2.imwrite(
"D://ML DL AI DSBDA//Railway Track Fault Detection//Processed Images//Non Defective//000{}.jpg".format(i), imageResized)
cv2.waitKey(0)
i += 1

# if i == 2:
# break

cv2.destroyAllWindows()


def main():
defectiveImagePath = 'D://ML DL AI DSBDA//Railway Track Fault Detection//archive//Images//Defective'
nonDefectivePath = 'D://ML DL AI DSBDA//Railway Track Fault Detection//archive//Images//Non Defective'
changeNames(defectiveImagePath)
changeNames(nonDefectivePath)
changeDimensionsForDefectiveImages(256, 256)
changeDimensionsForNonDefectiveImages(256, 256)


if __name__ == '__main__':
main()
53 changes: 53 additions & 0 deletions Track Fault Detection using DL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# <h1 align = "center"> Track Fault Detection using DL </h1>
## Aim of the project:
### The project focuses on detecting the faults in the railway tracks using various Deep Learning Algorithms
### Dataset Link: [railway Track fault Detection Resized (224 X 224) | Kaggle](https://www.kaggle.com/datasets/gpiosenka/railway-track-fault-detection-resized-224-x-224)

### Libraries and Frameworks used:
1. Pandas
2. Numpy
3. Matplotlib
4. Seaborn
5. Tensorflow
6. Keras
7. visualkeras
8. pickle
9. pillow
10. opendatasets


## Deep Learning Algorithms used:
1. Vgg16
2. ResNet50
3. InceptionV3
4. DenseNet
5. MobileNet

## Accuracy and training time comparison of all the Deep Learning Algorithms
| | Accuracy |
|-------------|---------------|
| Vgg16 | 96% |
| ResNet50 | 71% |
| InceptionV3 | 94% |
| DenseNet | 98% |
| MobileNet | 97% |

# Accuracy plots of all models

## Vgg16
![vgg16](https://github.com/the-silent-geek/DL-Simplified/blob/55596e0bfc60b5aba38f5bb64519fa9363dd5d61/Railway%20Track%20Fault%20Detection/images/vgg16.png)

## ResNet50
![resnet](https://github.com/the-silent-geek/DL-Simplified/blob/55596e0bfc60b5aba38f5bb64519fa9363dd5d61/Railway%20Track%20Fault%20Detection/images/ResNet.png)

## InceptionV3
![inception](https://github.com/the-silent-geek/DL-Simplified/blob/55596e0bfc60b5aba38f5bb64519fa9363dd5d61/Railway%20Track%20Fault%20Detection/images/inceptionV3.png)

## DenseNet
![densenet](https://github.com/the-silent-geek/DL-Simplified/blob/55596e0bfc60b5aba38f5bb64519fa9363dd5d61/Railway%20Track%20Fault%20Detection/images/densenet.png)

## MobileNet
![mobilenet](https://github.com/the-silent-geek/DL-Simplified/blob/55596e0bfc60b5aba38f5bb64519fa9363dd5d61/Railway%20Track%20Fault%20Detection/images/mobileNet.png)

# Conclusion
DenseNet model performs better comparative to other models used on the above dataset.
3 changes: 3 additions & 0 deletions Track Fault Detection using DL/dataset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## You can download the dataset from the following Link 🔗 :

### [https://www.kaggle.com/datasets/gpiosenka/railway-track-fault-detection-resized-224-x-224](url)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Track Fault Detection using DL/images/ResNet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Track Fault Detection using DL/images/vgg16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7ec6d84

Please sign in to comment.