-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* generalized depth module * update CLI options * setup save as validator * move comments into PR * put back to depth * fixes and flake8 * add depth tests * make detection indices a lsit * add cli tests * add docs * flake8 * fix save bug so overwrite works now; print out filepath csv not list of filepaths * fix bug where frame of zeros is wrong dimension; this happens when detection is at end of video * use noqa * first pass at code review comments * make parent directories and always include distance col even if null * add docs intro sentence * expose num_workers * expose gpu * use duplicated * remove log as this is just for calculating train metrics * change order around * cleanup; add gpu validation * fix typo * add comma * clean up transforms * remove unused code * fix docstring * set order explicitly * couple homepage updates * add section to homepage on depth * tweaks * tweak * add window order to det frame number * expose DepthDataset * flake8 * remove extra code * fix test * check values on real pred * round * use gpus if available * make tests more flexible to support various ffmpeg versions * round to 1 decimal place * avoid a copy * account for os differences * reflect rounding * alphabetize * use v3 as v1 is deprecated * normalize in get_item; conserve memory * lint * add note about memory * working tweak
- Loading branch information
Showing
19 changed files
with
859 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# zamba.models.depth_estimation.config | ||
|
||
::: zamba.models.depth_estimation.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# zamba.models.depth_estimation.depth_manager | ||
|
||
::: zamba.models.depth_estimation.depth_manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Depth estimation | ||
|
||
## Background | ||
|
||
Our depth estimation model is useful for predicting the distance an animal is from the camera, which is an input into models used to estimate animal abundance. | ||
|
||
The depth model comes from one of the winners of the [Deep Chimpact: Depth Estimation for Wildlife Conservation](https://www.drivendata.org/competitions/82/competition-wildlife-video-depth-estimation/) machine learning challenge hosted by DrivenData. The goal of this challenge was to use machine learning and advances in monocular (single-lens) depth estimation techniques to automatically estimate the distance between a camera trap and an animal contained in its video footage. The challenge drew on a unique labeled dataset from research teams from the Max Planck Institute for Evolutionary Anthropology (MPI-EVA) and the Wild Chimpanzee Foundation (WCF). | ||
|
||
The Zamba package supports running the depth estimation model on videos. Under the hood, it does the following: | ||
|
||
- Resamples the video to one frame per second | ||
- Runs the [MegadetectorLite](../models/species-detection.md#megadetectorlite) model on each frame to find frames with animals in them | ||
- Estimates depth for each detected animal in the frame | ||
- Outputs a csv with predictions | ||
|
||
## Output format | ||
|
||
The output of the depth estimation model is a csv with the following columns: | ||
|
||
- `filepath`: video name | ||
- `time`: seconds from the start of the video | ||
- `distance`: distance between detected animal and the camera | ||
|
||
There will be multiple rows per timestamp if there are multiple animals detected in the frame. If there is no animal in the frame, the distance will be null. | ||
|
||
For example, the first few rows of the `depth_predictions.csv` might look like this: | ||
|
||
``` | ||
filepath,time,distance | ||
video_1.avi,0,7.4 | ||
video_1.avi,0,7.4 | ||
video_1.avi,1, | ||
video_1.avi,2, | ||
video_1.avi,3, | ||
``` | ||
|
||
## Installation | ||
|
||
The depth estimation is included by default. If you've already [installed zamba](/docs/install/), there's nothing more you need to do. | ||
|
||
## Running depth estimation | ||
|
||
Here's how to run the depth estimation model. | ||
|
||
=== "CLI" | ||
```bash | ||
# output a csv with depth predictions for each frame in the videos in PATH_TO_VIDEOS | ||
zamba depth --data-dir PATH_TO_VIDEOS | ||
``` | ||
=== "Python" | ||
```python | ||
from zamba.models.depth_estimation import DepthEstimationConfig | ||
depth_conf = DepthEstimationConfig(data_dir="PATH_TO_VIDEOS") | ||
depth_conf.run_model() | ||
``` | ||
|
||
### Debugging | ||
|
||
Unlike in the species classification models, selected frames are stored in memory rather than cached to disk. If you run out of memory, try predicting on a smaller number of videos. If you hit a GPU memory error, try reducing the [number of workers](../../debugging/#reducing-num_workers) or the [batch size](../../debugging/#reducing-the-batch-size). | ||
|
||
## Getting help | ||
|
||
To see all of the available options, run `zamba depth --help`. | ||
|
||
```console | ||
$ zamba depth --help | ||
|
||
Usage: zamba depth [OPTIONS] | ||
|
||
Estimate animal distance at each second in the video. | ||
|
||
╭─ Options ─────────────────────────────────────────────────────────────────────────────────╮ | ||
│ --filepaths PATH Path to csv containing `filepath` column │ | ||
│ with videos. │ | ||
│ [default: None] │ | ||
│ --data-dir PATH Path to folder containing videos. │ | ||
│ [default: None] │ | ||
│ --save-to PATH An optional directory or csv path for │ | ||
│ saving the output. Defaults to │ | ||
│ `depth_predictions.csv` in the working │ | ||
│ directory. │ | ||
│ [default: None] │ | ||
│ --overwrite -o Overwrite output csv if it exists. │ | ||
│ --batch-size INTEGER Batch size to use for inference. │ | ||
│ [default: None] │ | ||
│ --num-workers INTEGER Number of subprocesses to use for data │ | ||
│ loading. │ | ||
│ [default: None] │ | ||
│ --gpus INTEGER Number of GPUs to use for inference. If │ | ||
│ not specifiied, will use all GPUs found │ | ||
│ on machine. │ | ||
│ [default: None] │ | ||
│ --model-cache-dir PATH Path to directory for downloading model │ | ||
│ weights. Alternatively, specify with │ | ||
│ environment variable `MODEL_CACHE_DIR`. │ | ||
│ If not specified, user's cache directory │ | ||
│ is used. │ | ||
│ [default: None] │ | ||
│ --weight-download-region [us|eu|asia] Server region for downloading weights. │ | ||
│ [default: None] │ | ||
│ --yes -y Skip confirmation of configuration and │ | ||
│ proceed right to prediction. │ | ||
│ --help Show this message and exit. │ | ||
╰───────────────────────────────────────────────────────────────────────────────────────────╯ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.