umyelab / LabGym

Quantify user-defined behaviors.
GNU General Public License v3.0
64 stars 5 forks source link

Error message when starting 'Train Detectors' #174

Closed mythhero2 closed 1 month ago

mythhero2 commented 2 months ago

After generating image examples, annotation was done via Roboflow. When trying 'Train Detectors' using the annotated images with json file, below error message was shown:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/LabGym/gui/training/detectors.py", line 398, in train_detector Detector(name=detector_name).train( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/LabGym/detector.py", line 168, in train if "LabGym_detector_train" in DatasetCatalog.list(): NameError: name 'DatasetCatalog' is not defined

What did I do wrong?

yujiahu415 commented 2 months ago

Hi,

This error indicates that the detectron2 hasn't been successfully installed or imported. When you initiate LabGym, did you receive this warning in the terminal: 'You need to install Detectron2 to use the Detector module in LabGym...'?

It's also possible that the detectron2 may be installed in a different environment from LabGym. Can you also check this?

You can try python3 to initiate python3 and type import LabGym and import detectron2 to see if there's any importing errors.

mythhero2 commented 2 months ago

I tried as you recommended: python3 import LabGym -----> nothing popped up import detectron2 --------> nothing popped up

However, as you pointed out, error message 'You need to install Detectron2 to use the Detector module in LabGym...' is coming up when I initiate LabGym.

I realized I didn't downgrade PyTorch to v2.0.1. I tried this as following:

python3 -m pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cpu

Now there is an new error message: ERROR: Could not find a version that satisfies the requirement torch==2.0.1 (from versions: 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1) ERROR: No matching distribution found for torch==2.0.1

It seems that Detectron2 was not well installed due to the above issue with PyTorch downgrade. Is this right?

By the way, I am running this on anaconda in M1 Mac (Sonoma 14.5).

mythhero2 commented 2 months ago

I tried to rebuild all under the different version of python (3.10.14). Everything went OK, and PyTorch downgrade was successful.

However, the error 'You need to install Detectron2 to use the Detector module in LabGym...' is still coming up after initiating LabGym, as below:

You need to install Detectron2 to use the Detector module in LabGym: https://detectron2.readthedocs.io/en/latest/tutorials/install.html 2024-07-15 18:24:46.622 Python[59371:1660682] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES. The user interface initialized!

yujiahu415 commented 2 months ago

After rebuilding everything under python3.10.14, have you also tried to initiate python3 to check its version, and import LabGym and detectron2 to see if they were successfully installed within python3.10.14, and also check PyTorch version==2.0.1? If so, can you try to uninstall detectron2 python3 -m pip uninstall detectron2 and then upgrade PyTorch python3 -m pip install torch==2.3.1, and then reinstall detectron2 python3 -m pip install 'git+https://github.com/facebookresearch/detectron2.git', and then downgrade PyTorch to v2.0.1: if your system is Mac, try python3 -m pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2. And let me know if this works.

mythhero2 commented 2 months ago

As you recommended, I rebuild everything under python 3.10.14 in Anaconda; reinstalled LabGym and detectron2 under Pytorch2.3.1. Then Pytorch2.0.1 was re-installed.

Everything seems to work well. No issue with 'Train Detectors' with annotated images.

I think my problems were the python version required for PyTorch v2.0.1 and whether detectron2 was in the same environment with LabGym.

Thanks for your advise!

yujiahu415 commented 1 month ago

Thanks for letting me know this!