# mjahmadee/cataract-lmm architecture

> Architecture diagram of the GitHub repository mjahmadee/cataract-lmm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mjahmadee/cataract-lmm
- Repository: https://github.com/mjahmadee/cataract-lmm

## Overview

Cataract-LMM is a multi-task framework for surgical video analysis. The documented workflow takes video through processing and frame preparation, then produces instance-segmentation, phase-recognition, and skill-assessment results. Its code is organized as distinct packages rather than one demonstrated end-to-end runtime: the video orchestrator coordinates processing components, while the analysis packages expose separate model, training, and inference paths. The README documents several capabilities beyond the sampled excerpts; those branches are included, but uncertain cross-package wiring is omitted.

Main entry points: [`codes/surgical-video-processing/pipelines/orchestrator.py`](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-video-processing/pipelines/orchestrator.py) (Pipeline orchestrator), [`codes/surgical-skill-assessment/main.py`](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/main.py) (Assessment workflow), [`codes/surgical-instance-segmentation/models/model_factory.py`](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/models/model_factory.py) (Model factory), [`codes/surgical-instance-segmentation/training/training_manager.py`](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/training/training_manager.py) (Training manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_video["Video processing"]
  node_video_cli["Processing entry<br/>[main.py]"]
  node_orchestrator["Pipeline orchestrator<br/>[orchestrator.py]"]
  node_video_core["Video processor<br/>[video_processor.py]"]
  node_privacy["De-identification"]
  node_metadata["Metadata handling"]
  node_quality["Quality control"]
end

subgraph group_segment["Instance segmentation"]
  node_seg_data["Dataset utilities<br/>[dataset_utils.py]"]
  node_seg_factory["Model factory<br/>[model_factory.py]"]
  node_seg_mask["Mask R-CNN<br/>[model.py]"]
  node_seg_predictor["Mask R-CNN predictor<br/>[predictor.py]"]
  node_seg_realtime["Real-time inference"]
  node_seg_train_manager["Training manager"]
  node_seg_trainer["Model trainers"]
end

subgraph group_phase["Phase recognition"]
  node_phase_preprocess["Video preprocessing"]
  node_phase_models["Temporal models"]
  node_phase_multistage["Multistage models"]
  node_phase_train["Training framework"]
  node_phase_analysis["Model analysis<br/>[model_analyzer.py]"]
end

subgraph group_skill["Skill assessment"]
  node_skill_entry["Assessment workflow<br/>[main.py]"]
  node_skill_factory["Model factory<br/>[factory.py]"]
  node_skill_models["Video classifiers<br/>[transformers.py]"]
  node_skill_trainer["Training engine<br/>[trainer.py]"]
  node_skill_predictor["Prediction engine<br/>[predictor.py]"]
end

node_user(("Video analyst"))
node_input["Surgical video"]
node_video_results["Processed video"]
node_seg_results["Instrument masks"]
node_phase_results["Surgery phases"]
node_skill_results["Skill metrics"]

node_user -->|"provides"| node_input
node_input -->|"supplies video"| node_video_cli
node_video_cli -->|"starts processing"| node_orchestrator
node_orchestrator -->|"processes video"| node_video_core
node_orchestrator -->|"uses when enabled"| node_privacy
node_orchestrator -->|"extracts metadata"| node_metadata
node_orchestrator -->|"checks quality"| node_quality
node_orchestrator -->|"produces"| node_video_results
node_video_results -.->|"feeds analysis"| node_seg_data
node_seg_data -->|"provides datasets"| node_seg_train_manager
node_seg_train_manager -->|"dispatches training"| node_seg_trainer
node_seg_train_manager -->|"creates models"| node_seg_factory
node_seg_factory -->|"constructs model"| node_seg_mask
node_seg_factory -->|"constructs predictor"| node_seg_predictor
node_seg_realtime -->|"invokes inference"| node_seg_predictor
node_seg_realtime -.->|"emits predictions"| node_seg_results
node_video_results -.->|"feeds analysis"| node_phase_preprocess
node_phase_preprocess -.->|"prepares video"| node_phase_train
node_phase_train -->|"uses model"| node_phase_multistage
node_phase_train -->|"loads models"| node_phase_models
node_phase_analysis -.->|"analyzes predictions"| node_phase_results
node_phase_models -.->|"classifies phases"| node_phase_results
node_video_results -.->|"feeds assessment"| node_skill_entry
node_skill_entry -->|"creates model"| node_skill_factory
node_skill_entry -->|"trains model"| node_skill_trainer
node_skill_entry -->|"runs prediction"| node_skill_predictor
node_skill_factory -->|"constructs classifier"| node_skill_models
node_skill_entry -.->|"reports assessment"| node_skill_results

click node_video_cli "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-video-processing/main.py"
click node_orchestrator "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-video-processing/pipelines/orchestrator.py"
click node_video_core "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-video-processing/core/video_processor.py"
click node_privacy "https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-video-processing/deidentification"
click node_metadata "https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-video-processing/metadata"
click node_quality "https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-video-processing/quality_control"
click node_seg_data "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/data/dataset_utils.py"
click node_seg_factory "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/models/model_factory.py"
click node_seg_mask "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/models/mask_rcnn/model.py"
click node_seg_predictor "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/models/mask_rcnn/predictor.py"
click node_seg_realtime "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/inference/real_time_engine.py"
click node_seg_train_manager "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/training/training_manager.py"
click node_seg_trainer "https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-instance-segmentation/training"
click node_phase_preprocess "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-phase-recognition/preprocessing/video_preprocessing.py"
click node_phase_models "https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-phase-recognition/models"
click node_phase_multistage "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-phase-recognition/models/multistage_models.py"
click node_phase_train "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-phase-recognition/validation/training_framework.py"
click node_phase_analysis "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-phase-recognition/analysis/model_analyzer.py"
click node_skill_entry "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/main.py"
click node_skill_factory "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/models/factory.py"
click node_skill_models "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/models/transformers.py"
click node_skill_trainer "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/engine/trainer.py"
click node_skill_predictor "https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/engine/predictor.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_video_cli,node_orchestrator,node_video_core,node_privacy,node_metadata,node_quality toneBlue
class node_seg_data,node_seg_factory,node_seg_mask,node_seg_predictor,node_seg_realtime,node_seg_train_manager,node_seg_trainer toneAmber
class node_phase_preprocess,node_phase_models,node_phase_multistage,node_phase_train,node_phase_analysis toneMint
class node_skill_entry,node_skill_factory,node_skill_models,node_skill_trainer,node_skill_predictor toneRose
class node_user,node_input,node_video_results,node_seg_results,node_phase_results,node_skill_results toneIndigo
```

## Components

### Video processing

- [Processing entry](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-video-processing/main.py): `codes/surgical-video-processing/main.py`
- [Pipeline orchestrator](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-video-processing/pipelines/orchestrator.py): `codes/surgical-video-processing/pipelines/orchestrator.py`
- [Video processor](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-video-processing/core/video_processor.py): `codes/surgical-video-processing/core/video_processor.py`
- [De-identification](https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-video-processing/deidentification): `codes/surgical-video-processing/deidentification`
- [Metadata handling](https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-video-processing/metadata): `codes/surgical-video-processing/metadata`
- [Quality control](https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-video-processing/quality_control): `codes/surgical-video-processing/quality_control`

### Instance segmentation

- [Dataset utilities](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/data/dataset_utils.py): `codes/surgical-instance-segmentation/data/dataset_utils.py`
- [Model factory](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/models/model_factory.py): `codes/surgical-instance-segmentation/models/model_factory.py`
- [Mask R-CNN](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/models/mask_rcnn/model.py): `codes/surgical-instance-segmentation/models/mask_rcnn/model.py`
- [Mask R-CNN predictor](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/models/mask_rcnn/predictor.py): `codes/surgical-instance-segmentation/models/mask_rcnn/predictor.py`
- [Real-time inference](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/inference/real_time_engine.py): `codes/surgical-instance-segmentation/inference/real_time_engine.py`
- [Training manager](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-instance-segmentation/training/training_manager.py): `codes/surgical-instance-segmentation/training/training_manager.py`
- [Model trainers](https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-instance-segmentation/training): `codes/surgical-instance-segmentation/training`

### Phase recognition

- [Video preprocessing](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-phase-recognition/preprocessing/video_preprocessing.py): `codes/surgical-phase-recognition/preprocessing/video_preprocessing.py`
- [Temporal models](https://github.com/mjahmadee/cataract-lmm/tree/main/codes/surgical-phase-recognition/models): `codes/surgical-phase-recognition/models`
- [Multistage models](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-phase-recognition/models/multistage_models.py): `codes/surgical-phase-recognition/models/multistage_models.py`
- [Training framework](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-phase-recognition/validation/training_framework.py): `codes/surgical-phase-recognition/validation/training_framework.py`
- [Model analysis](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-phase-recognition/analysis/model_analyzer.py): `codes/surgical-phase-recognition/analysis/model_analyzer.py`

### Skill assessment

- [Assessment workflow](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/main.py): `codes/surgical-skill-assessment/main.py`
- [Model factory](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/models/factory.py): `codes/surgical-skill-assessment/models/factory.py`
- [Video classifiers](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/models/transformers.py): `codes/surgical-skill-assessment/models/transformers.py`
- [Training engine](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/engine/trainer.py): `codes/surgical-skill-assessment/engine/trainer.py`
- [Prediction engine](https://github.com/mjahmadee/cataract-lmm/blob/main/codes/surgical-skill-assessment/engine/predictor.py): `codes/surgical-skill-assessment/engine/predictor.py`

### Other components

- **Video analyst**
- **Surgical video**
- **Processed video**
- **Instrument masks**
- **Surgery phases**
- **Skill metrics**

## Connections

- Video analyst → Surgical video: provides (evidence: `README.md`)
- Surgical video → Processing entry: supplies video (evidence: `README.md`)
- Processing entry → Pipeline orchestrator: starts processing (evidence: `codes/surgical-video-processing/main.py`)
- Pipeline orchestrator → Video processor: processes video (evidence: `codes/surgical-video-processing/pipelines/orchestrator.py`)
- Pipeline orchestrator → De-identification: uses when enabled (evidence: `codes/surgical-video-processing/pipelines/orchestrator.py`)
- Pipeline orchestrator → Metadata handling: extracts metadata (evidence: `codes/surgical-video-processing/pipelines/orchestrator.py`)
- Pipeline orchestrator → Quality control: checks quality (evidence: `codes/surgical-video-processing/pipelines/orchestrator.py`)
- Pipeline orchestrator → Processed video: produces (evidence: `README.md`)
- Processed video → Dataset utilities: feeds analysis
- Dataset utilities → Training manager: provides datasets (evidence: `codes/surgical-instance-segmentation/training/training_manager.py`)
- Training manager → Model trainers: dispatches training (evidence: `codes/surgical-instance-segmentation/training/training_manager.py`)
- Training manager → Model factory: creates models (evidence: `codes/surgical-instance-segmentation/training/training_manager.py`)
- Model factory → Mask R-CNN: constructs model (evidence: `codes/surgical-instance-segmentation/models/model_factory.py`)
- Model factory → Mask R-CNN predictor: constructs predictor (evidence: `codes/surgical-instance-segmentation/models/model_factory.py`)
- Real-time inference → Mask R-CNN predictor: invokes inference (evidence: `codes/surgical-instance-segmentation/inference/real_time_engine.py`)
- Real-time inference → Instrument masks: emits predictions
- Processed video → Video preprocessing: feeds analysis
- Video preprocessing → Training framework: prepares video
- Training framework → Multistage models: uses model (evidence: `codes/surgical-phase-recognition/validation/training_framework.py`)
- Training framework → Temporal models: loads models (evidence: `codes/surgical-phase-recognition/validation/training_framework.py`)
- Model analysis → Surgery phases: analyzes predictions
- Temporal models → Surgery phases: classifies phases (evidence: `README.md`)
- Processed video → Assessment workflow: feeds assessment
- Assessment workflow → Model factory: creates model (evidence: `codes/surgical-skill-assessment/main.py`)
- Assessment workflow → Training engine: trains model (evidence: `codes/surgical-skill-assessment/main.py`)
- Assessment workflow → Prediction engine: runs prediction (evidence: `codes/surgical-skill-assessment/main.py`)
- Model factory → Video classifiers: constructs classifier (evidence: `codes/surgical-skill-assessment/models/factory.py`)
- Assessment workflow → Skill metrics: reports assessment
