Skip to content

[WIP] Adding adapter for event detection on Chronos v1#35

Open
AnneMaelle wants to merge 36 commits into
benchopt:mainfrom
AnneMaelle:main
Open

[WIP] Adding adapter for event detection on Chronos v1#35
AnneMaelle wants to merge 36 commits into
benchopt:mainfrom
AnneMaelle:main

Conversation

@AnneMaelle
Copy link
Copy Markdown
Contributor

Add event detection task with MITDB dataset and Chronos adapter

Introduces event_detection as a new benchmark task:

  • MITDB dataset: 48-record MIT-BIH ECG database, sliding-window windowing (512 samples, 50% overlap),
    5-class AAMI beat grouping, events encoded as normalized (start, length, one-hot-class) slots
  • EventHead: DETR-style Transformer decoder with Hungarian matching loss (smooth-L1 position + BCE
    classification), trained on frozen Chronos encoder embeddings
  • Chronos solver: extended with event_detection support, batched embedding precomputation, fallback to
    ChronosPipeline for local T5 checkpoints, and configurable training hyperparameters
  • Metrics: map_iou, f1_det, event_span_iou, and event_iou_f1 (with configurable IoU threshold and
    matching strategy)

ABarneche and others added 30 commits May 28, 2026 16:12
- Add EventHead (Transformer-decoder, 10 learned queries) and
  ChronosEventAdapter in benchmark_utils/adapters/event_detection.py
- Add Chronos-EventDetection solver in solvers/chronos_event.py:
  frozen Chronos encoder + trainable head, with model_path param
  for offline/local model loading
- Add event_detection task branch to objective.py
- Add event_span_iou and event_class_f1 metrics to metrics.py
- Fix chronos.py: defer ChronosPipeline import to set_objective
  to avoid import-time crash when chronos-forecasting is not installed

Co-authored-by: Cursor <cursoragent@cursor.com>
ENH add Chronos event-detection solver with EventHead adapter
Add matching_strategy ("greedy"/"hungarian") and mode ("micro"/"macro")
parameters. Greedy now sorts predictions by descending confidence before
claiming the highest-IoU free ground-truth span. Penalise unmatched and
duplicate predictions as false positives over their active class columns.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add matching_strategy ("greedy"/"hungarian") and mode ("micro"/"macro")
parameters. Greedy now sorts predictions by descending confidence before
claiming the highest-IoU free ground-truth span. Penalise unmatched and
duplicate predictions as false positives over their active class columns.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Move _get_linear_cosine_scheduler, precompute_embeddings, fit_event_head
  from solvers/chronos_event.py to benchmark_utils/adapters/event_detection.py
- Add event_detection branch to solvers/chronos.py (import, SUPPORTED_TASKS,
  _CHRONOS_D, parameters, set_objective block, run() elif)
- Delete solvers/chronos_event.py

Co-authored-by: Cursor <cursoragent@cursor.com>
- Add num_queries parameter to Solver.parameters, __init__, and
  fit_event_head call in chronos.py
- Add _pad_or_truncate_labels helper in event_detection.py that
  truncates or zero-pads label arrays to exactly num_queries rows
- Apply padding/truncation upfront in fit_event_head so variable-length
  label lists can be batched safely

Co-authored-by: Cursor <cursoragent@cursor.com>
model code refactoring and add truncate padding on the model side
EventHead.compute_loss:
- Replace naive slot-aligned loss with DETR-style Hungarian matching
- Build (N, M) cost matrix per sample: L1 position cost + class cost
- Solve optimal assignment via scipy.optimize.linear_sum_assignment
- Matched slots: smooth_l1 position loss + GT class target
- Unmatched slots: BCE toward no-event (all-zero) class target

MITDB dataset:
- Add window_size=512 and window_overlap=0.5 parameters
- Add _extract_window_events helper: includes only beat events whose full
  span (start, length) = (R-peak - beat_window, 2*beat_window) lies
  entirely within the window; boundary-straddling events are discarded
- get_data now emits one (512, 2) window per stride step instead of
  one element per full record segment
- Positions normalised to [0, 1] over window_size

Co-authored-by: Cursor <cursoragent@cursor.com>
Chronos2Pipeline.from_pretrained raises AttributeError when the model
config references T5ForConditionalGeneration (Chronos-1 architecture).
load_model now catches AttributeError/ValueError and retries with the
legacy ChronosPipeline, so local chronos_t5_* checkpoints work without
any solver parameter changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
hungarian matching, data windowing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants