Spaces:
Sleeping
Sleeping
Commit
·
5ddffe7
1
Parent(s):
b9eabd1
Update model.py
Browse files
model.py
CHANGED
|
@@ -2,13 +2,26 @@ import tensorflow as tf
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def classify(img):
|
| 7 |
im = img
|
| 8 |
lt = ["other","Bone","Brain","eye","kidney","chest","skin"]
|
| 9 |
im = cv2.resize(im,(52,52))
|
| 10 |
-
|
| 11 |
-
result = model.predict(np.array([im]))
|
| 12 |
a = np.argmax(result)
|
| 13 |
c=""
|
| 14 |
if a==0:
|
|
@@ -28,52 +41,49 @@ def classify(img):
|
|
| 28 |
return c
|
| 29 |
|
| 30 |
|
| 31 |
-
|
| 32 |
def bone_net(img):
|
| 33 |
# img = cv2.resize(img,(224,224))
|
| 34 |
lt = ['not fractured', 'fractured']
|
| 35 |
-
|
| 36 |
-
result =
|
| 37 |
-
result = model.predict(np.array([img]))
|
| 38 |
ans = np.argmax(result)
|
| 39 |
return lt[ans]
|
| 40 |
|
| 41 |
def brain_net(img):
|
| 42 |
lt = ['pituitary', 'notumor', 'meningioma', 'glioma']
|
| 43 |
# img = cv2.resize(img,(52,52))
|
| 44 |
-
|
| 45 |
-
result =
|
| 46 |
ans = np.argmax(result)
|
| 47 |
return lt[ans]
|
| 48 |
|
| 49 |
def chest_net(img):
|
| 50 |
lt = ['PNEUMONIA', 'NORMAL']
|
| 51 |
# img = cv2.resize(img,(224,224))
|
| 52 |
-
|
| 53 |
-
result = model.predict(np.array([img]))
|
| 54 |
ans = np.argmax(result)
|
| 55 |
return lt[ans]
|
| 56 |
|
| 57 |
def Eye_net(img):
|
| 58 |
lt = ['glaucoma', 'normal', 'diabetic_retinopathy', 'cataract']
|
| 59 |
# img = cv2.resize(img,(224,224))
|
| 60 |
-
|
| 61 |
-
result =
|
| 62 |
ans = np.argmax(result)
|
| 63 |
return lt[ans]
|
| 64 |
|
| 65 |
def kidney_net(img):
|
| 66 |
lt = ['Cyst', 'Tumor', 'Stone', 'Normal']
|
| 67 |
# img = cv2.resize(img,(224,224))
|
| 68 |
-
|
| 69 |
-
result =
|
| 70 |
ans = np.argmax(result)
|
| 71 |
return lt[ans]
|
| 72 |
|
| 73 |
def skin_net(img):
|
| 74 |
lt = ['pigmented benign keratosis', 'melanoma', 'vascular lesion', 'actinic keratosis', 'squamous cell carcinoma', 'basal cell carcinoma', 'seborrheic keratosis', 'dermatofibroma', 'nevus']
|
| 75 |
# img = cv2.resize(img,(224,224))
|
| 76 |
-
|
| 77 |
-
result = model.predict(np.array([img]))
|
| 78 |
ans = np.argmax(result)
|
| 79 |
return lt[ans]
|
|
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
cls_model = tf.keras.models.load_model("all-in-one.h5",compile=False)
|
| 6 |
+
|
| 7 |
+
fract_model = tf.keras.models.load_model("fracture.h5",compile=False)
|
| 8 |
+
|
| 9 |
+
brain_model = tf.keras.models.load_model("brain.h5",compile=False)
|
| 10 |
+
|
| 11 |
+
chest_model = tf.keras.models.load_model("chest.h5",compile=False)
|
| 12 |
+
|
| 13 |
+
eye_model = tf.keras.models.load_model("eye.h5",compile=False)
|
| 14 |
+
|
| 15 |
+
kid_model = tf.keras.models.load_model("kidney.h5",compile=False)
|
| 16 |
+
|
| 17 |
+
skin_model = tf.keras.models.load_model("skin.h5",compile=False)
|
| 18 |
+
|
| 19 |
|
| 20 |
def classify(img):
|
| 21 |
im = img
|
| 22 |
lt = ["other","Bone","Brain","eye","kidney","chest","skin"]
|
| 23 |
im = cv2.resize(im,(52,52))
|
| 24 |
+
result = cls_model.predict(np.array([im]))
|
|
|
|
| 25 |
a = np.argmax(result)
|
| 26 |
c=""
|
| 27 |
if a==0:
|
|
|
|
| 41 |
return c
|
| 42 |
|
| 43 |
|
|
|
|
| 44 |
def bone_net(img):
|
| 45 |
# img = cv2.resize(img,(224,224))
|
| 46 |
lt = ['not fractured', 'fractured']
|
| 47 |
+
|
| 48 |
+
result = fract_model.predict(np.array([img]))
|
| 49 |
+
# result = model.predict(np.array([img]))
|
| 50 |
ans = np.argmax(result)
|
| 51 |
return lt[ans]
|
| 52 |
|
| 53 |
def brain_net(img):
|
| 54 |
lt = ['pituitary', 'notumor', 'meningioma', 'glioma']
|
| 55 |
# img = cv2.resize(img,(52,52))
|
| 56 |
+
|
| 57 |
+
result = brain_model.predict(np.array([img]))
|
| 58 |
ans = np.argmax(result)
|
| 59 |
return lt[ans]
|
| 60 |
|
| 61 |
def chest_net(img):
|
| 62 |
lt = ['PNEUMONIA', 'NORMAL']
|
| 63 |
# img = cv2.resize(img,(224,224))
|
| 64 |
+
result = chest_model.predict(np.array([img]))
|
|
|
|
| 65 |
ans = np.argmax(result)
|
| 66 |
return lt[ans]
|
| 67 |
|
| 68 |
def Eye_net(img):
|
| 69 |
lt = ['glaucoma', 'normal', 'diabetic_retinopathy', 'cataract']
|
| 70 |
# img = cv2.resize(img,(224,224))
|
| 71 |
+
|
| 72 |
+
result = eye_model.predict(np.array([img]))
|
| 73 |
ans = np.argmax(result)
|
| 74 |
return lt[ans]
|
| 75 |
|
| 76 |
def kidney_net(img):
|
| 77 |
lt = ['Cyst', 'Tumor', 'Stone', 'Normal']
|
| 78 |
# img = cv2.resize(img,(224,224))
|
| 79 |
+
|
| 80 |
+
result = kid_model.predict(np.array([img]))
|
| 81 |
ans = np.argmax(result)
|
| 82 |
return lt[ans]
|
| 83 |
|
| 84 |
def skin_net(img):
|
| 85 |
lt = ['pigmented benign keratosis', 'melanoma', 'vascular lesion', 'actinic keratosis', 'squamous cell carcinoma', 'basal cell carcinoma', 'seborrheic keratosis', 'dermatofibroma', 'nevus']
|
| 86 |
# img = cv2.resize(img,(224,224))
|
| 87 |
+
result = skin_model.predict(np.array([img]))
|
|
|
|
| 88 |
ans = np.argmax(result)
|
| 89 |
return lt[ans]
|