voldemortX / pytorch-auto-drive

PytorchAutoDrive: Segmentation models (ERFNet, ENet, DeepLab, FCN...) and Lane detection models (SCNN, RESA, LSTR, LaneATT, BézierLaneNet...) based on PyTorch with fast training, visualization, benchmarking & deployment help
BSD 3-Clause "New" or "Revised" License
837 stars 137 forks source link

error:from utils import datasets #85

Closed 578223592 closed 2 years ago

578223592 commented 2 years ago

when i read the code ,i get some codes in utils>runners>base.py from about lines 80

    def get_dataset_statics(self, dataset, map_dataset_statics, exist_ok=False):
        assert hasattr(self, '_cfg')
        if map_dataset_statics is not None:
            for k in map_dataset_statics:
                if exist_ok and k in self._cfg.keys():
                    continue
                if isinstance(dataset, str):
                    from utils import datasets
                    attr = getattr(datasets.__dict__[dataset], k)
                else:
                    attr = getattr(dataset, k)
                self._cfg[k] = attr

i want to see datasets.__dict__ so i write a py file in the same directory as base.py.

from utils import datasets
dict=datasets.__dict__
print(dict)

output:

/home/swx/.conda/envs/pad/bin/python /home/swx/pytorch-auto-drive-master/utils/runners/temp.py
Traceback (most recent call last):
  File "/home/swx/pytorch-auto-drive-master/utils/runners/temp.py", line 2, in <module>
    from utils import datasets
ModuleNotFoundError: No module named 'utils'

I tried to change the code to:

import sys
import os
sys.path.append(os.path.join(os.getcwd()))
from utils import datasets
dict=datasets.__dict__
data=datasets
print(dict)

and there is no error like :ModuleNotFoundError: No module named 'utils' anymore. I don't know if this is a bug or if I misunderstood.

In addition, I would appreciate it if I could get the function's action of get_dataset_statics

voldemortX commented 2 years ago

@578223592 what's the pwd when you run that temp.py? You need to import according to your execution directory. If no proper import is available, I do recommend using importmagician for sys path appends (like in the configs), it is cleaner.

voldemortX commented 2 years ago

what do you mean exactly by the function's action of get_dataset_statics? Do you mean you want me to explain what this function does or something?

578223592 commented 2 years ago

Thank you very much. Your recommendation is very helpful.

@578223592 what's the pwd when you run that temp.py? You need to import according to your execution directory. If no proper import is available, I do recommend using importmagician for sys path appends (like in the configs), it is cleaner.