{"id":30232140,"url":"https://github.com/agentmorris/camera-trap-vehicle-classifier","last_synced_at":"2025-08-14T23:10:02.623Z","repository":{"id":306310704,"uuid":"1017063683","full_name":"agentmorris/camera-trap-vehicle-classifier","owner":"agentmorris","description":"Classifier for vehicles cropped from camera trap images","archived":false,"fork":false,"pushed_at":"2025-08-03T00:04:06.000Z","size":907,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-03T02:25:00.581Z","etag":null,"topics":["camera-traps","image-classification","megadetector"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/agentmorris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-10T01:15:29.000Z","updated_at":"2025-08-03T00:04:09.000Z","dependencies_parsed_at":"2025-07-25T00:21:54.996Z","dependency_job_id":null,"html_url":"https://github.com/agentmorris/camera-trap-vehicle-classifier","commit_stats":null,"previous_names":["agentmorris/camera-trap-vehicle-classifier"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/agentmorris/camera-trap-vehicle-classifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentmorris%2Fcamera-trap-vehicle-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentmorris%2Fcamera-trap-vehicle-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentmorris%2Fcamera-trap-vehicle-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentmorris%2Fcamera-trap-vehicle-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agentmorris","download_url":"https://codeload.github.com/agentmorris/camera-trap-vehicle-classifier/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentmorris%2Fcamera-trap-vehicle-classifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270495133,"owners_count":24593908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["camera-traps","image-classification","megadetector"],"created_at":"2025-08-14T23:10:00.034Z","updated_at":"2025-08-14T23:10:02.610Z","avatar_url":"https://github.com/agentmorris.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Camera trap vehicle classifier\r\n\r\n## Background\r\n\r\nThe effects of human recreation on wildlife may vary depending on the type of road and trail use that is occurring (e.g. see [Naidoo and Burton, 2020](https://conbio.onlinelibrary.wiley.com/doi/full/10.1111/csp2.271)).  Classifying human and vehicle detections into finer sub-classes (e.g., car/truck, horseback rider, mountain biker) facilitates the study of how different types of recreational activities impact the distribution and abundance of wildlife. \r\n\r\n\r\n## Overview\r\n\r\nThis repo hosts the training and inference code for a PyTorch model that classifies vehicles cropped from camera trap images (typically cropped with [MegaDetector](https://github.com/agentmorris/MegaDetector)) into the following categories:\r\n\r\n* car/truck\r\n* motorbike\r\n* mountain bike\r\n* quad\r\n\r\nSample images are provided in the \u003ca href=\"#sample-images\"\u003esample images\u003c/a\u003e section below.\r\n\r\nThis classifier is typically used in an ensemble with [SpeciesNet](https://github.com/google/cameratrapai), which also allows us to identify domestic dogs and horses, which complements the picture of recreational area use provided by the vehicle classifications.\r\n\r\nThe current release is fine-tuned from the [timm/eva02_large_patch14_448.mim_m38m_ft_in22k_in1k](https://huggingface.co/timm/eva02_large_patch14_448.mim_m38m_ft_in22k_in1k) base model.\r\n\r\n\r\n## Training data overview\r\n\r\nThe training data for this model consists of ~200k vehicle crops extracted from ~300k images from 65 camera locations in British Columbia.  Training data was provided by [Robin Naidoo](https://www.worldwildlife.org/experts/robin-naidoo), World Wildlife Fund.\r\n\r\n\r\n## Downloading the model\r\n\r\nDownload the model zipfile from the [releases page](https://github.com/agentmorris/camera-trap-vehicle-classifier/releases) and extract locally.  It contains a checkpoint file (camera-trap-vehicle-classifier.2025.07.09.ckpt) and the class list file (classes.txt).\r\n\r\n\r\n## Preparing images\r\n\r\nThe inference script in this repo assumes that you have created a folder with cropped images; I typically do that with the [create_crop_folder](https://megadetector.readthedocs.io/en/latest/postprocessing.html#module-megadetector.postprocessing.create_crop_folder) module in the [MegaDetector Python package](https://pypi.org/project/megadetector/).\r\n\r\n\r\n## Setup\r\n\r\nClone the repo, e.g. to c:\\git\\camera-trap-vehicle-classifier:\r\n\r\n```bash\r\nmkdir c:\\git\r\ncd c:\\git\r\ngit clone https://github.com/agentmorris/camera-trap-vehicle-classifier\r\ncd camera-trap-vehicle-classifier\r\n```\r\n\r\nCreate a Python environment and install dependencies, e.g. with Anaconda:\r\n\r\n```bash\r\nconda create -n camera-trap-vehicle-classifier python=3.11 pip -y\r\nconda activate camera-trap-vehicle-classifier\r\npip install -r requirements.txt\r\n```\r\n\r\nIf you are on Windows and you have a GPU, you may have to also install the GPU version of PyTorch:\r\n\r\n`pip install torch torchvision --upgrade --force-reinstall --index-url https://download.pytorch.org/whl/cu118`\r\n\r\n\r\n## Running the classifier\r\n\r\n`python run_vehicle_classifier [checkpoint_path] [image_dir] --output [output_file] --classes [class_name_file]`\r\n\r\n...where:\r\n\r\n* `checkpoint_path` is the path to the .ckpt file you extracted from the zipfile\r\n* `image_dir` is your image folder (this will be processed recursively)\r\n* `output_file` is the .json file to which you want to write results\r\n* `class_name_file` is the location of the classes.txt file you extracted from the zipfile\r\n\r\n\r\n## Files in this repo\r\n\r\n### train_vehicle_classifier.py\r\n\r\nPyTorch Lightning script for fine-tuning vision models for vehicle classification.\r\n\r\nSupports timm and Hugging Face models.\r\n\r\nInput data is provided as:\r\n\r\n* A root image path\r\n* A COCO .json file containing relative filenames within that root path, with a \"split\" field in each\r\n  image set to either \"train\" or \"val.\r\n\r\n\r\n### train_vehicle_classifier_2025.07.02.py\r\n\r\nNotebook that drives train_vehicle_classifier to train the actual classifier.\r\n\r\nAlso:\r\n\r\n* Runs the classifier on the val crops and previews the results\r\n* Creates a val folder of whole images\r\n\r\n\r\n### run_vehicle_classifier.py\r\n\r\nInference script for PyTorch Lightning models trained with train_vehicle_classifier.py.\r\nRuns inference on a folder, producing a .json file in the MegaDetector batch output format\r\n(https://lila.science/megadetector-output-format).\r\n\r\nRelies on train_vehicle_classifier.py for core classes.\r\n\r\n\r\n## Sample images\r\n\r\nThese images are included here to capture the gestalt of what this classifier is trained on.  The classifier is trained only on the cropped vehicles, not on the entire images.  These are visualizations of the classifier output on the original images.  Image credit Robin Naidoo, World Wildlife Fund.\r\n\r\n### car/truck\r\n\r\n![](images/car_truck_00.jpg)\r\n![](images/car_truck_01.jpg)\r\n\r\n### motorbike\r\n\r\n![](images/motorbike_00.jpg)\r\n![](images/motorbike_01.jpg)\r\n\r\n### mountain bike\r\n\r\n![](images/mountain_biker_00.jpg)\r\n![](images/mountain_biker_01.jpg)\r\n\r\n### quad\r\n\r\n![](images/quad_00.jpg)\r\n![](images/quad_01.jpg)\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentmorris%2Fcamera-trap-vehicle-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagentmorris%2Fcamera-trap-vehicle-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentmorris%2Fcamera-trap-vehicle-classifier/lists"}