MahatirTusher commited on
Commit
5092eb8
·
verified ·
1 Parent(s): ded17e6

Upload 5 models

Browse files
Files changed (5) hide show
  1. Dockerfile +15 -0
  2. app.py +68 -0
  3. classes.txt +18 -0
  4. requirements.txt +0 -0
  5. wound_classifier_model_googlenet.h5 +3 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ FROM python:3.8-slim
3
+
4
+
5
+ WORKDIR /app
6
+
7
+ COPY requirements.txt requirements.txt
8
+
9
+ RUN pip install --no-cache-dir -r requirements.txt
10
+
11
+ COPY . .
12
+
13
+ EXPOSE 7860
14
+
15
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow.keras.models import load_model
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ # Load the model
8
+ try:
9
+ model = load_model('wound_classifier_model_googlenet.h5')
10
+ except Exception as e:
11
+ raise RuntimeError(f"Error loading model: {e}")
12
+
13
+ # Define the input shape
14
+ input_shape = (224, 224, 3)
15
+
16
+ def preprocess_image(image, target_size):
17
+ """
18
+ Preprocess the input image for the model.
19
+ - Resize the image to the target size.
20
+ - Normalize pixel values to the range [0, 1].
21
+ """
22
+ if image is None:
23
+ raise ValueError("No image provided")
24
+ image = image.convert("RGB") # Ensure the image is in RGB mode
25
+ image = image.resize(target_size)
26
+ image_array = np.array(image)
27
+ image_array = image_array / 255.0 # Normalize the image
28
+ return image_array
29
+
30
+ def predict(image):
31
+ """
32
+ Predict the class probabilities for the input image.
33
+ - Preprocess the image.
34
+ - Predict using the loaded model.
35
+ - Return results as a dictionary with class labels and probabilities.
36
+ """
37
+ try:
38
+ # Preprocess the image
39
+ input_data = preprocess_image(image, (input_shape[0], input_shape[1]))
40
+ input_data = np.expand_dims(input_data, axis=0) # Add batch dimension
41
+
42
+ # Load class labels
43
+ try:
44
+ with open('./classes.txt', 'r') as file:
45
+ class_labels = file.read().splitlines()
46
+ except FileNotFoundError:
47
+ raise RuntimeError("Class labels file 'classes.txt' not found.")
48
+
49
+ if len(class_labels) != model.output_shape[-1]:
50
+ raise ValueError("Mismatch between model output and class labels.")
51
+
52
+ # Predict probabilities
53
+ predictions = model.predict(input_data)
54
+ results = {class_labels[i]: float(predictions[0][i]) for i in range(len(class_labels))}
55
+ return results
56
+ except Exception as e:
57
+ return {"error": str(e)}
58
+
59
+ # Create a Gradio interface
60
+ iface = gr.Interface(
61
+ fn=predict,
62
+ inputs=gr.Image(type="pil"),
63
+ outputs=gr.Label(num_top_classes=18), # Adjust num_top_classes as needed
64
+ live=True
65
+ )
66
+
67
+ # Launch the Gradio interface
68
+ iface.launch(server_name="0.0.0.0", server_port=7860)
classes.txt ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Abrasions: 0
2
+ Bruises: 1
3
+ Burns: 2
4
+ Cut: 3
5
+ Diabetic Wounds: 4
6
+ Gingivitis: 5
7
+ Surgical Wounds: 6
8
+ Venous Wounds: 7
9
+ athlete foot: 8
10
+ cellulitis: 9
11
+ chickenpox: 10
12
+ cutaneous larva migrans: 11
13
+ impetigo: 12
14
+ nail fungus: 13
15
+ ringworm: 14
16
+ shingles: 15
17
+ tooth discoloration: 16
18
+ ulcer: 17
requirements.txt ADDED
Binary file (320 Bytes). View file
 
wound_classifier_model_googlenet.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f89fe0041825789e66caf712515f1265f43b05b5b843db2da5840f30a7abcbe
3
+ size 113524192