Spaces:
Sleeping
Sleeping
dev-deg commited on
Commit ·
4c5a031
1
Parent(s): 204dc88
Made improvements to display confidence value in instance segmentation classes
Browse files- app.py +4 -1
- habitat_classification.py +1 -1
- inferencing.py +10 -7
app.py
CHANGED
|
@@ -5,7 +5,10 @@ from inferencing import run_inference
|
|
| 5 |
iface = gr.Interface(
|
| 6 |
fn=run_inference,
|
| 7 |
inputs="image",
|
| 8 |
-
outputs=[gradio.Annotatedimage(label="Annotated Image"),
|
|
|
|
|
|
|
|
|
|
| 9 |
title="AMBULANT Benthic Identification System"
|
| 10 |
)
|
| 11 |
iface.launch()
|
|
|
|
| 5 |
iface = gr.Interface(
|
| 6 |
fn=run_inference,
|
| 7 |
inputs="image",
|
| 8 |
+
outputs=[gradio.Annotatedimage(label="Annotated Image"),
|
| 9 |
+
gradio.DataFrame(label="Predicted Benthic Habitat",headers=["Prediction", "Confidence"]),
|
| 10 |
+
gradio.DataFrame(label="Habitat Confidence Values",headers=["Classification", "Confidence"]),
|
| 11 |
+
gradio.DataFrame(label="Identified Classes Confidence Values",headers=["Classification", "Confidence"])],
|
| 12 |
title="AMBULANT Benthic Identification System"
|
| 13 |
)
|
| 14 |
iface.launch()
|
habitat_classification.py
CHANGED
|
@@ -82,5 +82,5 @@ def get_inconclusive():
|
|
| 82 |
'Confidence': 'N/a'})
|
| 83 |
probabilities_df = pd.DataFrame({
|
| 84 |
'Classification': ['Inconclusive'],
|
| 85 |
-
'
|
| 86 |
return result_df, probabilities_df
|
|
|
|
| 82 |
'Confidence': 'N/a'})
|
| 83 |
probabilities_df = pd.DataFrame({
|
| 84 |
'Classification': ['Inconclusive'],
|
| 85 |
+
'Confidence': 'N/a'})
|
| 86 |
return result_df, probabilities_df
|
inferencing.py
CHANGED
|
@@ -10,18 +10,17 @@ dotenv.load_dotenv()
|
|
| 10 |
hf_tk = os.getenv('HF_AT')
|
| 11 |
|
| 12 |
def display_detections(frame, results):
|
| 13 |
-
|
| 14 |
annotations = []
|
| 15 |
for result in results:
|
| 16 |
if result.boxes.data.nelement() != 0:
|
| 17 |
for detection in result.boxes.data:
|
| 18 |
x1, y1, x2, y2, conf, cls = detection.cpu().numpy()
|
| 19 |
class_name = result.names[int(cls)]
|
| 20 |
-
|
| 21 |
-
class_names.append(class_name)
|
| 22 |
annotations.append(((int(x1), int(y1), int(x2), int(y2)), class_name))
|
| 23 |
outframe = results[0].plot()
|
| 24 |
-
return outframe, annotations,
|
| 25 |
|
| 26 |
print("No detections")
|
| 27 |
return frame, [], []
|
|
@@ -39,9 +38,13 @@ def get_habitat_data(class_names):
|
|
| 39 |
return habitat_res[0], habitat_res[1]
|
| 40 |
|
| 41 |
def run_inference(input_image):
|
| 42 |
-
processed_frame, annotations,
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# Load YOLO model
|
| 46 |
raw_model = hf_hub_download(repo_id="dev-deg/Ambulant_1.0", filename="latest.pt",use_auth_token=hf_tk)
|
| 47 |
model = YOLO(raw_model)
|
|
|
|
| 10 |
hf_tk = os.getenv('HF_AT')
|
| 11 |
|
| 12 |
def display_detections(frame, results):
|
| 13 |
+
detections = []
|
| 14 |
annotations = []
|
| 15 |
for result in results:
|
| 16 |
if result.boxes.data.nelement() != 0:
|
| 17 |
for detection in result.boxes.data:
|
| 18 |
x1, y1, x2, y2, conf, cls = detection.cpu().numpy()
|
| 19 |
class_name = result.names[int(cls)]
|
| 20 |
+
detections.append([class_name, conf])
|
|
|
|
| 21 |
annotations.append(((int(x1), int(y1), int(x2), int(y2)), class_name))
|
| 22 |
outframe = results[0].plot()
|
| 23 |
+
return outframe, annotations, pd.DataFrame(detections, columns=["Class", "Confidence"])
|
| 24 |
|
| 25 |
print("No detections")
|
| 26 |
return frame, [], []
|
|
|
|
| 38 |
return habitat_res[0], habitat_res[1]
|
| 39 |
|
| 40 |
def run_inference(input_image):
|
| 41 |
+
processed_frame, annotations, detections = process_image(input_image)
|
| 42 |
+
if detections.empty:
|
| 43 |
+
habitat, probabilities = get_inconclusive()
|
| 44 |
+
detections = pd.DataFrame(columns=["Class", "Confidence"])
|
| 45 |
+
else:
|
| 46 |
+
habitat, probabilities = get_habitat_data(detections['Class'].tolist())
|
| 47 |
+
return (processed_frame, annotations), habitat, probabilities, detections
|
| 48 |
# Load YOLO model
|
| 49 |
raw_model = hf_hub_download(repo_id="dev-deg/Ambulant_1.0", filename="latest.pt",use_auth_token=hf_tk)
|
| 50 |
model = YOLO(raw_model)
|