Skip to content

Commit

Permalink
Comet Image Logging Fix (#9498)
Browse files Browse the repository at this point in the history
fix issues with image logging
  • Loading branch information
DN6 committed Sep 19, 2022
1 parent 1164069 commit 0b724c5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions utils/loggers/comet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
comet_ml = None
COMET_PROJECT_NAME = None

import PIL
import torch
import torchvision.transforms as T
import yaml
Expand Down Expand Up @@ -131,6 +132,8 @@ def __init__(self, opt, hyp, run_id=None, job_type="Training", **experiment_kwar
else:
self.iou_thres = IOU_THRES

self.log_parameters({"val_iou_threshold": self.iou_thres, "val_conf_threshold": self.conf_thres})

self.comet_log_predictions = COMET_LOG_PREDICTIONS
if self.opt.bbox_interval == -1:
self.comet_log_prediction_interval = 1 if self.opt.epochs < 10 else self.opt.epochs // 10
Expand All @@ -139,6 +142,7 @@ def __init__(self, opt, hyp, run_id=None, job_type="Training", **experiment_kwar

if self.comet_log_predictions:
self.metadata_dict = {}
self.logged_image_names = []

self.comet_log_per_class_metrics = COMET_LOG_PER_CLASS_METRICS

Expand Down Expand Up @@ -249,11 +253,12 @@ def log_predictions(self, image, labelsn, path, shape, predn):
filtered_detections = detections[mask]
filtered_labels = labelsn[mask]

processed_image = (image * 255).to(torch.uint8)

image_id = path.split("/")[-1].split(".")[0]
image_name = f"{image_id}_curr_epoch_{self.experiment.curr_epoch}"
self.log_image(to_pil(processed_image), name=image_name)
if image_name not in self.logged_image_names:
native_scale_image = PIL.Image.open(path)
self.log_image(native_scale_image, name=image_name)
self.logged_image_names.append(image_name)

metadata = []
for cls, *xyxy in filtered_labels.tolist():
Expand Down

0 comments on commit 0b724c5

Please sign in to comment.