Skip to content

Modernize inference and use pinned Hugging Face checkpoints - #10

Merged
robertavram-md merged 1 commit into
mainfrom
codex/modernize-inference-huggingface
Oct 27, 2026
Merged

robertavram-md merged 1 commit into
mainfrom
codex/modernize-inference-huggingface

Conversation

@robertavram-md

@robertavram-md robertavram-md commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Modernizes the legacy DICOM stenosis pipeline into an installable deepcoro package with separate input validation, geometry, preprocessing, model, Hub, and CLI modules. Inference resolves eight existing Hugging Face checkpoints from a pinned revision, supports cached/offline runs, and no longer embeds weights or downloads unrelated initialization weights.

Fixes DICOM-local frame indexing, CSV-relative paths, crop dimensions, blank-image normalization, small-image segmentation, empty outputs, tracking failures, and modern PyTorch checkpoint compatibility. Updates Docker packaging, documentation, and CI while preserving source entry points.

Validation: 35 tests pass; all eight published checkpoints downloaded and loaded; actual segmentation and GPU regression forwards, synthetic DICOM inference, MP4 encoding/decoding, offline reuse, wheel build, and installed CLI checked. Docker build was not run because Docker is unavailable in this environment.

Summary by Sourcery

Modernize DeepCoro inference into a validated installable package with reproducible external checkpoints, robust execution paths, and updated delivery tooling.

New Features:

  • Provide installable DeepCoro package and command-line tools for DICOM stenosis inference.
  • Resolve the eight required Hugging Face checkpoints from a pinned revision with local, cached, and offline execution support.

Bug Fixes:

  • Correct DICOM-local frame handling, CSV-relative paths, crop bounds, normalization, small-image segmentation, tracking failures, empty results, and modern checkpoint loading.

Enhancements:

  • Separate validation, DICOM handling, geometry, preprocessing, models, Hub integration, and pipeline orchestration while preserving legacy entry points.

Build:

  • Modernize Python packaging and Docker images around the installable package and external model cache.

CI:

  • Add automated test and CLI checks for pushes and pull requests.

Documentation:

  • Update installation, inference, model caching, offline use, Docker execution, inputs, outputs, and package organization documentation.

Tests:

  • Add regression coverage for model resolution, numerical edge cases, input validation, pipeline orchestration, and checkpoint compatibility.

Chores:

  • Remove embedded model downloads and unrelated initialization weights from runtime and container setup.

@cursor

cursor Bot commented Oct 27, 2026

Copy link
Copy Markdown

Bugbot needs on-demand usage enabled

Bugbot uses usage-based billing for this team and requires on-demand usage to be enabled.

A team admin can enable on-demand usage in the Cursor dashboard.

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Modernizes DeepCoro into an installable modular inference package, changes checkpoint loading to pinned and offline-capable Hugging Face resolution, fixes numerous DICOM/geometry/preprocessing/runtime edge cases, and updates deployment, documentation, compatibility entry points, and CI.

Sequence diagram for pinned and offline checkpoint resolution

sequenceDiagram
    participant CLI
    participant Pipeline
    participant Hub as deepcoro.hub
    participant HF as HuggingFaceCache
    participant Models as ModelLoader

    CLI->>Pipeline: deepcoro(input_file_path, save_dir, ...)
    Pipeline->>Hub: resolve_models(models_dir, repo_id, revision, cache_dir, local_files_only)
    alt local models supplied
        Hub->>Hub: validate_models(models_dir)
    else Hub models requested
        Hub->>HF: snapshot_download(repo_id, pinned revision, allow_patterns)
        HF-->>Hub: checkpoint snapshot
        Hub->>Hub: validate_models(snapshot)
    end
    Hub-->>Pipeline: validated model root
    Pipeline->>Models: load_model(segmentation checkpoint)
    Pipeline->>Models: load_regression_model(algorithm6.pt)
Loading

Sequence diagram for DICOM stenosis inference pipeline

