Spaces:
Sleeping
Sleeping
GitHub Actions
commited on
Commit
·
b5c878a
1
Parent(s):
29a08a3
Auto-deploy from GitHub
Browse files
detect.py
CHANGED
|
@@ -52,9 +52,47 @@ class DengueDetector:
|
|
| 52 |
print("Modelo carregado com as seguintes classes:", self.names)
|
| 53 |
|
| 54 |
def calculate_intensity(self, objects):
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
def detect_image(self, image_bytes, fast: bool = True):
|
| 60 |
img = Image.open(BytesIO(image_bytes)).convert("RGB")
|
|
@@ -159,6 +197,10 @@ class DengueDetector:
|
|
| 159 |
x2 *= inv
|
| 160 |
y2 *= inv
|
| 161 |
cname = self.names[int(c)]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
class_names.append(cname)
|
| 163 |
detections.append({
|
| 164 |
"class": cname,
|
|
@@ -177,4 +219,4 @@ class DengueDetector:
|
|
| 177 |
"contagem": counts,
|
| 178 |
"objetos": detections,
|
| 179 |
"intensity_score": intensity_score
|
| 180 |
-
}
|
|
|
|
| 52 |
print("Modelo carregado com as seguintes classes:", self.names)
|
| 53 |
|
| 54 |
def calculate_intensity(self, objects):
|
| 55 |
+
if not objects:
|
| 56 |
+
return 0.0
|
| 57 |
+
|
| 58 |
+
weights = {
|
| 59 |
+
"piscina_suja": 10.0,
|
| 60 |
+
"reservatorio_de_agua": 8.0,
|
| 61 |
+
"pneu": 6.0,
|
| 62 |
+
"lona": 4.0,
|
| 63 |
+
"monte_de_lixo": 3.0,
|
| 64 |
+
"saco_de_lixo": 2.0,
|
| 65 |
+
"piscina_limpa": 1.0
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
total_score = 0.0
|
| 69 |
+
first_obj = objects[0]
|
| 70 |
+
img_w = first_obj["box"]["original_width"]
|
| 71 |
+
img_h = first_obj["box"]["original_height"]
|
| 72 |
+
total_img_area = float(img_w * img_h)
|
| 73 |
+
|
| 74 |
+
if total_img_area == 0:
|
| 75 |
+
for obj in objects:
|
| 76 |
+
weight = weights.get(obj["class"], 1.0)
|
| 77 |
+
confidence = obj["confidence"]
|
| 78 |
+
total_score += weight * confidence
|
| 79 |
+
return total_score
|
| 80 |
+
|
| 81 |
+
for obj in objects:
|
| 82 |
+
weight = weights.get(obj["class"], 1.0)
|
| 83 |
+
confidence = obj["confidence"]
|
| 84 |
+
|
| 85 |
+
box = obj["box"]
|
| 86 |
+
w = box["x2"] - box["x1"]
|
| 87 |
+
h = box["y2"] - box["y1"]
|
| 88 |
+
obj_area = w * h
|
| 89 |
+
relative_area = obj_area / total_img_area
|
| 90 |
+
|
| 91 |
+
# risco = Peso * Confiança * Área Relativa
|
| 92 |
+
risk_contribution = weight * confidence * relative_area
|
| 93 |
+
total_score += risk_contribution
|
| 94 |
+
|
| 95 |
+
return total_score * 100.0
|
| 96 |
|
| 97 |
def detect_image(self, image_bytes, fast: bool = True):
|
| 98 |
img = Image.open(BytesIO(image_bytes)).convert("RGB")
|
|
|
|
| 197 |
x2 *= inv
|
| 198 |
y2 *= inv
|
| 199 |
cname = self.names[int(c)]
|
| 200 |
+
|
| 201 |
+
if cname == "lona" and s < 0.6:
|
| 202 |
+
continue
|
| 203 |
+
|
| 204 |
class_names.append(cname)
|
| 205 |
detections.append({
|
| 206 |
"class": cname,
|
|
|
|
| 219 |
"contagem": counts,
|
| 220 |
"objetos": detections,
|
| 221 |
"intensity_score": intensity_score
|
| 222 |
+
}
|