-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set up logging #63
Set up logging #63
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||
"""Top-level package for dreem.""" | ||||||
|
||||||
import logging.config | ||||||
from dreem.version import __version__ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import - from dreem.version import __version__ Committable suggestion
Suggested change
ToolsRuff
|
||||||
|
||||||
from dreem.models.global_tracking_transformer import GlobalTrackingTransformer | ||||||
|
@@ -16,3 +17,18 @@ | |||||
# from .training import run | ||||||
|
||||||
from dreem.inference.tracker import Tracker | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import - from dreem.inference.tracker import Tracker Committable suggestion
Suggested change
ToolsRuff
|
||||||
|
||||||
|
||||||
def setup_logging(): | ||||||
"""Setup logging based on `logging.yaml`.""" | ||||||
import logging | ||||||
import yaml | ||||||
import os | ||||||
|
||||||
package_directory = os.path.dirname(os.path.abspath(__file__)) | ||||||
|
||||||
with open(os.path.join(package_directory, "..", "logging.yaml"), "r") as stream: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary open mode parameters from the file open function. - with open(os.path.join(package_directory, "..", "logging.yaml"), "r") as stream:
+ with open(os.path.join(package_directory, "..", "logging.yaml")) as stream: Committable suggestion
Suggested change
ToolsRuff
|
||||||
logging_cfg = yaml.load(stream, Loader=yaml.FullLoader) | ||||||
|
||||||
logging.config.dictConfig(logging_cfg) | ||||||
logger = logging.getLogger("dreem") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove assignment to unused variable - logger = logging.getLogger("dreem") Committable suggestion
Suggested change
ToolsRuff
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,8 +3,11 @@ | |||||||||||||
import numpy as np | ||||||||||||||
import motmetrics as mm | ||||||||||||||
import torch | ||||||||||||||
from typing import Iterable | ||||||||||||||
import pandas as pd | ||||||||||||||
import logging | ||||||||||||||
from typing import Iterable | ||||||||||||||
|
||||||||||||||
logger = logging.getLogger("dreem.inference") | ||||||||||||||
|
||||||||||||||
# from dreem.inference.post_processing import _pairwise_iou | ||||||||||||||
# from dreem.inference.boxes import Boxes | ||||||||||||||
|
@@ -39,8 +42,8 @@ def get_matches(frames: list["dreem.io.Frame"]) -> tuple[dict, list, int]: | |||||||||||||
matches[match] = np.full(len(frames), 0) | ||||||||||||||
|
||||||||||||||
matches[match][idx] = 1 | ||||||||||||||
# else: | ||||||||||||||
# warnings.warn("No instances detected!") | ||||||||||||||
else: | ||||||||||||||
logger.debug("No instances detected!") | ||||||||||||||
return matches, indices, video_id | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
@@ -191,12 +194,7 @@ def to_track_eval(frames: list["dreem.io.Frame"]) -> dict: | |||||||||||||
data["num_gt_ids"] = len(unique_gt_ids) | ||||||||||||||
data["num_tracker_dets"] = num_tracker_dets | ||||||||||||||
data["num_gt_dets"] = num_gt_dets | ||||||||||||||
try: | ||||||||||||||
data["gt_ids"] = gt_ids | ||||||||||||||
# print(data['gt_ids']) | ||||||||||||||
except Exception as e: | ||||||||||||||
print(gt_ids) | ||||||||||||||
raise (e) | ||||||||||||||
data["gt_ids"] = gt_ids | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reconsider removing error handling. The removal of the try-except block for handling errors during the assignment of - data["gt_ids"] = gt_ids
+ try:
+ data["gt_ids"] = gt_ids
+ except Exception as e:
+ logger.error(f"Error assigning gt_ids: {e}")
+ raise Committable suggestion
Suggested change
|
||||||||||||||
data["tracker_ids"] = track_ids | ||||||||||||||
data["similarity_scores"] = similarity_scores | ||||||||||||||
data["num_timesteps"] = len(frames) | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,14 +4,16 @@ | |||||||||
from dreem.models import GTRRunner | ||||||||||
from omegaconf import DictConfig | ||||||||||
from pathlib import Path | ||||||||||
from pprint import pprint | ||||||||||
|
||||||||||
import hydra | ||||||||||
import os | ||||||||||
import pandas as pd | ||||||||||
import pytorch_lightning as pl | ||||||||||
import torch | ||||||||||
import sleap_io as sio | ||||||||||
import logging | ||||||||||
|
||||||||||
logger = logging.getLogger("dreem.inference") | ||||||||||
|
||||||||||
|
||||||||||
def export_trajectories( | ||||||||||
|
@@ -76,16 +78,13 @@ def track( | |||||||||
for frame in batch: | ||||||||||
lf, tracks = frame.to_slp(tracks) | ||||||||||
if frame.frame_id.item() == 0: | ||||||||||
print(f"Video: {lf.video}") | ||||||||||
logger.info(f"Video: {lf.video}") | ||||||||||
vid_trajectories[frame.video_id.item()].append(lf) | ||||||||||
|
||||||||||
for vid_id, video in vid_trajectories.items(): | ||||||||||
if len(video) > 0: | ||||||||||
try: | ||||||||||
vid_trajectories[vid_id] = sio.Labels(video) | ||||||||||
except AttributeError as e: | ||||||||||
print(video[0].video) | ||||||||||
raise (e) | ||||||||||
|
||||||||||
vid_trajectories[vid_id] = sio.Labels(video) | ||||||||||
|
||||||||||
return vid_trajectories | ||||||||||
|
||||||||||
|
@@ -106,7 +105,7 @@ def run(cfg: DictConfig) -> dict[int, sio.Labels]: | |||||||||
except KeyError: | ||||||||||
index = input("Pod Index Not found! Please choose a pod index: ") | ||||||||||
|
||||||||||
print(f"Pod Index: {index}") | ||||||||||
logger.info(f"Pod Index: {index}") | ||||||||||
|
||||||||||
checkpoints = pd.read_csv(cfg.checkpoints) | ||||||||||
checkpoint = checkpoints.iloc[index] | ||||||||||
|
@@ -115,10 +114,10 @@ def run(cfg: DictConfig) -> dict[int, sio.Labels]: | |||||||||
|
||||||||||
model = GTRRunner.load_from_checkpoint(checkpoint) | ||||||||||
tracker_cfg = pred_cfg.get_tracker_cfg() | ||||||||||
print("Updating tracker hparams") | ||||||||||
logger.info("Updating tracker hparams") | ||||||||||
model.tracker_cfg = tracker_cfg | ||||||||||
print(f"Using the following params for tracker:") | ||||||||||
pprint(model.tracker_cfg) | ||||||||||
logger.info(f"Using the following params for tracker:") | ||||||||||
logger.info(model.tracker_cfg) | ||||||||||
Comment on lines
+119
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extraneous - logger.info(f"Using the following params for tracker:")
+ logger.info("Using the following params for tracker:") Committable suggestion
Suggested change
ToolsRuff
|
||||||||||
|
||||||||||
dataset = pred_cfg.get_dataset(mode="test") | ||||||||||
dataloader = pred_cfg.get_dataloader(dataset, mode="test") | ||||||||||
|
@@ -139,7 +138,7 @@ def run(cfg: DictConfig) -> dict[int, sio.Labels]: | |||||||||
if os.path.exists(outpath): | ||||||||||
run_num += 1 | ||||||||||
outpath = outpath.replace(f".v{run_num-1}", f".v{run_num}") | ||||||||||
print(f"Saving {preds} to {outpath}") | ||||||||||
logger.info(f"Saving {preds} to {outpath}") | ||||||||||
pred.save(outpath) | ||||||||||
|
||||||||||
return preds | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import
logging.config
.- import logging.config
Committable suggestion
Tools
Ruff