## Table of contents
* [General info](#general-info)
* [Technologies](#technologies)
* [Files and Folders](#files-and-folders)
* [Setup](#Setup)
* [Workflow](#Workflow)
# General info
The objective of the project is to build a pytorch segmentation model which can identify defect location on steel surface. The segmentation model used here is Unet with Resnet encoder. For this we have used the open surface defect database from Northeaster University(NEU).
In this database, six kinds of typical surface defects of the hot-rolled steel strip are collected, i.e., rolled-in scale (RS), patches (Pa), crazing (Cr), pitted surface (PS), inclusion (In) and scratches (Sc). The images provided in the database are in grayscale and of uniform dimensions 200x200. A snapshot of how the images looks like are shown below:-
![alt text](http://faculty.neu.edu.cn/yunhyan/Webpage%20for%20article/NEU%20surface%20defect%20database/Fig.2.png)
The database can be found in the below link:-
http://faculty.neu.edu.cn/yunhyan/NEU_surface_defect_database.html
The description of the database in the above url states that the database includes 1,800 grayscale images: 300 samples each of six different kinds of typical surface defects
The defect images are found in the folder named IMAGES. The folder named ANNOTATIONS contains the details of the defect location on each image in xml files.
Before we started with the project we ran the script named Create_Validation_Images.ipynb. This script created two folders named Validation_Images and Validation_Annotations. The script randomly selected five images from each class and moved those images and their annotation xmls to the folders Validation_Images and Validation_Annotations respectively. The model training won't be done on the images present in the Validation_Images. These images will be only used for final validation with our model.
The details of the key files and folders are given below.
## Technologies
The technologies used in this project are given below:-
* Python(v3.7.10)
* Pytorch(v1.8.1)
## Files and Folders
Below is the description of the important files and folders in the project:-
* **ANNOTATIONS** - This folder contains the annotation xmls of the samples on which model training and validation were done.
* **IMAGES** - This folder contains the sample images which were used for mode training and validation.
* **Validation_Annotations** - This folder contains the annotation xmls of the images which won't be used for model training and validation.
* **Validation_Images** - This folder contains the images which won't be used for model training and validation. The images from this folder are used for inferencing.
* **Models** - This folder contains the trained model's .pth file.
* **Utilities** - This folder contains some custom utility scripts that are required for model training, evalutation and inferencing. The python scripts present in this folder are listed below:-
* **Meter.py** - This python script contains the calculation logic for the metrics used for model evaluation i.e IOU, Dice Coefficient, Dice Positive and Dice Negative.
* **Trainer.py** - This python script contains logic to train the model.
* **Data_Retriever_Seg.py** - The output of this python script are Train and Test Datasets.
* **Extract_masks.py** - This file has functions to extract masks from the annotation xmls.
* **Resnet_Unet.py** - This python script contains the model class. The model returned by this script is a Unet model with Resnet encoder.
* **Data_Retriever_Inference_Real_Time.py** - This script returns the data loader for inferencing.
* **Create_Validation_Images.ipynb** - This ipynb file creates two folders named Validation_Images and Validation_Annotations. The script randomly selected five images from each class and moved those images and their annotation xmls to the folders Validation_Images and Validation_Annotations respectively. The model training won't be done on the images present in the Validation_Images. These images will be only used for final validation with our model.
* **Exploratory_Data_Analysis.ipynb** - This ipynb file gives an analysis of the data.
* **Train_Segmentation_Model_FPN+inceptionv4.ipynb** - This ipynb file is used to train an FPN with inceptionv4 encoder.
* **Train_Segmentation_Model_FPN+Resnet.ipynb** - This ipynb file is used to train an FPN with resnet34 encoder.
* **Train_Segmentation_Model_FPN+xception.ipynb** - This ipynb file is used to train an FPN with xception encoder.
* **Train_Segmentation_Model_Unet+Resnet.ipynb** - This ipynb file is used to train an Unet with resnet34 encoder.
* **Inference_Script.ipynb** - This ipynb file is used for inferencing. It reads the images from the Validation_Images folder as input and generates the masks as output. It also shows the comparison of the predicted mask with the original mask.
## Setup
This section gives an overview of how to use the project.
* Install the requirements from the requirements.txt file using the command **pip install -r requirements.txt**.
* First to get an overview about the data have a look at the ipynb file named Exploratory_Data_Analysis.ipynb.
* The respective model trainings can be done by the script Train_Segmentation_Model** scripts.
* Once, the model has been trained the script named Inference_Script.ipynb can be used to get inference on the validation images.
## Workflow
This section gives an overview of the workflow.
* **Separating files for validation** - As mentioned earlier before the experiment is started we need to separate some images and xmls for each defect class. These are the files that won't be used for training and cross validation. These files will be only used for inferencing. The Create_Validation_Images.ipynb file is used for this purpose. A visual representation of this is shown below:-
![fig 1](./Workflow_Images/Data_Separation.jpg)
* **Training Worflow** - Once, the data separation was done the training process was started. The pytorch framework with CUDA support was used for training. The below git repository made by qubvel was used for building segmentation models.
https://github.com/qubvel/segmentation_models.pytorch
This repository provides several architectures for image segmentaion. The library provides the necessary instructions on how to use the architectures. The architectures that were tried for this project are given below:-
* Unet with Resnet34 encoder
* FPN with Resnet34 encoder
* FPN with inceptionv4 encoder
* FPN with xception encoder
Irrespective of the architecture used the training process is same. This includes the below steps:-
* Starting the model training by executing one of the Train_Segmentation_Model scripts.
* All those scripts calls the start function of the Trainer script to start the training.
* This in turn calls the Data_Retriever script to generate the data loaders for both training and validation. The batch size used was 4.
* At the end of each epoch evaluate if the validation dice score is better than the previous best score. If it is better then save the model state.
A visual representation of the above workflow is shown below:-
![fig 2](./Workflow_Images/Training_Workflow.jpg)
* **Inferencing** - For this the Inference_Script was used. In this step one of the saved model is used to generate the masks for the unknown images in the Validation_Images folder. Also, comparison is done between the predicted masks and the actual masks from the corresponding xml files in the Validation_Annotation folder.
A visual representation of the same is shown below:-
![image](https://user-images.githubusercontent.com/63548045/119221648-e8d25700-bb0d-11eb-90bd-901d0976295e.png)
![image](https://user-images.githubusercontent.com/63548045/119221661-fe478100-bb0d-11eb-890e-ff0302fe0edf.png)
![image](https://user-images.githubusercontent.com/63548045/119221692-161f0500-bb0e-11eb-8452-d1442527098a.png)
![image](https://user-ima
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
缺陷检测项目-使用UNet实现钢材表面缺陷检测-使用NEU-DET数据集-优质项目实战.zip (2000个子文件)
Exploratory_Data_Analysis.ipynb 3.23MB
Training_Workflow.jpg 102KB
Data_Separation.jpg 89KB
crazing_264.jpg 23KB
crazing_268.jpg 23KB
crazing_252.jpg 23KB
crazing_272.jpg 23KB
crazing_190.jpg 23KB
crazing_191.jpg 23KB
crazing_279.jpg 23KB
crazing_297.jpg 23KB
crazing_197.jpg 23KB
crazing_233.jpg 23KB
crazing_298.jpg 23KB
crazing_92.jpg 23KB
crazing_295.jpg 23KB
crazing_231.jpg 23KB
crazing_4.jpg 22KB
crazing_1.jpg 22KB
crazing_234.jpg 22KB
crazing_149.jpg 22KB
patches_67.jpg 22KB
patches_125.jpg 22KB
crazing_161.jpg 22KB
crazing_24.jpg 22KB
patches_66.jpg 22KB
crazing_133.jpg 22KB
patches_3.jpg 22KB
patches_277.jpg 22KB
crazing_131.jpg 22KB
crazing_103.jpg 21KB
patches_248.jpg 21KB
crazing_95.jpg 21KB
patches_217.jpg 21KB
patches_243.jpg 21KB
patches_189.jpg 21KB
patches_148.jpg 21KB
patches_5.jpg 21KB
patches_280.jpg 21KB
patches_108.jpg 21KB
patches_16.jpg 21KB
crazing_3.jpg 21KB
patches_241.jpg 21KB
patches_238.jpg 21KB
patches_236.jpg 20KB
patches_77.jpg 20KB
crazing_23.jpg 20KB
crazing_8.jpg 20KB
patches_35.jpg 20KB
patches_90.jpg 20KB
patches_292.jpg 20KB
patches_200.jpg 20KB
crazing_45.jpg 20KB
patches_19.jpg 20KB
crazing_276.jpg 19KB
patches_118.jpg 19KB
patches_270.jpg 19KB
patches_139.jpg 19KB
crazing_213.jpg 19KB
crazing_204.jpg 19KB
crazing_76.jpg 19KB
crazing_195.jpg 19KB
patches_300.jpg 19KB
rolled-in_scale_82.jpg 18KB
crazing_72.jpg 18KB
rolled-in_scale_83.jpg 18KB
rolled-in_scale_93.jpg 18KB
rolled-in_scale_179.jpg 18KB
rolled-in_scale_180.jpg 18KB
rolled-in_scale_144.jpg 17KB
rolled-in_scale_162.jpg 17KB
rolled-in_scale_155.jpg 17KB
pitted_surface_60.jpg 17KB
patches_142.jpg 17KB
rolled-in_scale_187.jpg 17KB
rolled-in_scale_2.jpg 17KB
rolled-in_scale_205.jpg 17KB
patches_233.jpg 17KB
rolled-in_scale_120.jpg 17KB
rolled-in_scale_166.jpg 17KB
crazing_53.jpg 17KB
rolled-in_scale_47.jpg 16KB
rolled-in_scale_16.jpg 16KB
rolled-in_scale_191.jpg 16KB
rolled-in_scale_26.jpg 16KB
rolled-in_scale_67.jpg 16KB
rolled-in_scale_56.jpg 16KB
rolled-in_scale_224.jpg 16KB
rolled-in_scale_30.jpg 16KB
patches_299.jpg 16KB
pitted_surface_190.jpg 15KB
patches_261.jpg 15KB
pitted_surface_170.jpg 15KB
pitted_surface_78.jpg 15KB
pitted_surface_243.jpg 15KB
rolled-in_scale_265.jpg 15KB
pitted_surface_166.jpg 15KB
rolled-in_scale_103.jpg 15KB
rolled-in_scale_238.jpg 15KB
pitted_surface_6.jpg 14KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
极智视界
- 粉丝: 2w+
- 资源: 1459
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功