mad-lab-fau / gaitmap

The Gait and Movement Analysis Package
https://gaitmap.readthedocs.io
Other
39 stars 2 forks source link

ModuleNotFoundError: No module named 'pomegranate' #67

Closed rmndrs89 closed 1 month ago

rmndrs89 commented 4 months ago

Hi all,

after installing gaitmap and gaitmap_mad using poetry (i.e. poetry add gaitmap gaitmap_mad), I was trying to run a stride segmentation on some data with the Nils Roth HMM, like:

from gaitmap.utils.coordinate_conversion import convert_to_fbf
from gaitmap.stride_segmentation.hmm import PreTrainedRothSegmentationModel, HmmStrideSegmentation

def main() -> None:
    ...

    # Instantiate a HMM
    roth_hmm_model = PreTrainedRothSegmentationModel()

    # Segment gait sequence into strides
    hmm_seg = HmmStrideSegmentation(roth_hmm_model, snap_to_min_win_ms=300, snap_to_min_axis="gyr_ml")
    hmm_seg = hmm_seg.segment(bf_data, sampling_rate_hz=SAMPLING_FREQ_HZ)

I get the following error:

Exception has occurred: ModuleNotFoundError
No module named 'pomegranate'
  File "/home/robbin/Projects/imuhealth/main.py", line 8, in <module>
    from gaitmap.stride_segmentation.hmm import PreTrainedRothSegmentationModel, HmmStrideSegmentation
ModuleNotFoundError: No module named 'pomegranate'

I have tried to install pomegranate separately with the same restrictions as in the gaitmap pyproject.toml, but this did not help.

Is this a known issue, and what will be the workaround?

AKuederle commented 4 months ago

@rmndrs89 Pomegrante is an optional dependency, so yes you always have to install it manually or by using the provided extra. Additionally, pomegranate does not support Python >=3.10. So it is likely that you are not able to install it all if you are not using Python 3.9.

See installation instructions for the HMM part in the README:

To use the HMM (anything imported from gaitmap.stride_segmentation.hmm) based algorithms make sure you install gaitmap with the hmm extra.

pip install gaitmap_mad "gaitmap[hmm]" --upgrade

This installs the pomegranate package, which is the basis for the HMM implementation. Note, that we only support the pomegranate version >=0.14.2,<=0.14.6 and that pomegrante is not compatible with Python 3.10.

AKuederle commented 4 months ago

I just double checked. When using Python 3.9 things work as expected. When using Python 3.10 or later, pomegrante will (silently) not be installed. Might be a good idea to catch the import error and provide some context...

Can you confirm that the wrong Python version is also the issue in your case?

rmndrs89 commented 4 months ago

Hi @AKuederle ,

Yes, you are right 👍 I have an environment with Python 3.10.

Does this also hold for pomegranate 1.0.0?

AKuederle commented 4 months ago

Pomegranate 1.0 is a complete rewrite using pytorch as backend. This is great, but the API changed completely and multiple pieces of functionality that we relied on are not available at all anymore. There is a branch where I tried to rewrite the hmm logic with the 1.0 version, but I couldn't get it to work.