Package: megadetector
MegaDetectorThis package is a pip-installable version of the support/inference code forMegaDetector, an object detection model that helps conservation biologists spend less time doing boring things with camera trap images.If you want to learn more about what MegaDetector is all about, head over to theMegaDetector repo.Reasons you probably aren't looking for this packageIf 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.  We recommend starting with our "Getting started with MegaDetector" page, then digging in to theMegaDetector User Guide, which will walk you through the process of using MegaDetector.  That journey willnotinvolve this package.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 still probably don't want this package.  MegaDetector is just a fine-tuned version ofYOLOv5, and theultralyticspackage (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 packageIf you want to programmatically interact with the postprocessing tools from the MegaDetector repo, or programmatically run MegaDetector in a way that producesTimelapse-friendly output (i.e., output in the standardMegaDetector output format), this package might be for you.Although even if that describes you, youstillmight be better off cloning the MegaDetector repo.  Pip-installability requires that some dependencies be newer than what was available at the time MDv5 was trained, so results arevery slightlydifferent than results produced in the "official" environment.  These differencesprobablydon't matter much, but they have not been formally characterized.If I haven't talked you out of using this package...To install:pip install megadetectorMegaDetector model weights aren't downloaded at pip-install time, but they will be (optionally) automatically downloaded the first time you run the model.Examples of things you can do with this packageRun MegaDetector on one image and count the number of detectionsfrom md_utils import url_utils
from md_visualization import visualization_utils as vis_utils
from 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 to the system temp folder;
# you can also specify a filename explicitly, or set the $MDV5A
# environment variable to point to the model file.
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 {} detection above threshold'.format(len(detections_above_threshold)))Run MegaDetector on a folder of imagesfrom detection.run_detector_batch import load_and_run_detector_batch,write_results_to_file
from md_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 to the system temp folder;
# you can also specify a filename explicitly, or set the $MDV5A
# environment variable to point to the model file.
results = load_and_run_detector_batch('MDV5A', image_file_names)

# Write results as relative filenames, this is what Timelapse
# and other downstream tools expect.
write_results_to_file(results,output_file,relative_path_base=image_folder)ContactContactcameratraps@lila.sciencewith questions.Gratuitous animal pictureImage credit University of Minnesota, from theOrinoquía Camera Trapsdata set.