sequenceDiagram
    participant Pipeline
    participant CSV as AnnotationReader
    participant DICOM as DICOMReader
    participant Geometry
    participant Segmentation
    participant Segments
    participant Regressor
    participant Output

    Pipeline->>CSV: read_annotations(input_file_path)
    Pipeline->>DICOM: read_dicom(relative or absolute path)
    DICOM-->>Pipeline: pixels, pixel_spacing, fps, patient_age
    Pipeline->>Geometry: resize_coordinates(box, pixel_spacing, pixels.shape, target_size)
    Pipeline->>Geometry: register(pixels, frame, resized_box)
    Pipeline->>Segmentation: perform_segmentation_inference(models, image, device)
    Segmentation-->>Pipeline: frame labels
    Pipeline->>Segments: identify_segments(stenoses, labels, artery_view)
    Segments-->>Pipeline: selected artery segments
    Pipeline->>Geometry: create_cropped_registered_video(pixels, frame, shifts, box)
    Pipeline->>Regressor: forward(video, age, artery_segment)
    Regressor-->>Pipeline: stenosis probability
    Pipeline->>Output: write df_stenosis.csv and optional MP4
Loading

File-Level Changes

Change Details Files
Refactored the legacy monolithic inference script into an installable, modular package while retaining source-level compatibility entry points.
  • Separated DICOM validation, geometry/tracking, preprocessing, segmentation labels, model construction, Hub resolution, pipeline orchestration, and CLI handling.
  • Added package metadata, console scripts, Python version/dependency constraints, and lazy loading of heavy inference dependencies.
  • Kept main.py and utils.py as forwarding compatibility layers and updated Docker execution to use the installed CLI.
deepcoro/__init__.py
deepcoro/__main__.py
deepcoro/cli.py
deepcoro/dicom.py
deepcoro/geometry.py
deepcoro/models.py
deepcoro/pipeline.py
deepcoro/preprocessing.py
deepcoro/segments.py
main.py
utils.py
pyproject.toml
requirements.txt
Changed model provisioning to resolve only the eight required Hugging Face checkpoints from a reproducible revision, with local and offline cache support.
  • Pinned the official repository to a commit and restricted downloads to seven segmentation checkpoints plus the regression checkpoint.
  • Added validation for missing, empty, and Git LFS pointer files, while supporting local model directories and existing clone layouts.
  • Removed embedded model provisioning and implicit ImageNet/Kinetics initialization downloads; added the deepcoro-download workflow and CLI options for revisions, cache directories, authentication, and offline mode.
deepcoro/hub.py
deepcoro/models.py
deepcoro/cli.py
README.md
Dockerfile
Corrected inference data handling and numerical edge cases across the DICOM-to-prediction pipeline.
  • Resolved relative DICOM paths against the annotation CSV and treated frame indices as DICOM-local zero-based values.
  • Added strict validation for CSV annotations, DICOM metadata, image dimensions, crop bounds, frame rates, dates, and grayscale input.
  • Handled blank-image normalization, small segmentation inputs, rectangular/tiny regions, out-of-frame tracking regions, empty outputs, tracking failures, and modern safe PyTorch checkpoint loading.
  • Preserved segmentation/regression preprocessing and output semantics while improving model caching, GPU memory movement, video streaming, and result CSV writing.
deepcoro/dicom.py
deepcoro/geometry.py
deepcoro/preprocessing.py
deepcoro/segments.py
deepcoro/models.py
deepcoro/pipeline.py
Modernized packaging, deployment documentation, and automated validation.
  • Replaced the Git LFS model clone and legacy base image with a Python 3.11 slim image, package installation, ffmpeg, and a persistent Hugging Face cache volume.
  • Documented installation, CLI/Docker usage, model access, offline operation, input/output formats, and package organization.
  • Added GitHub Actions coverage for installation, tests, and CLI help, plus focused tests for Hub behavior, numerical regressions, DICOM/CSV validation, and pipeline orchestration.
