harishvijayasarangan commited on
Commit
d7b796d
·
verified ·
1 Parent(s): 4b24210

Upload 19 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ sample/1.jpeg filter=lfs diff=lfs merge=lfs -text
37
+ sample/2.jpeg filter=lfs diff=lfs merge=lfs -text
38
+ sample/3.jpeg filter=lfs diff=lfs merge=lfs -text
39
+ sample/4.jpeg filter=lfs diff=lfs merge=lfs -text
40
+ sample/5.jpeg filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && apt-get install -y \
7
+ libgl1-mesa-glx \
8
+ libglib2.0-0 \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ # Copy requirements first for better caching
12
+ COPY requirements.txt .
13
+ RUN pip install --no-cache-dir -r requirements.txt
14
+
15
+ # Copy the rest of the application
16
+ COPY . .
17
+
18
+ # Expose the port the app runs on
19
+ EXPOSE 8080
20
+
21
+ # Command to run the application
22
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import onnxruntime
2
+ import numpy as np
3
+ import gradio as gr
4
+ from PIL import Image
5
+
6
+ labels = {
7
+ 0: "No DR",
8
+ 1: "Mild",
9
+ 2: "Moderate",
10
+ 3: "Severe",
11
+ 4: "Proliferative DR",
12
+ }
13
+ session = onnxruntime.InferenceSession('model.onnx')
14
+
15
+ def transform_image(image):
16
+ image = image.resize((224, 224))
17
+ img_array = np.array(image, dtype=np.float32) / 255.0
18
+ mean = np.array([0.5353, 0.3628, 0.2486], dtype=np.float32)
19
+ std = np.array([0.2126, 0.1586, 0.1401], dtype=np.float32)
20
+ img_array = (img_array - mean) / std
21
+ img_array = np.transpose(img_array, (2, 0, 1))
22
+ return np.expand_dims(img_array, axis=0).astype(np.float32)
23
+ def predict(input_img):
24
+ """Predict DR grade from input image using ONNX model"""
25
+ input_tensor = transform_image(input_img)
26
+ input_name = session.get_inputs()[0].name
27
+ output_name = session.get_outputs()[0].name
28
+ prediction = session.run([output_name], {input_name: input_tensor})[0][0]
29
+ exp_preds = np.exp(prediction - np.max(prediction))
30
+ probabilities = exp_preds / exp_preds.sum()
31
+ confidences = {labels[i]: float(probabilities[i]) for i in labels}
32
+ #filtered_confidences = {key: confidences[key] for key in ["No DR", "Severe"]}
33
+ #return filtered_confidences
34
+ return confidences
35
+
36
+ dr_app = gr.Interface(
37
+ fn=predict,
38
+ inputs=gr.Image(type="pil"),
39
+ outputs=gr.Label(),
40
+ title="Diabetic Retinopathy Detection",
41
+ description="",
42
+ examples=[
43
+ "sample/1.jpeg",
44
+ "sample/2.jpeg",
45
+ "sample/3.jpeg",
46
+ "sample/4.jpeg",
47
+ ],
48
+ analytics_enabled=False,
49
+ )
50
+ if __name__ == "__main__":
51
+ dr_app.launch(server_name="0.0.0.0", server_port=8080)
model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2df12f77e5a9240ad729d61a4e63c0304cb232bc99f47c4a166c2330efa0780
3
+ size 28227960
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ onnxruntime
2
+ numpy
3
+ gradio
4
+ Pillow
sample/1.jpeg ADDED

Git LFS Details

  • SHA256: e409d4ae7195bf2e97b92924a9c777810d6c58bd6e5a952ce49d02eb15411965
  • Pointer size: 131 Bytes
  • Size of remote file: 157 kB
sample/10_left.jpeg ADDED
sample/10_right.jpeg ADDED
sample/13_left.jpeg ADDED
sample/13_right.jpeg ADDED
sample/15_left.jpeg ADDED
sample/15_right.jpeg ADDED
sample/16_left.jpeg ADDED
sample/16_right.jpeg ADDED
sample/17_left.jpeg ADDED
sample/17_right.jpeg ADDED
sample/2.jpeg ADDED

Git LFS Details

  • SHA256: 580657a2a8f09c02d7c22658a1adb15ee5ae5a05bc55f8fbcc00d003c94c1b87
  • Pointer size: 131 Bytes
  • Size of remote file: 148 kB
sample/3.jpeg ADDED

Git LFS Details

  • SHA256: b2c8445c497101a6879ed7012d78583e1af464558ff4f5c81edbc0c836fce3e7
  • Pointer size: 131 Bytes
  • Size of remote file: 133 kB
sample/4.jpeg ADDED

Git LFS Details

  • SHA256: 2d8d228526aaedc6c2c439b39621ed3f5b8e39d8611308838a6c9b9b28cd3213
  • Pointer size: 131 Bytes
  • Size of remote file: 137 kB
sample/5.jpeg ADDED

Git LFS Details

  • SHA256: d00283a2c667926660becedf9f69005993fed6cc98a624fe0c85520a2b0f878e
  • Pointer size: 131 Bytes
  • Size of remote file: 132 kB