Skip to content
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

tutorial inference question #2

Open
jihyeheo opened this issue Oct 8, 2024 · 2 comments
Open

tutorial inference question #2

jihyeheo opened this issue Oct 8, 2024 · 2 comments

Comments

@jihyeheo
Copy link

jihyeheo commented Oct 8, 2024

hi? I'm trying to apply ecg-fm, but the process of importing physionet_finetune.pt doesn't work. 5. In load model!
The mimic pt works well, but why is that?

root = os.getcwd()
root
model_pretrained = build_model_from_checkpoint(
checkpoint_path=os.path.join(root, 'ckpts', 'physionet_finetuned.pt')
)
model_pretrained

@KadenMc
Copy link
Collaborator

KadenMc commented Oct 24, 2024

Are you on the latest versions of both ECG-FM and fairseq-signals repositories? If not, see if that fixes your issue.

Otherwise, please report back the error message you receive, as well as information about your virtual environment.

@chenqi-li
Copy link

chenqi-li commented Oct 31, 2024

Hi I am facing a similar issue, where I cannot load the physionet_finetuned.pt.

I have installed the latest ECG-FM and fairseq-signals. I tested with the code below.

import os
import pandas as pd
import torch

from fairseq_signals.utils.store import MemmapReader


# Manage directories
root = os.getcwd()
fairseq_signals_root = '/users/fairseq-signals'
fairseq_signals_root = fairseq_signals_root.rstrip('/')


# Download finetuned checkpoint
from huggingface_hub import hf_hub_download
_ = hf_hub_download(
    repo_id='wanglab/ecg-fm-preprint',
    filename='physionet_finetuned.pt',
    local_dir=os.path.join(root, 'ckpts'),
)
_ = hf_hub_download(
    repo_id='wanglab/ecg-fm-preprint',
    filename='physionet_finetuned.yaml',
    local_dir=os.path.join(root, 'ckpts'),
)



# Load model
from fairseq_signals.models import build_model_from_checkpoint
model_finetuned = build_model_from_checkpoint(
    checkpoint_path=os.path.join(root, 'ckpts/physionet_finetuned.pt')
)

I am getting the error

Traceback (most recent call last):
  File "/users/ECG-FM/inference_example.py", line 31, in <module>
    model_finetuned = build_model_from_checkpoint(
  File "/users/fairseq-signals/fairseq_signals/models/__init__.py", line 106, in build_model_from_checkpoint
    return build_model(model_cfg, task=None, from_checkpoint=True, checkpoint_path=checkpoint_path)
  File "/users/fairseq-signals/fairseq_signals/models/__init__.py", line 93, in build_model
    model_instance = model.build_model(cfg, task)
  File "/users/fairseq-signals/fairseq_signals/models/ecg_transformer.py", line 260, in build_model
    encoder = ECGTransformerModel.from_pretrained(cfg.model_path, cfg)
  File "/users/fairseq-signals/fairseq_signals/models/ecg_transformer.py", line 232, in from_pretrained
    model = super().from_pretrained(model_path, cfg, arg_overrides)
  File "/users/fairseq-signals/fairseq_signals/models/transformer.py", line 237, in from_pretrained
    return super().from_pretrained(model_path, cfg, arg_overrides, **kwargs)
  File "/users/fairseq-signals/fairseq_signals/models/pretraining_model.py", line 81, in from_pretrained
    model = task.build_model(args.model)
  File "/users/fairseq-signals/fairseq_signals/tasks/ecg_pretraining.py", line 380, in build_model
    model = super().build_model(model_cfg)
  File "/users/fairseq-signals/fairseq_signals/tasks/task.py", line 291, in build_model
    model = models.build_model(cfg, self, from_checkpoint)
  File "/users/fairseq-signals/fairseq_signals/models/__init__.py", line 93, in build_model
    model_instance = model.build_model(cfg, task)
  File "/users/fairseq-signals/fairseq_signals/models/ecg_transformer.py", line 260, in build_model
    encoder = ECGTransformerModel.from_pretrained(cfg.model_path, cfg)
  File "/users/fairseq-signals/fairseq_signals/models/ecg_transformer.py", line 232, in from_pretrained
    model = super().from_pretrained(model_path, cfg, arg_overrides)
  File "/users/fairseq-signals/fairseq_signals/models/transformer.py", line 237, in from_pretrained
    return super().from_pretrained(model_path, cfg, arg_overrides, **kwargs)
  File "/users/fairseq-signals/fairseq_signals/models/pretraining_model.py", line 63, in from_pretrained
    state = checkpoint_utils.load_checkpoint_to_cpu(model_path, arg_overrides)
  File "/users/fairseq-signals/fairseq_signals/utils/checkpoint_utils.py", line 267, in load_checkpoint_to_cpu
    with open(local_path, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '<REDACTED>'

In the physionet_finetuned.pt checkpoint, the model.model_path variable in the cfg is REDACTED, and the build_model_from_checkpoint function appears to use that variable?

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

No branches or pull requests

3 participants