Skip to main content

MegaDetector is an AI model that helps conservation folks spend less time doing boring things with camera trap images.

Project description

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.

Reasons you might not be looking for this package

If you are an ecologist...

If you are an ecologist looking to use MegaDetector to help you get through your camera trap images, you probably don't want this package, or at least you probably don't want to start at this page. We recommend starting with our "Getting started with MegaDetector" page, then digging in to the MegaDetector User Guide, which will walk you through the process of using MegaDetector.

If you are a computer-vision-y type...

If you are a computer-vision-y person looking to run or fine-tune MegaDetector programmatically, you probably don't want this package. MegaDetector is just a fine-tuned version of YOLOv5, and the ultralytics package (from the developers of YOLOv5) has a zillion bells and whistles for both inference and fine-tuning that this package doesn't.

Reasons you might want to use this package

If you want to programmatically interact with the postprocessing tools from the MegaDetector repo, or programmatically run MegaDetector in a way that produces Timelapse-friendly output (i.e., output in the standard MegaDetector output format), this package might be for you.

If I haven't talked you out of using this package...

To install:

pip install megadetector

MegaDetector model weights aren't downloaded at pip-install time, 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
from megadetector.utils import path_utils
import os

# Pick a folder to run MD on recursively, and an output file
image_folder = os.path.expanduser('~/megadetector_test_images')
output_file = os.path.expanduser('~/megadetector_output_test.json')

# Recursively find images
image_file_names = path_utils.find_images(image_folder,recursive=True)

# This will automatically download MDv5a; you can also specify a filename.
results = load_and_run_detector_batch('MDV5A', image_file_names)

# 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=detector_filename)

Contact

Contact cameratraps@lila.science with questions.

Gratuitous animal picture


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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

megadetector-5.0.21.tar.gz (585.4 kB view details)

Uploaded Source

Built Distribution

megadetector-5.0.21-py3-none-any.whl (708.7 kB view details)

Uploaded Python 3

File details

Details for the file megadetector-5.0.21.tar.gz.

File metadata

  • Download URL: megadetector-5.0.21.tar.gz
  • Upload date:
  • Size: 585.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for megadetector-5.0.21.tar.gz
Algorithm Hash digest
SHA256 8f0f2a4debca6fc6e51f5cebdfe9f9f2d4f5378a1c94d6c8f83433188328c2d2
MD5 7a6d7c59ec68672bfed1c59b6e4fa85e
BLAKE2b-256 57ca2f74ca53a8bea44be9fb5f7432424150cff6b7e9562f1b953f5a122d48b3

See more details on using hashes here.

File details

Details for the file megadetector-5.0.21-py3-none-any.whl.

File metadata

File hashes

Hashes for megadetector-5.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 fdb7317eeddde993f9483b1d6ad84cf78f8255e1ca56429d8341c26f9de67cf6
MD5 9b78a19f9a60c3304b88cfff9da07040
BLAKE2b-256 1dd88950c28c91f17985b92d26b2bae66844b75c84382c51c0e5bd3b3536c81e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page