ZFTurbo / segmentation_models_pytorch_3d

Segmentation models for 3D data with different backbones. PyTorch.
MIT License
20 stars 2 forks source link

find module path for python by modifying to relative module path #2

Open yuyuan871111 opened 3 months ago

yuyuan871111 commented 3 months ago

Hi, I just installed your package via Type 2: Copy segmentation_models_pytorch_3d folder from this repository in your project folder..

I discovered that certain files, particularly those in the model and decoder, rely on the segmentation_models_pytorch_3d module as part of the import root directory. This made it difficult for Python to locate the module when I copied the segmentation_models_pytorch_3d folder to my project directory. To resolve this, I changed the import format to a relative import (as attached). Is it a good choice to do so, or is there any solution to make Python find the files without modifying the source codes?

Screenshot 2024-03-14 at 17 22 38

Here is the list of files where I found the same issue. (maybe more)

modified:   segmentation_models_pytorch_3d/decoders/deeplabv3/model.py
modified:   segmentation_models_pytorch_3d/decoders/fpn/model.py
modified:   segmentation_models_pytorch_3d/decoders/linknet/decoder.py
modified:   segmentation_models_pytorch_3d/decoders/linknet/model.py
modified:   segmentation_models_pytorch_3d/decoders/manet/decoder.py
modified:   segmentation_models_pytorch_3d/decoders/manet/model.py
modified:   segmentation_models_pytorch_3d/decoders/pan/model.py
modified:   segmentation_models_pytorch_3d/decoders/pspnet/decoder.py
modified:   segmentation_models_pytorch_3d/decoders/pspnet/model.py
modified:   segmentation_models_pytorch_3d/decoders/unet/decoder.py
modified:   segmentation_models_pytorch_3d/decoders/unet/model.py
modified:   segmentation_models_pytorch_3d/decoders/unetplusplus/decoder.py
modified:   segmentation_models_pytorch_3d/decoders/unetplusplus/model.py
modified:   segmentation_models_pytorch_3d/encoders/__init__.py
modified:   segmentation_models_pytorch_3d/encoders/efficientnet.py
ZFTurbo commented 3 months ago

I will try to fix it. If you install from the pip or if you import from the directory your main .py file is located it should work fine.

yuyuan871111 commented 3 months ago

When I tried to install it from the poetry (almost the same as pip), it appeared a similar issue as using copy-paste installation.

Screenshot 2024-03-21 at 11 38 46
ZFTurbo commented 3 months ago

Can you try to add in your .py file:

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

import segmentation_models_pytorch_3d 

If your segmentation_models_pytorch_3d folder located in the same folder with your python file.