Dockerfile
README.md
.github/workflows/tests.yml
tests/test_hub.py
tests/test_numerics.py
tests/test_pipeline.py
.dockerignore
.gitignore
runall.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-27T21:17:32.160041Z b5e3961 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@robertavram-md
robertavram-md merged commit 7992850 into main Oct 27, 2026
6 checks passed
@cursor
cursor Bot requested a review from elodielabrecque October 27, 2026 21:19

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: High

Review is required. This assessment did not approve the pull request.

The diff rewrites DeepCoro inference. main.py and utils.py are compatibility shims; DICOM validation, crop geometry, tracking, segmentation, regression, and CSV/video outputs now live in the new deepcoro package (23 files, +1269/−743). That is the product’s clinical output path, not a packaging-only change.

Why this is high risk:

  • Segment selection votes across frames and keeps one annotation per segment. Severe stenosis is a fixed probability cutoff (0.23). Percent stenosis, the results CSV, and annotated videos can all differ from the previous pipeline.
  • Checkpoint loading changed (weights_only, no ImageNet encoder initialization, regressor in float64). Default weights are downloaded at runtime from a pinned Hugging Face snapshot instead of being cloned into the image at build time.
  • The container contract changed: python:3.11-slim, models are not baked in, the entrypoint is the deepcoro CLI, and a Hugging Face cache volume is required.
  • No CODEOWNERS file. The pull request was merged with no review on it.

Requested reviewer: @elodielabrecque (primary author of the previous algorithm code in utils.py). @cacoool has the Docker history but is not a repository collaborator, so that review request was rejected.

Open in Web View Automation 

Sent by Cursor Automation: Assign PR reviewers

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Fixed security issues:

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="README.md" line_range="114" />
<code_context>
+  -v /path/to/dcm_input:/dcm_input:ro \
+  -v /path/to/results:/results \
+  -v /path/to/hf-cache:/cache/huggingface \
+  deepcoro_inference
+```
+
</code_context>
<issue_to_address>
**Docker cannot use host credentials**

When docker downloads from the gated repository using a host-only `HF_TOKEN` or a login token outside the mounted cache, `docker run` does not forward a host `HF_TOKEN`, and the container cannot use a host `hf auth login` token unless that token is in the mounted cache; the gated-repository download is rejected and inference stops before running.

Document forwarding `HF_TOKEN` securely with `docker run -e HF_TOKEN`, or mount the host Hugging Face token cache into the container.

Also at `Dockerfile:12`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and changes to checkpoint loading, preprocessing, tracking, and inference can produce an incorrect artery segment or stenosis estimate, which is written to the results CSV and annotated videos. Those outputs can be regenerated from the original DICOMs and annotations after reverting or fixing the code.

Blocking findings: README.md:114


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread README.md
-v /path/to/dcm_input:/dcm_input:ro \
-v /path/to/results:/results \
-v /path/to/hf-cache:/cache/huggingface \
deepcoro_inference

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Docker cannot use host credentials

When docker downloads from the gated repository using a host-only HF_TOKEN or a login token outside the mounted cache, docker run does not forward a host HF_TOKEN, and the container cannot use a host hf auth login token unless that token is in the mounted cache; the gated-repository download is rejected and inference stops before running.

Document forwarding HF_TOKEN securely with docker run -e HF_TOKEN, or mount the host Hugging Face token cache into the container.

Also at Dockerfile:12.

Prompt for AI agents
In `README.md` at line 114:

**Docker cannot use host credentials**

When docker downloads from the gated repository using a host-only `HF_TOKEN` or a login token outside the mounted cache, `docker run` does not forward a host `HF_TOKEN`, and the container cannot use a host `hf auth login` token unless that token is in the mounted cache; the gated-repository download is rejected and inference stops before running.

Document forwarding `HF_TOKEN` securely with `docker run -e HF_TOKEN`, or mount the host Hugging Face token cache into the container.

Also at `Dockerfile:12`.

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.

2 participants