Skip to main content

MegaDetector

This package is a pip-installable version of the support/inference code for MegaDetector, an object detection model that helps conservation biologists spend less time doing boring things with camera trap images. Complete documentation for this Python package is available at megadetector.readthedocs.io.

If you aren't looking for the Python package specifically, and you just want to learn more about what MegaDetector is all about, head over to the MegaDetector repo.

If you don't want to run MegaDetector, and you just want to use the utilities in this package - postprocessing, manipulating large volumes of camera trap images, etc. - you may want to check out the megadetector-utils package, which is identical to this one, but excludes all of the PyTorch/YOLO dependencies, and is thus approximately one zillion times smaller.

Installation

Install with:

pip install megadetector

MegaDetector model weights aren't downloaded at the time you install the package, but they will be (optionally) automatically downloaded the first time you run the model.

Package reference

See megadetector.readthedocs.io.

Examples of things you can do with this package

Run MegaDetector on one image and count the number of detections

from megadetector.utils import url_utils
from megadetector.visualization import visualization_utils as vis_utils
from megadetector.detection import run_detector

# This is the image at the bottom of this page, it has one animal in it
image_url = 'https://github.com/agentmorris/MegaDetector/raw/main/images/orinoquia-thumb-web.jpg'
temporary_filename = url_utils.download_url(image_url)

image = vis_utils.load_image(temporary_filename)

# This will automatically download MDv5a; you can also specify a filename.
model = run_detector.load_detector('MDV5A')

result = model.generate_detections_one_image(image)

detections_above_threshold = [d for d in result['detections'] if d['conf'] > 0.2]
print('Found {} detections above threshold'.format(len(detections_above_threshold)))

Run MegaDetector on a folder of images

from megadetector.detection.run_detector_batch import \
    load_and_run_detector_batch, write_results_to_file

# Choose a folder to run MD on recursively, and an output file
image_folder = '/path/to/megadetector_test_images'
output_file = '/path/to/output/file.json'

# The package will automatically download whichever model you request; you 
# can also specify a filename.
model_name = 'MDV5A'

# Run the model on all images in the folder
results = load_and_run_detector_batch(model_name, image_folder)

# Write results to a format that Timelapse and other downstream tools like
write_results_to_file(results,
                      output_file,
                      relative_path_base=image_folder,
                      detector_file=model_name)

Contact

Contact cameratraps@lila.science with questions.

Gratuitous animal picture


Image credit University of Minnesota, from the Orinoquía Camera Traps data set.

Metadata

Release files for megadetector 10.0.27

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for megadetector 10.0.27
File Size Uploaded
megadetector-10.0.27.tar.gz 686.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for megadetector 10.0.27
File Interpreter ABI Platform
megadetector-10.0.27-py3-none-any.whl Python 3 none any Details

Total release size: 1.5 MB

Release files / megadetector-10.0.27.tar.gz

Download URL megadetector-10.0.27.tar.gz
Size 686.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dd70d7fd590d69c026dbecea4c8023765e05449a3939d1c59aa41e5c05493668
BLAKE2b-256 checksum
How to use checksums
8750a868e3060cb8beacb95b1e72b027aa17812fc8410b3e0c282ef51c8937ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / megadetector-10.0.27-py3-none-any.whl

Download URL megadetector-10.0.27-py3-none-any.whl
Size 764.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2d373150ca7e285aeee6e136e1f2b33a0fd17a4ed2c299410435843efdb58d2
BLAKE2b-256 checksum
How to use checksums
a91ec38ab6ddaa29cf4244e78dca5126f562c1a1b02faaa8c2fd450bacef6655
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

10.0.27 This release

2 release files

10.0.9

2 release files

10.0.7

2 release files

10.0.6

2 release files

10.0.5

2 release files

10.0.4

2 release files

10.0.3

2 release files

10.0.2

2 release files

10.0.1

2 release files

5.0.27

2 release files

5.0.26

2 release files

5.0.24

2 release files

5.0.23

2 release files

5.0.19

2 release files

5.0.18

2 release files

5.0.17

2 release files

5.0.16

2 release files

5.0.15

2 release files

5.0.14

2 release files

5.0.9

2 release files

5.0.8

2 release files

5.0.7

2 release files

5.0.6

2 release files

5.0.5

2 release files

5.0.4

2 release files

5.0.3

2 release files

5.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page