Skip to content

Commit

Permalink
Add model loading instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
KadenMc committed Aug 19, 2024
1 parent bd3e7d0 commit d3178f5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ Clone [fairseq_signals](https://github.com/Jwoo5/fairseq-signals) and refer to t
### Data Preparation
We implemented a flexible, end-to-end, multi-source data preprocessing pipeline. Please refer to it [here](https://github.com/Jwoo5/fairseq-signals/tree/master/scripts/preprocess/ecg).

### Inference

### Inference & Model Loading
See our [inference tutorial notebook](inference_tutorial.ipynb)!

### Training
Expand Down
60 changes: 60 additions & 0 deletions inference_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,66 @@
"# Visualize predicted and actual labels side-by-side\n",
"pred_thresh_mapped[['predicted']].join(code_15_labels[['actual']], how='left')"
]
},
{
"cell_type": "markdown",
"id": "d7c6b21a-2d1e-453e-ab8f-dc2015dd80a0",
"metadata": {},
"source": [
"# 5. Extra - Load models"
]
},
{
"cell_type": "markdown",
"id": "ed6cece6-a6e0-46c5-b022-7bdeb9ce68ec",
"metadata": {},
"source": [
"Above, inference is ran through scripts using the hydra client. Loading the models separately is possible like so:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8afcc57b-cf99-4538-bac9-82f3381bcef4",
"metadata": {},
"outputs": [],
"source": [
"import yaml\n",
"from fairseq_signals.models import build_model\n",
"\n",
"with open(\"ckpts/mimic_iv_ecg_physionet_pretrained.yaml\" ,\"r\") as f:\n",
" pretrained_cfg = yaml.load(f, yaml.FullLoader)\n",
"\n",
"pretrained_model_cfg = pretrained_cfg[\"model\"]\n",
"pretrained_model = build_model(pretrained_model_cfg, task=None)\n",
"pretrained_model"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed23b1b2-3aae-401d-8a44-f9088a52c8c0",
"metadata": {},
"outputs": [],
"source": [
"import yaml\n",
"from fairseq_signals.models import build_model\n",
"\n",
"with open(\"ckpts/physionet_finetuned.yaml\" ,\"r\") as f:\n",
" finetuned_cfg = yaml.load(f, yaml.FullLoader)\n",
"\n",
"finetuned_model_cfg = finetuned_cfg[\"model\"]\n",
"finetuned_model = build_model(finetuned_model_cfg, task=None)\n",
"finetuned_model"
]
},
{
"cell_type": "markdown",
"id": "51c04185-5013-4d69-b542-768995a3b8ce",
"metadata": {},
"source": [
"If you are seeing `FileNotFoundError: [Errno 2] No such file or directory: '<REDACTED>'`, please ensure you have run the `Prepare checkpoints` cells above!"
]
}
],
"metadata": {
Expand Down

0 comments on commit d3178f5

Please sign in to comment.