agentmorris / MegaDetector

MegaDetector is an AI model that helps conservation folks spend less time doing boring things with camera trap images.
MIT License
103 stars 24 forks source link

ModuleNotFoundError: No module named 'visualization' #65

Closed agentmorris closed 1 year ago

agentmorris commented 1 year ago

Hi there, I've probably done something stupid, but can't figure out what. I've run this on two different computers (but within the same university, so maybe there are some rights issues) and get to the same error.

Running Windows 10, Anaconda and Git installed fine. I ran the following lines of code without error:

mkdir c:\git cd c:\git git clone https://github.com/Microsoft/cameratraps git clone https://github.com/Microsoft/ai4eutils cd c:\git\cameratraps conda env create --file environment-detector.yml conda activate cameratraps-detector set PYTHONPATH=%PYTHONPATH%;c:\git\cameratraps;c:\git\ai4eutils;c:\git\yolov5

The git folder is in C:\git and the megadetector file is in C:\megadetector. (i.e. using the suggested defaults).

But when I run the following code, I get the error below.

(cameratraps-detector) PS C:\git\CameraTraps> python detection\run_detector.py "c:\megadetector\md_v5a.0.0.pt" --image_file ".\test_images\test_images\caltech_camera_traps_58a022a4-23d2-11e8-a6a3-ec086b02610b.jpg" --threshold 0.2

Traceback (most recent call last): File "detection\run_detector.py", line 53, in import visualization.visualization_utils as viz_utils ModuleNotFoundError: No module named 'visualization'

I did try do some trouble shooting, and two websites suggested that I run the following code: pip install tf-keras-vis pip install keras-vis

I did this. But no change.

What I am I missing? Thank you in advance for your time, and please let me know if there is any additional information that you may need.


Issue cloned from Microsoft/CameraTraps, original issue posted by alastairpotts on Jul 10, 2022.

agentmorris commented 1 year ago

Thanks for your interest in MegaDetector, and sorry you're having trouble getting up and running.

"visualization" is a folder in our repo, so this error indicates that our repo folder isn't found on your PYTHONPATH. It looks like you did everything correctly, so first can you just confirm that you ran the "set PYTHONPATH" statement immediately before trying to run the code? I.e., it was run in the same command prompt session?

If so, let's try one other thing... when you install Anaconda, it creates two shortcuts, one called "Anaconda prompt" and one called "Anaconda PowerShell prompt". Either is fine for running MegaDetector, but I want to make sure there isn't something funny going on with environment variables because you're in the PowerShell prompt (the "PS" in your prompt indicates that it's a PowerShell prompt). Can you try again in the non-PowerShell Anaconda prompt? And remember to run the "set PYTHONPATH" statement again in the new prompt.

Let us know if that fixes things... we'll get you going! Plenty more things we can try to help debug if this doesn't work.

Thanks!

-Dan


(Comment originally posted by agentmorris)

agentmorris commented 1 year ago

Hi there alastairpotts, As AgentMorris indicated, it could be that the PYTHONPATH variable is not set in the Powershell version of Anaconda.

Setting an environment variable in the PowerShell command is not done using the SET command. You can confirm that the environment variable exists in Powershell Anaconda by typing $env:py and then hit tab to allow it to autocomplete, if it doesn't then it likely doesn't exist. Or you can enter the following get-childitem env: This will then list all the environment variables You can set this in Powershell using the following command:

This will add the PYTHONPATH environment variable for the user and set it persistently. Good luck. https://shellgeek.com/set-environment-variable-using-powershell/#:~:text=Use%20%5BSystem.%20Environment%5D%20method%20in%20PowerShell%20to%20set,in%20Windows%20operating%20system.%20It%20contains%20name-value%20pair.


(Comment originally posted by pestell159)

agentmorris commented 1 year ago

Thanks for more details, @pestell159 . Based on this thread, I've updated the instructions to specifically encourage the standard Anaconda prompt (previously the instructions were a little more laissez-faire on this issue).

@alastairpotts , hope that either switching prompts or following @pestell159's suggestions fixes this for you!


(Comment originally posted by agentmorris)

agentmorris commented 1 year ago

It certainly has done. Thank you!

On Fri, 22 Jul 2022, 19:48 Dan Morris @.***> wrote:

Thanks for more details, @pestell159 https://github.com/pestell159 . Based on this thread, I've updated the instructions to specifically encourage the standard Anaconda prompt (previously the instructions were a little more laissez-faire on this issue).

@alastairpotts https://github.com/alastairpotts , hope that either switching prompts or following @pestell159 https://github.com/pestell159's suggestions fixes this for you!

— Reply to this email directly, view it on GitHub https://github.com/microsoft/CameraTraps/issues/300#issuecomment-1192804990, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVFA33OI77OA3XXGOPJ5GDVVLNFTANCNFSM53FQHUXQ . You are receiving this because you were mentioned.Message ID: @.***>


(Comment originally posted by alastairpotts)

agentmorris commented 1 year ago

Great! Closing. And thanks for helping us improve the instructions!


(Comment originally posted by agentmorris)

agentmorris commented 1 year ago

Hi Dan,

Oh my gosh. So simple and it worked! Not sure why the PowerShell did not work, but the non-PowerShell worked. Got my first batch identified and looking great!

Thank you!!!

Alastair

On Mon, 11 Jul 2022 at 01:19, Dan Morris @.***> wrote:

Thanks for your interest in MegaDetector, and sorry you're having trouble getting up and running.

"visualization" is a folder in our repo, so this error indicates that our repo folder isn't found on your PYTHONPATH. It looks like you did everything correctly, so first can you just confirm that you ran the "set PYTHONPATH" statement immediately before trying to run the code? I.e., it was run in the same command prompt session?

If so, let's try one other thing... when you install Anaconda, it creates two shortcuts, one called "Anaconda prompt" and one called "Anaconda PowerShell prompt". Either is fine for running MegaDetector, but I want to make sure there isn't something funny going on with environment variables because you're in the PowerShell prompt (the "PS" in your prompt indicates that it's a PowerShell prompt). Can you try again in the non-PowerShell Anaconda prompt? And remember to run the "set PYTHONPATH" statement again in the new prompt.

Let us know if that fixes things... we'll get you going! Plenty more things we can try to help debug if this doesn't work.

Thanks!

-Dan

— Reply to this email directly, view it on GitHub https://github.com/microsoft/CameraTraps/issues/300#issuecomment-1179821153, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVFA3YH4CYX2DRGAGUFVITVTNLA5ANCNFSM53FQHUXQ . You are receiving this because you authored the thread.Message ID: @.***>

-- C: 082 491-7275


(Comment originally posted by alastairpotts)