Spaces:
Sleeping
Sleeping
umairahmad89
commited on
Commit
·
2cd5935
0
Parent(s):
initial commit
Browse files
.gitignore
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.DS_Store
|
2 |
+
flagged
|
3 |
+
images
|
4 |
+
labels
|
5 |
+
labels-prev
|
6 |
+
project*
|
7 |
+
test*
|
8 |
+
val
|
9 |
+
yolo-labels
|
10 |
+
ahmad.pt
|
11 |
+
annotations.csv
|
12 |
+
convert.py
|
13 |
+
plot.py
|
14 |
+
README.md
|
15 |
+
LICENSE
|
16 |
+
*.zip
|
17 |
+
tf*
|
18 |
+
weights/*
|
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Tuple
|
2 |
+
from ultralytics import YOLO
|
3 |
+
from ultralytics.engine.results import Boxes
|
4 |
+
from ultralytics.utils.plotting import Annotator
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
cell_detector = YOLO("./weights/yolo_uninfected_cells.pt")
|
9 |
+
redetr_detector = YOLO("./weights/redetr_infected_cells.pt")
|
10 |
+
yolo_detector = YOLO("./weights/yolo_infected_cells.pt")
|
11 |
+
|
12 |
+
models = {"Yolo V11": yolo_detector, "Real Time Detection Transformer": redetr_detector}
|
13 |
+
classes = {"Yolo V11": [0], "Real Time Detection Transformer": [1]}
|
14 |
+
|
15 |
+
|
16 |
+
def inference(image, model) -> Tuple[str, str, str]:
|
17 |
+
bboxes = []
|
18 |
+
labels = []
|
19 |
+
healthy_cell_count = 0
|
20 |
+
unhealthy_cell_count = 0
|
21 |
+
cells_results = cell_detector.predict(image, conf=0.5)
|
22 |
+
selected_model_results = models[model].predict(
|
23 |
+
image, conf=0.05, classes=classes[model], imgsz=1024
|
24 |
+
)
|
25 |
+
|
26 |
+
for cell_result in cells_results:
|
27 |
+
boxes: Boxes = cell_result.boxes
|
28 |
+
healthy_cells_bboxes = boxes.xyxy.tolist()
|
29 |
+
healthy_cell_count += len(healthy_cells_bboxes)
|
30 |
+
bboxes.extend(healthy_cells_bboxes)
|
31 |
+
labels.extend(["healthy"] * healthy_cell_count)
|
32 |
+
|
33 |
+
for res in selected_model_results:
|
34 |
+
boxes: Boxes = res.boxes
|
35 |
+
unhealthy_cells_bboxes = boxes.xyxy.tolist()
|
36 |
+
unhealthy_cell_count += len(unhealthy_cells_bboxes)
|
37 |
+
bboxes.extend(unhealthy_cells_bboxes)
|
38 |
+
labels.extend(["unhealthy"] * unhealthy_cell_count)
|
39 |
+
|
40 |
+
annotator = Annotator(image, font_size=5, line_width=1)
|
41 |
+
|
42 |
+
for box, label in zip(bboxes, labels):
|
43 |
+
annotator.box_label(box, label)
|
44 |
+
|
45 |
+
img = annotator.result()
|
46 |
+
return (img, healthy_cell_count, unhealthy_cell_count)
|
47 |
+
|
48 |
+
|
49 |
+
ifer = gr.Interface(
|
50 |
+
fn=inference,
|
51 |
+
inputs=[
|
52 |
+
gr.Image(label="Input Image", type="numpy"),
|
53 |
+
gr.Dropdown(
|
54 |
+
choices=["Yolo V11", "Real Time Detection Transformer"], multiselect=False
|
55 |
+
),
|
56 |
+
],
|
57 |
+
outputs=[
|
58 |
+
gr.Image(label="Output Image", type="numpy"),
|
59 |
+
gr.Textbox(label="Healthy Cells Count"),
|
60 |
+
gr.Textbox(label="Infected Cells Count"),
|
61 |
+
],
|
62 |
+
title="Blood Cancer Cell Detection and Counting"
|
63 |
+
)
|
64 |
+
|
65 |
+
ifer.launch(share=True)
|
data.yaml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
train: ./dataset/autosplit_train.txt
|
2 |
+
val: ./dataset/autosplit_val.txt
|
3 |
+
test: ./dataset/autosplit_test.txt
|
4 |
+
nc: 1
|
5 |
+
names:
|
6 |
+
- cell
|
split.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics.data.utils import autosplit
|
2 |
+
|
3 |
+
autosplit(
|
4 |
+
path="./dataset/images",
|
5 |
+
weights=(0.8, 0.1, 0.1), # (train, validation, test) fractional splits
|
6 |
+
annotated_only=False, # split only images with annotation file when True
|
7 |
+
)
|
train.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics import YOLO
|
2 |
+
|
3 |
+
|
4 |
+
model = YOLO("yolov8n.pt")
|
5 |
+
model.to('cuda')
|
6 |
+
model.train(data="data.yaml", epochs=100, batch=8, device="cuda", imgsz=640)
|
val.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics import YOLO
|
2 |
+
|
3 |
+
|
4 |
+
model = YOLO("best_BCCM.pt")
|
5 |
+
model.to('cuda')
|
6 |
+
model.val(data="data.yaml")
|