Spaces:
Build error
Build error
Duplicate from blackphin/kidney-detection-model
Browse filesCo-authored-by: Shivansh Goel <blackphin@users.noreply.huggingface.co>
- .gitattributes +1 -0
- .gitignore +3 -0
- Model/Model.h5 +3 -0
- Model/efficient-net.ipynb +0 -0
- Model/watershed-segmentation.ipynb +0 -0
- README.md +14 -0
- app.py +64 -0
- demo/Cyst.jpg +0 -0
- demo/Normal.jpg +0 -0
- demo/Stone.jpg +0 -0
- demo/Tumor.jpg +0 -0
- poetry.lock +0 -0
- requirements.txt +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*h5 filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.venv
|
| 2 |
+
__pycache__
|
| 3 |
+
*.docx
|
Model/Model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:61102bc6b12bbb86693920bdca6962d66ba34b6ab3002fd5eb03cc2e1269be22
|
| 3 |
+
size 135395432
|
Model/efficient-net.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Model/watershed-segmentation.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Kidney Detection Model
|
| 3 |
+
emoji: 🌍
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.19.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
duplicated_from: blackphin/kidney-detection-model
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import numpy as np
|
| 6 |
+
import seaborn as sns
|
| 7 |
+
import cv2
|
| 8 |
+
|
| 9 |
+
import tensorflow as tf
|
| 10 |
+
from tensorflow.keras import backend as K
|
| 11 |
+
from tensorflow.keras.models import load_model
|
| 12 |
+
from tensorflow.keras.applications.imagenet_utils import preprocess_input
|
| 13 |
+
from tensorflow.keras.applications.imagenet_utils import preprocess_input
|
| 14 |
+
|
| 15 |
+
from sklearn.metrics import f1_score
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import gradio as gr
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 22 |
+
sns.set_style('darkgrid')
|
| 23 |
+
if not sys.warnoptions:
|
| 24 |
+
import warnings
|
| 25 |
+
warnings.simplefilter("ignore")
|
| 26 |
+
pd.set_option('display.max_columns', None) # or 1000
|
| 27 |
+
pd.set_option('display.max_rows', None) # or 1000
|
| 28 |
+
pd.set_option('display.max_colwidth', None) # or 199
|
| 29 |
+
print('Modules loaded')
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def F1_score(y_true, y_pred): # taken from old keras source code
|
| 33 |
+
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
|
| 34 |
+
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
|
| 35 |
+
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
|
| 36 |
+
precision = true_positives / (predicted_positives + K.epsilon())
|
| 37 |
+
recall = true_positives / (possible_positives + K.epsilon())
|
| 38 |
+
f1_val = 2*(precision*recall)/(precision+recall+K.epsilon())
|
| 39 |
+
return f1_val
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
model = load_model(r"Model\Model.h5",
|
| 43 |
+
custom_objects={"F1_score": f1_score})
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def recog_model(img_path):
|
| 47 |
+
img = cv2.imread(img_path)
|
| 48 |
+
img = cv2.resize(img, (250, 224))
|
| 49 |
+
x = np.expand_dims(img, axis=0)
|
| 50 |
+
x = preprocess_input(x)
|
| 51 |
+
|
| 52 |
+
prediction = model.predict(x)
|
| 53 |
+
|
| 54 |
+
# convert the prediction to a class label
|
| 55 |
+
classes = ['Tumor', 'Cyst', 'Normal', 'Stone']
|
| 56 |
+
predicted_class = classes[np.argmax(prediction[0])]
|
| 57 |
+
confidence = str(100 * (np.max(prediction[0])))
|
| 58 |
+
return (str(predicted_class+" detected with a confidence of "+confidence+"%"))
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
demo = gr.Interface(fn=recog_model, inputs=gr.Image(image_mode="L", type="filepath", label="Input Image"),
|
| 62 |
+
outputs=gr.Label(label="Model Prediction"), allow_flagging="never", examples=[r"demo\Cyst.jpg", r"demo\Normal.jpg", r"demo\Stone.jpg", r"demo\Tumor.jpg"])
|
| 63 |
+
|
| 64 |
+
demo.launch()
|
demo/Cyst.jpg
ADDED
|
demo/Normal.jpg
ADDED
|
demo/Stone.jpg
ADDED
|
demo/Tumor.jpg
ADDED
|
poetry.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|