Spaces:
Sleeping
Sleeping
Finalize with comments
Browse files
app.py
CHANGED
|
@@ -1,30 +1,17 @@
|
|
| 1 |
import os
|
| 2 |
os.system('pip install tf_keras')
|
|
|
|
| 3 |
|
| 4 |
-
import torch
|
| 5 |
-
from torchvision import transforms
|
| 6 |
import tensorflow as tf
|
| 7 |
from tensorflow.keras.preprocessing import image
|
| 8 |
-
import tf_keras
|
| 9 |
import numpy as np
|
| 10 |
import gradio as gr
|
| 11 |
|
| 12 |
model_path = "./4-17_ViT-B16_Lung3_v4_E30/"
|
| 13 |
-
model = tf_keras.models.load_model(model_path)
|
| 14 |
|
| 15 |
# Define preprocessing function
|
| 16 |
def preprocess_image(image_path):
|
| 17 |
-
# transform_test = transforms.Compose([
|
| 18 |
-
# transforms.Resize((224, 224)),
|
| 19 |
-
# transforms.ToTensor(),
|
| 20 |
-
# transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
|
| 21 |
-
# ])
|
| 22 |
-
|
| 23 |
-
# preprocessed_img = transform_test(image)
|
| 24 |
-
# preprocessed_img = torch.transpose(preprocessed_img, 0, 2)
|
| 25 |
-
# return preprocessed_img
|
| 26 |
-
|
| 27 |
-
#-----------------------------------
|
| 28 |
# Load the image from file
|
| 29 |
img = image.load_img(image_path, target_size=(224, 224))
|
| 30 |
|
|
@@ -51,15 +38,6 @@ def predict(image_path):
|
|
| 51 |
predicted_class = 'Pneumonia' if predicted_probabilities > 0.5 else 'Normal'
|
| 52 |
|
| 53 |
return predicted_class
|
| 54 |
-
# predicted_class = np.argmax(predicted_probabilities)
|
| 55 |
-
|
| 56 |
-
# Extract the predicted class label with the highest probability
|
| 57 |
-
# prediction = np.argmax(predictions[0])
|
| 58 |
-
|
| 59 |
-
# if(predicted_class > 0.5):
|
| 60 |
-
# return "Pneumonia"
|
| 61 |
-
# else:
|
| 62 |
-
# return "Normal"
|
| 63 |
|
| 64 |
image_component = gr.Image(type="filepath", label="Chest X-ray Image")
|
| 65 |
label_component = gr.Label(label="Classification result", num_top_classes=1)
|
|
|
|
| 1 |
import os
|
| 2 |
os.system('pip install tf_keras')
|
| 3 |
+
import tf_keras #Keras3 no longer supports hub.KerasLayer()
|
| 4 |
|
|
|
|
|
|
|
| 5 |
import tensorflow as tf
|
| 6 |
from tensorflow.keras.preprocessing import image
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
model_path = "./4-17_ViT-B16_Lung3_v4_E30/"
|
| 11 |
+
model = tf_keras.models.load_model(model_path) #Load model with old version (tf_keras instead of tf.keras)
|
| 12 |
|
| 13 |
# Define preprocessing function
|
| 14 |
def preprocess_image(image_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Load the image from file
|
| 16 |
img = image.load_img(image_path, target_size=(224, 224))
|
| 17 |
|
|
|
|
| 38 |
predicted_class = 'Pneumonia' if predicted_probabilities > 0.5 else 'Normal'
|
| 39 |
|
| 40 |
return predicted_class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
image_component = gr.Image(type="filepath", label="Chest X-ray Image")
|
| 43 |
label_component = gr.Label(label="Classification result", num_top_classes=1)
|