Adonai Vera
commited on
Commit
·
e2608da
1
Parent(s):
fbabf41
Get feedback from the user
Browse files- .DS_Store +0 -0
- .gitignore +32 -0
- app.py +86 -11
- flagged/log.csv +2 -0
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
**/*.DS_store
|
| 3 |
+
.vscode
|
| 4 |
+
node_modules
|
| 5 |
+
|
| 6 |
+
__pycache__
|
| 7 |
+
*.py[cod]
|
| 8 |
+
|
| 9 |
+
*.egg-info
|
| 10 |
+
.project
|
| 11 |
+
.pydevproject
|
| 12 |
+
**/*.ipynb_checkpoints
|
| 13 |
+
.idea
|
| 14 |
+
*.swp
|
| 15 |
+
|
| 16 |
+
*~
|
| 17 |
+
|
| 18 |
+
build/
|
| 19 |
+
dist/
|
| 20 |
+
|
| 21 |
+
/eta/
|
| 22 |
+
|
| 23 |
+
/docs/build/
|
| 24 |
+
/docs/source/api/
|
| 25 |
+
|
| 26 |
+
/bin
|
| 27 |
+
/lib
|
| 28 |
+
coverage.xml
|
| 29 |
+
.coverage.*
|
| 30 |
+
pyvenv.cfg
|
| 31 |
+
|
| 32 |
+
flagged/
|
app.py
CHANGED
|
@@ -6,6 +6,66 @@ from PIL import Image
|
|
| 6 |
# Initialize the pipeline with your model
|
| 7 |
pipe = pipeline("image-classification", model="SubterraAI/ofwat_defects_classification")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
defect_dict = {
|
| 10 |
"CL": "Crack Longitudinal",
|
| 11 |
"CLJ": "Crack Longitudinal at Joint",
|
|
@@ -56,6 +116,13 @@ defect_dict = {
|
|
| 56 |
"DES": "Debris Silt",
|
| 57 |
"RF": "Roots Fine",
|
| 58 |
"RM": "Roots Mass",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
"RT": "Roots Tap",
|
| 60 |
"IS(J)": "Infiltration Light Seeping Joint",
|
| 61 |
"ID(J)": "Infiltration Light Dripping Joint",
|
|
@@ -70,10 +137,21 @@ defect_dict = {
|
|
| 70 |
}
|
| 71 |
|
| 72 |
def replace_label_with_full_name(res, defect_dict_key_code):
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
def classify_image(image):
|
| 79 |
# Convert the input image to PIL format
|
|
@@ -82,11 +160,8 @@ def classify_image(image):
|
|
| 82 |
# Classify the image using the pipeline
|
| 83 |
res = pipe(PIL_image)
|
| 84 |
|
| 85 |
-
replaced_res = replace_label_with_full_name(res, defect_dict)
|
| 86 |
-
|
| 87 |
-
|
| 88 |
# Extract labels and scores
|
| 89 |
-
return
|
| 90 |
|
| 91 |
# Create the Gradio interface
|
| 92 |
iface = gr.Interface(
|
|
@@ -94,15 +169,15 @@ iface = gr.Interface(
|
|
| 94 |
"image",
|
| 95 |
"label",
|
| 96 |
examples=[
|
|
|
|
| 97 |
["examples/CS.jpg"],
|
| 98 |
["examples/GI.jpg"],
|
| 99 |
-
["examples/PP.jpg"],
|
| 100 |
["examples/RC.jpg"]
|
| 101 |
],
|
| 102 |
description="Upload an image to classify its material.",
|
| 103 |
-
title="Defects Classification with AI by Subterra"
|
| 104 |
-
|
| 105 |
-
|
| 106 |
)
|
| 107 |
|
| 108 |
# Launch the interface
|
|
|
|
| 6 |
# Initialize the pipeline with your model
|
| 7 |
pipe = pipeline("image-classification", model="SubterraAI/ofwat_defects_classification")
|
| 8 |
|
| 9 |
+
defect_full_names_list = [
|
| 10 |
+
"Crack Longitudinal",
|
| 11 |
+
"Crack Longitudinal at Joint",
|
| 12 |
+
"Crack Circumferential",
|
| 13 |
+
"Crack Circumferential at Joint",
|
| 14 |
+
"Crack Multiple",
|
| 15 |
+
"Crack Multiple at Joint",
|
| 16 |
+
"Crack Spiral",
|
| 17 |
+
"Fracture Longitudinal",
|
| 18 |
+
"Fracture Circumferential",
|
| 19 |
+
"Fracture Multiple",
|
| 20 |
+
"Fracture Spiral",
|
| 21 |
+
"Broken",
|
| 22 |
+
"Broken Pipe at Joint",
|
| 23 |
+
"Hole",
|
| 24 |
+
"Deformation (Not Brick)",
|
| 25 |
+
"Collapse",
|
| 26 |
+
"Joint Displaced",
|
| 27 |
+
"Joint Displaced Medium",
|
| 28 |
+
"Joint Displaced Large",
|
| 29 |
+
"Open Joint",
|
| 30 |
+
"Open Joint Medium",
|
| 31 |
+
"Open Joint Large",
|
| 32 |
+
"Increased Roughness",
|
| 33 |
+
"Visible Aggregate",
|
| 34 |
+
"Aggregate Projecting",
|
| 35 |
+
"Visible Reinforcement",
|
| 36 |
+
"Reinforcement Projecting",
|
| 37 |
+
"Corroded Reinforcement",
|
| 38 |
+
"Surface Damage Spalling",
|
| 39 |
+
"Other Damage",
|
| 40 |
+
"Line Defect",
|
| 41 |
+
"Weld Failure Circumferential",
|
| 42 |
+
"Weld Failure Longitudinal",
|
| 43 |
+
"Weld Failure Spiral",
|
| 44 |
+
"Defective Repair, part of wall missing",
|
| 45 |
+
"Defective Repair",
|
| 46 |
+
"Displaced bricks",
|
| 47 |
+
"Missing bricks",
|
| 48 |
+
"Dropped Invert",
|
| 49 |
+
"Encrustation/Scale Light",
|
| 50 |
+
"Encrustation/Scale Medium",
|
| 51 |
+
"Encrustation/Scale Heavy",
|
| 52 |
+
"Debris Grease",
|
| 53 |
+
"Debris Silt",
|
| 54 |
+
"Roots Fine",
|
| 55 |
+
"Roots Mass",
|
| 56 |
+
"Roots Tap",
|
| 57 |
+
"Infiltration Light Seeping Joint",
|
| 58 |
+
"Infiltration Light Dripping Joint",
|
| 59 |
+
"Infiltration Moderate Running Joint",
|
| 60 |
+
"Infiltration Severe Gusher Joint",
|
| 61 |
+
"Connection Intruding",
|
| 62 |
+
"Connection Defective",
|
| 63 |
+
"Sealing Ring Intruding",
|
| 64 |
+
"Sealing Ring Broken",
|
| 65 |
+
"Other sealent intruding",
|
| 66 |
+
"Camera Underwater"
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
defect_dict = {
|
| 70 |
"CL": "Crack Longitudinal",
|
| 71 |
"CLJ": "Crack Longitudinal at Joint",
|
|
|
|
| 116 |
"DES": "Debris Silt",
|
| 117 |
"RF": "Roots Fine",
|
| 118 |
"RM": "Roots Mass",
|
| 119 |
+
"RL": "Roots Lateral",
|
| 120 |
+
"LR": "Line Right",
|
| 121 |
+
"LL": "Line Left",
|
| 122 |
+
"LD": "Line Down",
|
| 123 |
+
"LU": "Line Up",
|
| 124 |
+
"DEF": "Deformed Elliptical (Flexible)",
|
| 125 |
+
"WL": "Weeper Lateral",
|
| 126 |
"RT": "Roots Tap",
|
| 127 |
"IS(J)": "Infiltration Light Seeping Joint",
|
| 128 |
"ID(J)": "Infiltration Light Dripping Joint",
|
|
|
|
| 137 |
}
|
| 138 |
|
| 139 |
def replace_label_with_full_name(res, defect_dict_key_code):
|
| 140 |
+
new_res = {}
|
| 141 |
+
for dic in res:
|
| 142 |
+
# Splitting the label to handle possible suffix
|
| 143 |
+
parts = dic["label"].split('_', 1)
|
| 144 |
+
code = parts[0]
|
| 145 |
+
suffix = '_' + parts[1] if len(parts) > 1 else ''
|
| 146 |
+
|
| 147 |
+
# Replacing the code with its full name, if it exists in the dictionary
|
| 148 |
+
full_name = defect_dict_key_code.get(code, code)
|
| 149 |
|
| 150 |
+
# Constructing the new label with the suffix if it exists
|
| 151 |
+
new_label = full_name + suffix
|
| 152 |
+
new_res[new_label] = dic["score"]
|
| 153 |
+
|
| 154 |
+
return new_res
|
| 155 |
|
| 156 |
def classify_image(image):
|
| 157 |
# Convert the input image to PIL format
|
|
|
|
| 160 |
# Classify the image using the pipeline
|
| 161 |
res = pipe(PIL_image)
|
| 162 |
|
|
|
|
|
|
|
|
|
|
| 163 |
# Extract labels and scores
|
| 164 |
+
return replace_label_with_full_name(res, defect_dict)
|
| 165 |
|
| 166 |
# Create the Gradio interface
|
| 167 |
iface = gr.Interface(
|
|
|
|
| 169 |
"image",
|
| 170 |
"label",
|
| 171 |
examples=[
|
| 172 |
+
["examples/PP.jpg"],
|
| 173 |
["examples/CS.jpg"],
|
| 174 |
["examples/GI.jpg"],
|
|
|
|
| 175 |
["examples/RC.jpg"]
|
| 176 |
],
|
| 177 |
description="Upload an image to classify its material.",
|
| 178 |
+
title="Defects Classification with AI by Subterra",
|
| 179 |
+
allow_flagging="manual",
|
| 180 |
+
flagging_options=defect_full_names_list
|
| 181 |
)
|
| 182 |
|
| 183 |
# Launch the interface
|
flagged/log.csv
CHANGED
|
@@ -5,3 +5,5 @@ image,output 0,output 1,flag,username,timestamp
|
|
| 5 |
| GI | Galvanized Iron |
|
| 6 |
| PP | Polypropylene |
|
| 7 |
| RC | Reinforced Concrete |",,,2023-11-27 15:26:38.548865
|
|
|
|
|
|
|
|
|
| 5 |
| GI | Galvanized Iron |
|
| 6 |
| PP | Polypropylene |
|
| 7 |
| RC | Reinforced Concrete |",,,2023-11-27 15:26:38.548865
|
| 8 |
+
"{""path"":""flagged/image/f8cda673ba099bdc61a5/PP.jpg"",""url"":""http://127.0.0.1:7860/file=/private/var/folders/5q/yl8pmxm116g6r3k8fd9gk74m0000gn/T/gradio/12885a897d79141c54ccb542582449159242eaa0/PP.jpg"",""size"":null,""orig_name"":""PP.jpg"",""mime_type"":null}","{""label"":""Roots Mass_1"",""confidences"":[{""label"":""Roots Mass_1"",""confidence"":0.7871310114860535},{""label"":""Roots Fine"",""confidence"":0.09039264917373657},{""label"":""Roots Tap"",""confidence"":0.00837390124797821},{""label"":""Roots Mass_2"",""confidence"":0.006819701287895441},{""label"":""Broken"",""confidence"":0.0035697731655091047}]}",,,2024-01-09 10:34:30.437383
|
| 9 |
+
"{""path"":""flagged/image/befb43e3dd4bacae416e/GI.jpg"",""url"":""http://127.0.0.1:7860/file=/private/var/folders/5q/yl8pmxm116g6r3k8fd9gk74m0000gn/T/gradio/ba9d81007395e0c7bff4c5a44e53e64b44fad560/GI.jpg"",""size"":null,""orig_name"":""GI.jpg"",""mime_type"":null}","{""label"":""Line Right"",""confidences"":[{""label"":""Line Right"",""confidence"":0.5224241018295288},{""label"":""Line Left"",""confidence"":0.32871416211128235},{""label"":""Line Down"",""confidence"":0.03255414962768555},{""label"":""Joint Displaced Medium_1"",""confidence"":0.009562213905155659},{""label"":""Line Up"",""confidence"":0.0074854386039078236}]}",Crack Longitudinal,,2024-01-09 10:39:15.651496
|