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

No module named 'detection' #56

Closed agentmorris closed 1 year ago

agentmorris commented 1 year ago

when i try to run the code on local pc i got this error Traceback (most recent call last): File "CameraTraps\detection/run_detector_batch.py", line 79, in <module> from detection.run_detector import ImagePathUtils, is_gpu_available, load_detector ModuleNotFoundError: No module named 'detection'


Issue cloned from Microsoft/CameraTraps, original issue posted by VYRION-Ai on Apr 24, 2022.

agentmorris commented 1 year ago

this is my code

`import os
import tensorflow as tf

os.environ['PYTHONPATH'] += 'i4eutils'
os.environ['PYTHONPATH'] += 'CameraTraps'

print(tf.__version__)
os.system(
    "python CameraTraps\detection/run_detector_batch.py --detector_file megadetector_v4_1_0.pb --image_file img   --output_file j/ra.json")
`

and this is the out put 2.8.0 Traceback (most recent call last): File "CameraTraps\detection/run_detector_batch.py", line 79, in <module> from detection.run_detector import ImagePathUtils, is_gpu_available, load_detector ModuleNotFoundError: No module named 'detection'


(Comment originally posted by VYRION-Ai)

agentmorris commented 1 year ago

i solve the it by , put all folders in detection folder and remove detection. from all files it written and it runs


(Comment originally posted by VYRION-Ai)

agentmorris commented 1 year ago

It appears that the CameraTraps repo is not on the PYTHONPATH of the python process that's running run_detector_batch.py. It looks like you added "CameraTraps" to your PYTHONPATH, which should be OK if the python process is definitely running in the parent folder of the "CameraTraps" repo.

I'm not sure what your environment looks like; the issue may be that either (1) by using "os.system", your particular environment is not passing the PYTHONPATH environment variable to the Python process or (2) the Python process is running in a different working directory.

More generally, I think you're adapting this approach from the Colab; those instructions are pretty specific to the Colab environment, so I wouldn't recommend that. With enough tinkering, I think you could get this approach to work, but it would be unusual. Instead, outside of Colab, I would recommend following the instructions here:

https://github.com/microsoft/CameraTraps/blob/main/megadetector.md#2-run_detector_batchpy

There are instructions for both Windows and Linux.

Also, unrelated to the current issue, there's a typo in your code: "i4eutils" should be "ai4eutils".

Hope that helps!


(Comment originally posted by agentmorris)

agentmorris commented 1 year ago

Oops, my reply crossed paths with totoadel's, closing the issue.

If you run into any other issues, consider following the instructions I linked to, but I'm glad you got it working.


(Comment originally posted by agentmorris)