Skip to content

Commit 58d973c

Browse files
minor bugfixes (#125)
* minor bugfixes * improved logging to debug missing classification images * improved logging and no classification due to value below threshold * Upgraded version
1 parent 25c8ca5 commit 58d973c

File tree

9 files changed

+29
-20
lines changed

9 files changed

+29
-20
lines changed

requirements.txt

-6 Bytes
Binary file not shown.

wadas/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Date: 2024-08-14
1818
# Description: module to keep track of WADAS version
1919

20-
__version__ = "v0.5.1"
20+
__version__ = "v0.5.2"
2121
__dbversion__ = __version__

wadas/ai/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def classify(self, img, results, classification_threshold):
109109
# Performing classification
110110
classification_result = self.classify_crop(cropped_image, classification_threshold)
111111
if classification_result[0]:
112-
113112
classified_animals.append(
114113
{
115114
"id": classification_id,
@@ -129,6 +128,7 @@ def classify_crop(self, crop_img, classification_threshold):
129128
labels = txt_animalclasses[self.language]
130129

131130
if max(logits) < classification_threshold:
131+
logger.info("Classification value under selected threshold.")
132132
return ["", 0]
133133

134134
return [labels[np.argmax(logits)], max(logits)]

wadas/domain/ai_model.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,28 @@ def classify(self, img_path, results):
145145
logger.info("Running classification on %s image...", img_path)
146146
img = Image.open(img_path).convert("RGB")
147147

148-
classified_animals = self.detection_pipeline.classify(
149-
img, results, AiModel.classification_threshold
150-
)
151-
152-
for detection in classified_animals:
153-
# Cropping detection result(s) from original image leveraging detected boxes
154-
cropped_image = img.crop(detection["xyxy"])
155-
cropped_image_path = os.path.join(
156-
"classification_output", f"{detection['id']}_cropped_image.jpg"
148+
classified_animals = None
149+
classified_img_path = None
150+
if not (
151+
classified_animals := self.detection_pipeline.classify(
152+
img, results, AiModel.classification_threshold
157153
)
158-
cropped_image.save(cropped_image_path)
159-
logger.debug("Saved crop of image at %s.", cropped_image_path)
160-
161-
img_path = self.build_classification_square(img, classified_animals, img_path)
162-
return img_path, classified_animals
154+
):
155+
logger.debug("No classified animals, skipping img crops saving.")
156+
else:
157+
for classified_animal in classified_animals:
158+
# Cropping detection result(s) from original image leveraging detected boxes
159+
cropped_image = img.crop(classified_animal["xyxy"])
160+
cropped_image_path = os.path.join(
161+
"classification_output", f"{classified_animal['id']}_cropped_image.jpg"
162+
)
163+
cropped_image.save(cropped_image_path)
164+
logger.debug("Saved crop of image at %s.", cropped_image_path)
165+
166+
classified_img_path = self.build_classification_square(
167+
img, classified_animals, img_path
168+
)
169+
return classified_img_path, classified_animals
163170

164171
def build_classification_square(self, img, classified_animals, img_path):
165172
"""Build square on classified animals."""

wadas/domain/animal_detection_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def run(self):
7878
f"animal from camera {cur_img['img_id']}!"
7979
)
8080
else:
81-
logger.info("No animals to classify.")
81+
logger.info("No animal classified.")
8282
message = ""
8383
else:
8484
message = "WADAS has detected an animal from camera %s!" % id

wadas/domain/custom_classification_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ def run(self):
9696
self.last_classified_animals_str,
9797
)
9898
else:
99-
logger.info("No animals to classify.")
99+
logger.info("No animal classified.")
100100

101101
self.execution_completed()

wadas/domain/operation_mode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def _classify(self, detection_event: DetectionEvent):
160160
# Update detection event into db, if enabled
161161
if db := DataBase.get_enabled_db():
162162
db.update_detection_event(detection_event)
163+
else:
164+
logger.debug("No classified animals or classification results below threshold.")
163165

164166
def ftp_camera_exist(self):
165167
"""Method that returns True if at least an FTP camera exists, False otherwise."""

wadas/domain/test_model_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run(self):
8383
f"animal from camera {detection_event.classification_img_path}!"
8484
)
8585
else:
86-
logger.info("No animals to classify.")
86+
logger.info("No animal classified.")
8787
message = ""
8888

8989
# Send notification

wadas/ui/configure_web_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
QWidget,
3535
)
3636

37-
from ui.error_message_dialog import WADASErrorMessage
3837
from wadas.domain.database import DataBase, DBUser
38+
from wadas.ui.error_message_dialog import WADASErrorMessage
3939
from wadas.ui.qt.ui_configure_web_interface import Ui_DialogConfigureWebInterface
4040

4141
module_dir_path = os.path.dirname(os.path.abspath(__file__))

0 commit comments

Comments
 (0)