Spaces:
Running
Running
GitHub Actions
commited on
Commit
·
29a08a3
1
Parent(s):
63549e1
Auto-deploy from GitHub
Browse files- detect.py +4 -45
- predict.py +1 -1
detect.py
CHANGED
|
@@ -52,46 +52,9 @@ class DengueDetector:
|
|
| 52 |
print("Modelo carregado com as seguintes classes:", self.names)
|
| 53 |
|
| 54 |
def calculate_intensity(self, objects):
|
| 55 |
-
|
| 56 |
-
|
| 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 |
-
risk_contribution = weight * confidence * relative_area
|
| 92 |
-
total_score += risk_contribution
|
| 93 |
-
|
| 94 |
-
return total_score
|
| 95 |
|
| 96 |
def detect_image(self, image_bytes, fast: bool = True):
|
| 97 |
img = Image.open(BytesIO(image_bytes)).convert("RGB")
|
|
@@ -196,10 +159,6 @@ class DengueDetector:
|
|
| 196 |
x2 *= inv
|
| 197 |
y2 *= inv
|
| 198 |
cname = self.names[int(c)]
|
| 199 |
-
|
| 200 |
-
if cname == "lona" and s < 0.6:
|
| 201 |
-
continue
|
| 202 |
-
|
| 203 |
class_names.append(cname)
|
| 204 |
detections.append({
|
| 205 |
"class": cname,
|
|
@@ -218,4 +177,4 @@ class DengueDetector:
|
|
| 218 |
"contagem": counts,
|
| 219 |
"objetos": detections,
|
| 220 |
"intensity_score": intensity_score
|
| 221 |
-
}
|
|
|
|
| 52 |
print("Modelo carregado com as seguintes classes:", self.names)
|
| 53 |
|
| 54 |
def calculate_intensity(self, objects):
|
| 55 |
+
weights = {"piscina": 9, "caixa_agua": 4}
|
| 56 |
+
score = sum(weights.get(obj["class"], 0) for obj in objects)
|
| 57 |
+
return score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
def detect_image(self, image_bytes, fast: bool = True):
|
| 60 |
img = Image.open(BytesIO(image_bytes)).convert("RGB")
|
|
|
|
| 159 |
x2 *= inv
|
| 160 |
y2 *= inv
|
| 161 |
cname = self.names[int(c)]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
class_names.append(cname)
|
| 163 |
detections.append({
|
| 164 |
"class": cname,
|
|
|
|
| 177 |
"contagem": counts,
|
| 178 |
"objetos": detections,
|
| 179 |
"intensity_score": intensity_score
|
| 180 |
+
}
|
predict.py
CHANGED
|
@@ -249,4 +249,4 @@ class DenguePredictor:
|
|
| 249 |
{"factor": "Humidity", "value": "Increases adult mosquito survival"}
|
| 250 |
]
|
| 251 |
|
| 252 |
-
return lag_plot_b64, summary, tipping_points
|
|
|
|
| 249 |
{"factor": "Humidity", "value": "Increases adult mosquito survival"}
|
| 250 |
]
|
| 251 |
|
| 252 |
+
return lag_plot_b64, summary, tipping_points
|