analysiscenter/cardio

how to predict with .edf file?

Closed this issue · 6 comments

Dear all:
I have train a model with /example/Getting_started.jupyter
it's worked with .hea file
and it can predict hea file
but how to read .edf file
when I change lod .head file to .edf file
code:
index = bf.FilesIndex(path="../cardio/tests/data/sample.edf", no_ext=True, sort=True)
eds = bf.Dataset(index, batch_class=EcgBatch)
batch = eds.next_batch(batch_size=2)
batch_with_data = batch.load(fmt="edf", components=["signal", "meta"])

from cardio.pipelines import dirichlet_predict_pipeline
model_path = "af_model_dump"
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.7, allow_growth=True)
pipeline = dirichlet_predict_pipeline(model_path, gpu_options=gpu_options)
res = (eds >> pipeline).run()
pred = res.get_variable("predictions_list")

I get problem :
/usr/local/lib/python3.6/dist-packages/cardio/core/ecg_batch.py in _reraise_exceptions(self, results)
197 if bf.any_action_failed(results):
198 all_errors = self.get_errors(results)
--> 199 raise RuntimeError("Cannot assemble the batch", all_errors)
200
201 @staticmethod

RuntimeError: ('Cannot assemble the batch', [FileNotFoundError(2, 'No such file or directory')])

Plz help me~~
thanks a lot

Hi, @Hunter0904 !

Predefined pipelines that you are using were designed to demonstrate how the library works on two specific tasks with specific datasets. If you take a look at dirichlet_predict_pipeline's source code, you'd see that fmt parameter in load action is set to 'wfdb', because the pipeline was developed to work with PhysioNet2017 Challenge data.

You can use our pipelines as an example to develop those suited for your needs. E.g., to solve your current issue you can just replace 'wfdb' to 'edf' in dirichlet_predict_pipeline.

@dpodvyaznikov Thank for your answer.
But I don't have enough data to train new 'edf' model.
Is there a way to change the 'edf' file to 'wfdb' format ?
then I can use the same model to predict.

You still can use the model you've trained with dirichlet_train_pipeline.
The issue is in the way dirichlet_predict_pipeline tries to load the data. Since it has fmt='wfdb' in its load action, it tries to open file sample.hea instead of sample.edf. Since there is no such file, you get the error.
As I've said before, if you change fmt parameter to 'edf' in source code of dirichlet_predict_pipeline, you'll be able to run inference on edf files. Or you can make it a function argument and pass it directly when creatin pipeline.

I will try it ~
very appreciate~thanks a lot

I'll close this issue for now.

I had tried this. It's worked.
thanks a lot~~~