Skip to content

Commit 68d1967

Browse files
committed
add english readme
1 parent a6d4dbb commit 68d1967

File tree

2 files changed

+231
-2
lines changed

2 files changed

+231
-2
lines changed

README.en.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# Image_Recognition_WebGUI
2+
3+
✨ An Alzheimer's intelligent diagnosis web application based on 3D convolutional neural network and the ADNI dataset: AI artificial intelligence image recognition-Pytorch; visualization Web graphic interface-Pywebio; nii medical image recognition. 100% pure Python.
4+
5+
🚩[简体中文文档](./README.md)
6+
7+
[Personal website: www.bytesc.top](http://www.bytesc.top) includes a lightweight version of the online demo.
8+
9+
[Lightweight version link](https://github.com/bytesc/Image-Recognition-system)
10+
11+
## Feature Introduction
12+
13+
- 1, Intelligent diagnosis of Alzheimer's disease based on brain MRI medical images.
14+
- 2, Draw parameter correlation heat map.
15+
- 3, Written in pure python, lightweight, easy to reproduce, easy to deploy.
16+
- 4, High code readability, with extremely detailed comments in the core part.
17+
18+
## Interface Display
19+
20+
- Enter the web interface
21+
![image](./readme_static/readme_img/4.png)
22+
- Click "Use demo.nii" to test the recognition function using the default demo image.
23+
![image](./readme_static/readme_img/3.png)
24+
- You can also upload your own medical images.
25+
![image](./readme_static/readme_img/9.png)
26+
- Click "View Image" to render the parameter heat map.
27+
![image](./readme_static/readme_img/5.png)
28+
![image](./readme_static/readme_img/6.png)
29+
- Generate a parameter correlation heat map based on the uploaded image.
30+
![image](./readme_static/readme_img/7.png)
31+
32+
## How to use
33+
34+
Python version 3.9
35+
36+
Requires `8GB` or more memory.
37+
38+
First install dependencies.
39+
40+
```bash
41+
pip install -r requirement.txt
42+
```
43+
44+
demo01.py is the project entry point. Run this file to start the server.
45+
46+
```bash
47+
python demo01.py
48+
```
49+
50+
Copy the link to your browser and open it.
51+
![image](./readme_static/readme_img/10.png)
52+
Click "Demo" to enter the Web interface.
53+
![image](./readme_static/readme_img/11.png)
54+
55+
After that, you can click "Use demo.nii" to use the default test case. You can also click "Upload.nii" and select different types of image files from the readme_static/test folder for testing.
56+
57+
## Project Structure
58+
59+
```
60+
└─Image_Recognition_WebGUI
61+
├─data
62+
│ └─model_save
63+
├─imgs
64+
│ ├─img_hot
65+
│ ├─img_merge
66+
│ └─img_raw
67+
├─nii
68+
├─readme_static
69+
│ ├─readme_img
70+
│ └─test
71+
│ ├─AD
72+
│ ├─CN
73+
│ ├─EMCI
74+
│ ├─LMCI
75+
│ └─MCI
76+
└─run_logs
77+
```
78+
79+
- The data folder stores some static resources, and the model_save folder stores trained models.
80+
- The imgs folder stores rendered images.
81+
- The nii folder stores user-uploaded medical image data.
82+
- readme_static stores static resources used in readme documents.
83+
- The readme_static/test folder contains some image files of five categories that can be used for testing.
84+
- run_logs stores user access logs.
85+
86+
87+
## Core code of the classifier
88+
89+
```python
90+
from torch import nn
91+
import torch
92+
93+
class ClassificationModel3D(nn.Module):
94+
"""Classification model"""
95+
def __init__(self, dropout=0.4, dropout2=0.4):
96+
nn.Module.__init__(self)
97+
98+
# Define four Conv3d layers
99+
self.Conv_1 = nn.Conv3d(1, 8, 3) # Input channel is 1, output channel is 8, kernel size is 3x3x3
100+
self.Conv_2 = nn.Conv3d(8, 16, 3) # Input channel is 8, output channel is 16, kernel size is 3x3x3
101+
self.Conv_3 = nn.Conv3d(16, 32, 3) # Input channel is 16, output channel is 32, kernel size is 3x3x3
102+
self.Conv_4 = nn.Conv3d(32, 64, 3) # Input channel is 32, output channel is 64, kernel size is 3x3x3
103+
104+
# Define four BatchNorm3d layers, one after each convolution layer
105+
self.Conv_1_bn = nn.BatchNorm3d(8)
106+
self.Conv_2_bn = nn.BatchNorm3d(16)
107+
self.Conv_3_bn = nn.BatchNorm3d(32)
108+
self.Conv_4_bn = nn.BatchNorm3d(64)
109+
110+
# Define four MaxPool3d layers, one after each convolution layer
111+
self.Conv_1_mp = nn.MaxPool3d(2) # Pooling kernel size is 2
112+
self.Conv_2_mp = nn.MaxPool3d(3) # Pooling kernel size is 3
113+
self.Conv_3_mp = nn.MaxPool3d(2) # Pooling kernel size is 2
114+
self.Conv_4_mp = nn.MaxPool3d(3) # Pooling kernel size is 3
115+
116+
# Define two fully connected layers
117+
self.dense_1 = nn.Linear(4800, 128) # Input dimension is 4800, output dimension is 128
118+
self.dense_2 = nn.Linear(128, 5) # Input dimension is 128, output dimension is 5. Since this is a five-class problem, the final output dimension must be 5
119+
120+
# Define ReLU activation function and dropout layer
121+
self.relu = nn.ReLU()
122+
self.dropout = nn.Dropout(dropout) # Prevent overfitting
123+
self.dropout2 = nn.Dropout(dropout2) # Enhance robustness
124+
125+
def forward(self, x):
126+
# First convolutional layer
127+
x = self.relu(self.Conv_1_bn(self.Conv_1(x)))
128+
"""
129+
This line of code performs convolutional, batch normalization and ReLU activation operations on the input x.
130+
131+
self.Conv_1(x) performs a 3D convolution operation on the input x and outputs a feature map.
132+
133+
self.Conv_1_bn(...) performs batch normalization on the feature map output by the convolution operation to obtain a normalized feature map.
134+
135+
self.relu(...) performs a ReLU activation function operation on the normalized feature map to obtain an activated feature map.
136+
137+
The purpose of this operation is to extract features from the input x and nonlinearize them so that the network can better learn these features. The batch normalization technique used here can accelerate the training process of the model and improve its generalization ability. The final output result is a feature map x processed by convolutional, batch normalization and ReLU activation functions.
138+
"""
139+
# Max pooling of the first convolutional layer
140+
x = self.Conv_1_mp(x)
141+
"""
142+
This line of code performs a maximum pooling operation on the input x to reduce the size of the feature map by half.
143+
144+
self.Conv_1_mp(...) performs a maximum pooling operation on the input x with a pooling kernel size of 2.
145+
146+
The pooling operation extracts the maximum value in each pooling window in the feature map as the value at the corresponding position in the output feature map, thereby reducing the size of the feature map by half.
147+
148+
Maximum pooling can help the network achieve spatial invariance so that it can recognize the same features when there are slight changes in the input. In this model, after maximum pooling, the feature map x will be passed to the next convolutional layer for feature extraction and nonlinear processing.
149+
"""
150+
151+
# Second convolutional layer
152+
x = self.relu(self.Conv_2_bn(self.Conv_2(x)))
153+
# Max pooling of second convolutional layer
154+
x = self.Conv_2_mp(x)
155+
# Third convolutional layer
156+
x = self.relu(self.Conv_3_bn(self.Conv_3(x)))
157+
# Max pooling of third convolutional layer
158+
x = self.Conv_3_mp(x)
159+
# Fourth convolutional layer
160+
x = self.relu(self.Conv_4_bn(self.Conv_4(x)))
161+
# Max pooling of fourth convolutional layer
162+
x = self.Conv_4_mp(x)
163+
# Flatten tensor into a one-dimensional vector
164+
x = x.view(x.size(0), -1)
165+
"""
166+
This line of code flattens the input tensor x into a one-dimensional vector.
167+
168+
x.size(0) gets the size of the first dimension of the input tensor x, which is the batch size of the tensor.
169+
170+
-1 means to flatten the second dimension and all dimensions after it into one dimension.
171+
172+
x.view(...) performs a shape transformation on the input tensor x, flattening it into a one-dimensional vector.
173+
174+
The purpose of this operation is to transform the feature map x processed by convolution and pooling into a one-dimensional vector so that it can be passed to the fully connected layer for classification or regression tasks. The size of the flattened vector is (batch_size, num_features), where batch_size is the batch size of the input tensor and num_features is the number of elements in the flattened vector, which is also the number of features after convolution and pooling processing.
175+
"""
176+
177+
# dropout layer
178+
x = self.dropout(x)
179+
"""
180+
This line of code performs a dropout operation on the input tensor x, i.e., sets some elements of the input tensor to zero with a certain probability.
181+
182+
self.dropout(...) performs a dropout operation on the input tensor x, with a dropout probability of dropout.
183+
184+
The dropout operation sets some elements of the input tensor to zero with a certain probability, achieving the purpose of random deactivation. This can reduce overfitting and enhance the generalization ability of the model.
185+
186+
In this model, the dropout operation is applied before the fully connected layer, which can help the model better learn the features of the data and prevent overfitting. The resulting x tensor is the result after the dropout operation and will be passed to the next fully connected layer for processing.
187+
"""
188+
# fully connected layer 1
189+
x = self.relu(self.dense_1(x))
190+
"""
191+
This line of code performs a fully connected operation on the input tensor x and applies the ReLU activation function.
192+
193+
self.dense_1(x) performs a fully connected operation on the input tensor x, mapping it to a feature space of size 128.
194+
195+
self.relu(...) applies the ReLU activation function to the output of the fully connected layer to obtain an activated feature vector.
196+
197+
In this model, the role of the fully connected layer is to map the feature vector processed by convolution, pooling, and dropout to a new feature space for classification or regression tasks. The role of the ReLU activation function is to nonlinearize the feature vector so that the network can better learn the nonlinear correlation in the data. The resulting x tensor is the result after processing by the fully connected layer and ReLU activation function and will be passed to the next dropout layer for processing.
198+
"""
199+
# dropout2 layer
200+
x = self.dropout2(x)
201+
# fully connected layer 2
202+
x = self.dense_2(x)
203+
# return output result
204+
return x
205+
206+
207+
if __name__ == "__main__":
208+
# create an instance of ClassificationModel3D class named model, i.e., create a 3D image classification model
209+
model = ClassificationModel3D()
210+
211+
# create a test tensor test_tensor with shape (1, 1, 166, 256, 256),
212+
# where 1 represents batch size, 1 represents input channel number, 166, 256 and 256 represent depth, height and width of input data respectively
213+
test_tensor = torch.ones(1, 1, 166, 256, 256)
214+
215+
# perform forward propagation on test tensor test_tensor to obtain output result output from model
216+
output = model(test_tensor)
217+
218+
# print shape of output result, i.e., (batch_size, num_classes), where batch_size is batch size of test tensor and num_classes is number of classes in classification task
219+
print(output.shape)
220+
221+
```
222+
223+
ref: https://github.com/moboehle/Pytorch-LRP
224+
225+
Datasets: https://adni.loni.usc.edu
226+
227+

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Image_Recognition_WebGUI
22

3-
基于 ADNI 数据集的阿尔兹海默智能诊断 Web 应用:AI 人工智能图像识别-Pytorch;可视化 Web 图形界面-Pywebio; nii 医学影像识别。100%纯 Python
3+
✨ 基于 3D 卷积神经网络和 ADNI 数据集的阿尔兹海默智能诊断 Web 应用:AI 人工智能图像识别-Pytorch;可视化 Web 图形界面-Pywebio; nii 医学影像识别。100%纯 Python
4+
5+
🚩[English Readme](./README.en.md)
46

57
[个人网站:www.bytesc.top](http://www.bytesc.top) 含轻量化版本在线演示
68

@@ -217,7 +219,7 @@ if __name__ == "__main__":
217219

218220
ref: https://github.com/moboehle/Pytorch-LRP
219221

220-
数据集:https://adni.loni.usc.edu"
222+
数据集:https://adni.loni.usc.edu
221223

222224
# 开源许可证
223225

0 commit comments

Comments
 (0)