PetervanLunteren / EcoAssist

Simplify camera trap image analysis with ML species recognition models based around the MegaDetector model
MIT License
121 stars 16 forks source link

Local variable 'elapsed time' referenced before assignment. #6

Closed rolanddu closed 1 year ago

rolanddu commented 1 year ago

When I attempt to to use EcoAssist_GUI.py using the provided training data, I receive this error. I am running on Windows 11 install under Anaconda, but I also receive the same error running in Linux Mint.

ERROR: local variable 'elapsed_time' referenced before assignment

DETAILS: Traceback (most recent call last): File "EcoAssist_GUI.py", line 1052, in start_deploy deploy_model(var_choose_folder.get(), additional_img_options, data_type = "img") File "EcoAssist_GUI.py", line 912, in deploy_model progress_stats['text'] = create_md_progress_lbl(elapsed_time = elapsed_time, UnboundLocalError: local variable 'elapsed_time' referenced before assignment.

Thanks, Roland

PetervanLunteren commented 1 year ago

This error means that there is some unexpected output coming from the model file. Do you get this error when verifying your installation using the default MegaDetector 5a on the test images described here? If so, then possibly something is wrong with your model file. Sometimes protection software prevent the download of the actual model files. Could you check if there are two files named md_v5a.0.0.pt and md_v5b.0.0.pt in \EcoAssist_files\pretrained_models\? You can find the location of the EcoAssist_files here.

rolanddu commented 1 year ago

Yes, I am using the defaults in the GUI, as described in the directions for testing, and the model files are fully downloaded. They are each 274.187 kilobytes in size. There are 5 test images in the test folder.

Thanks for your help. Roland

On Mon, May 1, 2023, 5:43 PM Peter van Lunteren @.***> wrote:

This error means that there is some unexpected output coming from the model file. Do you get this error when verifying your installation using the default MegaDetector 5a on the test images described here https://github.com/PetervanLunteren/EcoAssist#test-your-installation? If so, then possibly something is wrong with your model file. Sometimes protection software prevent the download of the actual model files. Could you check if there are two files named md_v5a.0.0.pt and md_v5b.0.0.pt in \EcoAssist_files\pretrained_models\? You can find the location of the EcoAssist_files here https://github.com/PetervanLunteren/EcoAssist#uninstall.

— Reply to this email directly, view it on GitHub https://github.com/PetervanLunteren/EcoAssist/issues/6#issuecomment-1530347885, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMJZLLYX67GI22MVOEKCCDXEAVABANCNFSM6AAAAAAXSEPQWI . You are receiving this because you authored the thread.Message ID: @.***>

PetervanLunteren commented 1 year ago

Hmm. There must be something else wrong. The log file should point us in the right direction. Could you please:

rolanddu commented 1 year ago

EXECUTED: deploy_model({'path_to_image_folder': '/home/roland/.EcoAssist_files/EcoAssist/test_images', 'selected_options': ['--output_relative_filenames', '--recursive'], 'data_type': 'img'})

EXECUTED: switch_yolov5_git_to({'model_type': 'old models'})

command:

["'/usr/bin/python' '/home/roland/.EcoAssist_files/cameratraps/detection/run_detector_batch.py' '/home/roland/.EcoAssist_files/pretrained_models/md_v5a.0.0.pt' '--output_relative_filenames' '--recursive' '/home/roland/.EcoAssist_files/EcoAssist/test_images' '/home/roland/.EcoAssist_files/EcoAssist/test_images/image_recognition_file.json'"]

Traceback (most recent call last): File "/home/roland/.EcoAssist_files/cameratraps/detection/run_detector_batch.py", line 47, in import humanfriendly ModuleNotFoundError: No module named 'humanfriendly' ERROR: local variable 'elapsed_time' referenced before assignment

DETAILS: Traceback (most recent call last): File "/home/roland/.EcoAssist_files/EcoAssist/EcoAssist_GUI.py", line 1048, in start_deploy deploy_model(var_choose_folder.get(), additional_img_options, data_type = "img") File "/home/roland/.EcoAssist_files/EcoAssist/EcoAssist_GUI.py", line 908, in deploy_model progress_stats['text'] = create_md_progress_lbl(elapsed_time = elapsed_time, UnboundLocalError: local variable 'elapsed_time' referenced before assignment

Closing at: Mon May 1 08:42:10 PM EDT 2023

PetervanLunteren commented 1 year ago

Right. It seems like the virtual environment somehow was not created.

I updated the code for Windows to proceed to a manual installation if the automatic one fails.

Could you try the Windows installation again to see if that fixes the issue?

rolanddu commented 1 year ago

The new install ends abruptly:

Volume in drive C is OS Volume Serial Number is E1234

Directory of C:\Program Files\EcoAssist_files\pretrained_models

05/02/2023 05:34 AM

. 05/02/2023 05:34 AM 280,766,885 md_v5a.0.0.pt 05/02/2023 05:35 AM 280,766,885 md_v5b.0.0.pt 2 File(s) 561,533,770 bytes 1 Dir(s) 3,299,837,648,896 bytes free 'conda' is not recognized as an internal or external command, operable program or batch file. \NVIDIA was unexpected at this time.

PetervanLunteren commented 1 year ago

This error has to do with a check to see if conda is correctly installed. Apparently it crashes on devices which have GPU acceleration...

I've adjusted the install script to avoid all issues regarding the automatic installs of git and conda and their checks (these bugs were giving me a headache). However, that means that users will have to install git and anaconda prior to installing EcoAssist. I've updated the documentation. Hope this resolves your issues. If so, please close this issue as solved.

rolanddu commented 1 year ago

I am still working on this. I will post more after I finish with this attempt. There seem to be issues with the version of Pillow not including resampling and some other issues. Just being sure I tried all my options. As Anaconda users know, "solving environment" takes hours, so my response time is slow. Thanks for your help.

rolanddu commented 1 year ago

Latest output in terminal:

(ecoassistcondaenv) C:\Program Files\EcoAssist_files\EcoAssist>python EcoAssist_GUI.py ['C:\Program Files\EcoAssist_files\cameratraps', 'C:\Program Files\EcoAssist_files\yolov5', 'C:\Program Files\EcoAssist_files\ai4eutils', 'C:\Program Files\EcoAssist_files', 'C:\Program Files\EcoAssist_files\EcoAssist', 'C:\ProgramData\anaconda3\envs\ecoassistcondaenv\lib\site-packages\git\ext\gitdb', 'C:\ProgramData\anaconda3\envs\ecoassistcondaenv\python38.zip', 'C:\ProgramData\anaconda3\envs\ecoassistcondaenv\DLLs', 'C:\ProgramData\anaconda3\envs\ecoassistcondaenv\lib', 'C:\ProgramData\anaconda3\envs\ecoassistcondaenv', 'C:\ProgramData\anaconda3\envs\ecoassistcondaenv\lib\site-packages', 'C:\ProgramData\anaconda3\envs\ecoassistcondaenv\lib\site-packages\win32', 'C:\ProgramData\anaconda3\envs\ecoassistcondaenv\lib\site-packages\win32\lib', 'C:\ProgramData\anaconda3\envs\ecoassistcondaenv\lib\site-packages\Pythonwin'] EXECUTED: browse_dir({'var': <tkinter.StringVar object at 0x000001B2BF799A60>, 'var_short': <tkinter.StringVar object at 0x000001B2BF799AC0>, 'dsp': <tkinter.Label object .!notebook.!frame.!labelframe.!label>, 'cut_off_length': 100, 'n_row': 0, 'n_column': 1, 'str_sticky': 'w'})

EXECUTED: start_deploy({})

EXECUTED: deploy_model({'path_to_image_folder': 'C:/Program Files/EcoAssist_files/EcoAssist/test_images', 'selected_options': ['--output_relative_filenames', '--recursive'], 'data_type': 'img'})

EXECUTED: switch_yolov5_git_to({'model_type': 'old models'})

command:

['C:\ProgramData\anaconda3\envs\ecoassistcondaenv\python.exe', 'C:\Program Files\EcoAssist_files\cameratraps\detection\run_detector_batch.py', 'C:\Program Files\EcoAssist_files\pretrained_models\md_v5a.0.0.pt', '--output_relative_filenames', '--recursive', 'C:\Program Files\EcoAssist_files\EcoAssist\test_images', 'C:\Program Files\EcoAssist_files\EcoAssist\test_images\image_recognition_file.json']

Traceback (most recent call last): File "C:\Program Files\EcoAssist_files\cameratraps\detection\run_detector_batch.py", line 69, in from detection.run_detector import ImagePathUtils, is_gpu_available,\ ModuleNotFoundError: No module named 'detection' ERROR: local variable 'elapsed_time' referenced before assignment

DETAILS: Traceback (most recent call last): File "EcoAssist_GUI.py", line 1056, in start_deploy deploy_model(var_choose_folder.get(), additional_img_options, data_type = "img") File "EcoAssist_GUI.py", line 916, in deploy_model progress_stats['text'] = create_md_progress_lbl(elapsed_time = elapsed_time, UnboundLocalError: local variable 'elapsed_time' referenced before assignment

Thanks, Roland

PetervanLunteren commented 1 year ago

Well, that is super weird. All of a sudden it can't find it's modules. If your showing me an error message from runtime, I assume that the installation went trough OK?

Can you check if the latest update to the open.bat solves the issue? Instead of you having to install everything again, you can:

rolanddu commented 1 year ago

Yes, it appears the install worked. I followed you above steps with similar result:

Traceback (most recent call last): File "C:\Program Files\EcoAssist_files\cameratraps\detection\run_detector_batch.py", line 69, in from detection.run_detector import ImagePathUtils, is_gpu_available,\ ModuleNotFoundError: No module named 'detection' ERROR: local variable 'elapsed_time' referenced before assignment

DETAILS: Traceback (most recent call last): File "EcoAssist_GUI.py", line 1056, in start_deploy deploy_model(var_choose_folder.get(), additional_img_options, data_type = "img") File "EcoAssist_GUI.py", line 916, in deploy_model progress_stats['text'] = create_md_progress_lbl(elapsed_time = elapsed_time, UnboundLocalError: local variable 'elapsed_time' referenced before assignment

Exception in Tkinter callback Traceback (most recent call last): File "EcoAssist_GUI.py", line 1056, in start_deploy deploy_model(var_choose_folder.get(), additional_img_options, data_type = "img") File "EcoAssist_GUI.py", line 916, in deploy_model progress_stats['text'] = create_md_progress_lbl(elapsed_time = elapsed_time, UnboundLocalError: local variable 'elapsed_time' referenced before assignment

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\ProgramData\anaconda3\envs\ecoassistcondaenv\lib\tkinter__init.py", line 1892, in call__ return self.func(*args) File "EcoAssist_GUI.py", line 1077, in start_deploy reset_frame_states() NameError: name 'reset_frame_states' is not defined

PetervanLunteren commented 1 year ago

Can you send me all the .txt files in EcoAssist_files\EcoAssist\logfiles via email?

rolanddu commented 1 year ago

Completely removing Anaconda and Python from my Windows 11 and then reinstalling the latest Anaconda fixed the problem.