animl-lite 3.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Conservation Technology Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,204 @@
1
+ Metadata-Version: 2.4
2
+ Name: animl-lite
3
+ Version: 3.1.0
4
+ Summary: Tools for classifying camera trap images
5
+ Author-email: Kyra Swanson <tswanson@sdzwa.org>
6
+ Project-URL: Homepage, https://github.com/conservationtechlab/animl-py
7
+ Keywords: camera trap,ecology,conservation,zoo,SDZWA,conservationtechlab
8
+ Requires-Python: >=3.12
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: numpy>=2.0.2
12
+ Requires-Dist: onnxruntime-gpu>=1.23.2
13
+ Requires-Dist: pandas>=2.2.2
14
+ Requires-Dist: pillow>=11.0.0
15
+ Requires-Dist: pyyaml>=6.0.3
16
+ Requires-Dist: opencv-python>=4.12.0.88
17
+ Requires-Dist: tqdm>=4.66.5
18
+ Dynamic: license-file
19
+
20
+ # animl-py
21
+ AniML comprises a variety of machine learning tools for analyzing ecological data. This Python package includes a set of functions to classify subjects within camera trap field data and can handle both images and videos.
22
+ This package is also available in R: [animl](https://github.com/conservationtechlab/animl)
23
+
24
+ Table of Contents
25
+ 1. Installation
26
+ 2. [Usage](#usage)
27
+ 3. [Models](#models)
28
+
29
+ ## Installation Instructions
30
+
31
+ It is recommended that you set up a conda environment for using animl.
32
+ See **Dependencies** below for more detail. You will have to activate the conda environment first each
33
+ time you want to run AniML from a new terminal.
34
+
35
+ ### From GitHub
36
+ ```
37
+ git clone https://github.com/conservationtechlab/animl-py.git
38
+ cd animl-py
39
+ pip install -e .
40
+ ```
41
+
42
+ ### From PyPi
43
+ ```
44
+ pip install animl
45
+ ```
46
+
47
+ ### Dependencies
48
+ We recommend running AniML on GPU-enabled hardware.
49
+ **If using an NVIDIA GPU, ensure driviers, cuda-toolkit and cudnn are installed.
50
+
51
+ **Python** >= 3.9
52
+
53
+ **Onnx** <br>
54
+ Animl currently depends on onnxruntime-gpu >= 1.23.2.
55
+
56
+ Python Package Dependencies
57
+ * numpy>=2.0.2
58
+ * onnxruntime-gpu>=1.23.2
59
+ * pandas>=2.2.2
60
+ * pillow>=11.0.0
61
+ * opencv-python>=4.12.0.88
62
+ * tqdm>=4.66.5
63
+
64
+
65
+ ### Verify Install
66
+ We recommend you download the [examples](https://github.com/conservationtechlab/animl-py/blob/main/examples/Southwest.zip) folder within this repository.
67
+ Download and unarchive the zip folder. Then with the conda environment active:
68
+ ```
69
+ python -m animl /path/to/example/folder
70
+ ```
71
+ This should create an Animl-Directory subfolder within
72
+ the example folder.
73
+
74
+ Or, if using your own data/models, animl can be given the paths to those files:
75
+ Download and unarchive the zip folder. Then with the conda environment active:
76
+ ```
77
+ python -m animl /example/folder --detector /path/to/megadetector --classifier /path/to/classifier --classlist /path/to/classlist.txt
78
+ ```
79
+ You can use animl in this fashion on any image directory.
80
+
81
+ Finally you can use the animl.yml config file to specify parameters:
82
+ ```
83
+ python -m animl /path/to/animl.yml
84
+ ```
85
+
86
+ ## Usage
87
+
88
+ ### Inference
89
+ The functionality of animl can be parcelated into its individual functions to suit your data and scripting needs.
90
+ The sandbox.ipynb notebook has all of these steps available for further exploration.
91
+
92
+ 1. It is recommended that you use the animl working directory for storing intermediate steps.
93
+ ```python
94
+ import animl
95
+ workingdir = animl.WorkingDirectory('/path/to/save/data')
96
+ ```
97
+
98
+ 2. Build the file manifest of your given directory. This will find both images and videos.
99
+ ```python
100
+ files = animl.build_file_manifest('/path/to/images', out_file=workingdir.filemanifest, exif=True)
101
+ ```
102
+
103
+ 3. If there are videos, extract individual frames for processing.
104
+ Select either the number of frames or fps using the argumments.
105
+ The other option can be set to None or removed.
106
+ ```python
107
+ allframes = animl.extract_frames(files, out_dir=workingdir.vidfdir, out_file=workingdir.imageframes,
108
+ parallel=True, frames=3, fps=None)
109
+ ```
110
+
111
+ 4. Pass all images into MegaDetector. We recommend [MDv5a](https://github.com/agentmorris/MegaDetector/releases/download/v5.0/md_v5a.0.0.pt).
112
+ The function parse_MD will convert the json to a pandas DataFrame and merge detections with the original file manifest, if provided.
113
+
114
+ ```python
115
+ detector = animl.load_detector('/path/to/mdmodel.pt', model_type="MDV5", device='cuda:0')
116
+ mdresults = animl.detect(detector, allframes, resize_width=animl.MEGADETECTORv5_SIZE, resize_height=animl.MEGADETECTORv5_SIZE,
117
+ letterbox=True, file_col="frame", checkpoint_path=working_dir.mdraw, quiet=True)
118
+ detections = animl.parse_detections(mdresults, manifest=all_frames, out_file=workingdir.detections)
119
+ ```
120
+
121
+ 5. For speed and efficiency, extract the empty/human/vehicle detections before classification.
122
+ ```python
123
+ animals = animl.get_animals(detections)
124
+ empty = animl.get_empty(detections)
125
+ ```
126
+ 6. Classify using the appropriate species model. Merge the output with the rest of the detections
127
+ if desired.
128
+ ```python
129
+ class_list = animl.load_class_list('/path/to/classlist.txt')
130
+ classifier = animl.load_classifier('/path/to/model', len(class_list), device='cuda:0')
131
+ raw_predictions = animl.classify(classifier, animals, resize_width=480, resize_height=480,
132
+ file_col="frame", batch_size=4, out_file=working_dir.predictions)
133
+ ```
134
+
135
+ 7. Apply labels from class list with or without utilizing timestamp-based sequences.
136
+ ```python
137
+ manifest = animl.single_classification(animals, empty, raw_predictions, class_list['class'])
138
+
139
+ ```
140
+ or
141
+ ```python
142
+ manifest = animl.sequence_classification(animals, empty,
143
+ raw_predictions,
144
+ class_list['class'],
145
+ station_col='station',
146
+ empty_class="",
147
+ sort_columns=None,
148
+ file_col="filepath",
149
+ maxdiff=60)
150
+ ```
151
+
152
+ 8. (OPTIONAL) Save the Pandas DataFrame's required columns to csv and then use it to create json for TimeLapse compatibility
153
+ ```python
154
+ csv_loc = animl.export_timelapse(animals, empty, imagedir, only_animal = True)
155
+ animl.export_megadetector(csv_loc, imagedir + "final_result.json")
156
+ ```
157
+
158
+ 9. (OPTIONAL) Create symlinks within a given directory for file browser access.
159
+ ```python
160
+ manifest = animl.export_folders(manifest, out_dir=working_dir.linkdir, out_file=working_dir.results)
161
+ ```
162
+
163
+ ---
164
+ ### Training
165
+
166
+ Training workflows are still under development. Please submit Issues as you come upon them.
167
+
168
+ 1. Assuming a file manifest of training data with species labels, first split the data into training, validation and test splits.
169
+ This function splits each label proportionally by the given percentages, by default 0.7 training, 0.2 validation, 0.1 Test.
170
+ ```python
171
+ train, val, test, stats = animl.train_val_test(manifest, out_dir='path/to/save/data/', label_col="species",
172
+ percentage=(0.7, 0.2, 0.1), seed=None)
173
+ ```
174
+
175
+ 2. Set up training configuration file. Specify the paths to the data splits from the previous step. See [config README]()
176
+
177
+ 3. (Optional) Update train.py to include MLOPS connection.
178
+
179
+ 4. Using the config file, begin training
180
+ ```bash
181
+ python -m animl.train --config /path/to/config.yaml
182
+ ```
183
+ Every 10 epochs (or define custom 'checkpoint_frequency'), the model will be checkpointed to the 'experiment_folder' parameter in the config file, and will contain performance metrics for selection.
184
+
185
+
186
+ 5. Testing of a model checkpoint can be done with the "test.py" module. Add an 'active_model' parameter to the config file that contains the path of the checkpoint to test.
187
+ This will produce a confusion matrix of the test dataset as well as a csv containing predicted and ground truth labels for each image.
188
+ ```bash
189
+ python -m animl.test --config /path/to/config.yaml
190
+ ```
191
+
192
+ # Models
193
+
194
+ The Conservation Technology Lab has several models available for use.
195
+ You can use the download function within animl or access them here:
196
+ ```python
197
+ animl.download_model(animl.CLASSIFIER['SDZWA_Andes_v1'], out_dir: str = 'models/')
198
+ ```
199
+
200
+ * Southwest United States [v3](https://sandiegozoo.box.com/s/0mait8k3san3jvet8251mpz8svqyjnc3)
201
+ * [Amazon](https://sandiegozoo.box.com/s/dfc3ozdslku1ekahvz635kjloaaeopfl)
202
+ * [Savannah](https://sandiegozoo.box.com/s/ai6yu45jgvc0to41xzd26moqh8amb4vw)
203
+ * [Andes](https://sandiegozoo.box.com/s/kvg89qh5xcg1m9hqbbvftw1zd05uwm07)
204
+ * [MegaDetector](https://github.com/agentmorris/MegaDetector/releases/download/v5.0/md_v5a.0.0.pt)
@@ -0,0 +1,185 @@
1
+ # animl-py
2
+ AniML comprises a variety of machine learning tools for analyzing ecological data. This Python package includes a set of functions to classify subjects within camera trap field data and can handle both images and videos.
3
+ This package is also available in R: [animl](https://github.com/conservationtechlab/animl)
4
+
5
+ Table of Contents
6
+ 1. Installation
7
+ 2. [Usage](#usage)
8
+ 3. [Models](#models)
9
+
10
+ ## Installation Instructions
11
+
12
+ It is recommended that you set up a conda environment for using animl.
13
+ See **Dependencies** below for more detail. You will have to activate the conda environment first each
14
+ time you want to run AniML from a new terminal.
15
+
16
+ ### From GitHub
17
+ ```
18
+ git clone https://github.com/conservationtechlab/animl-py.git
19
+ cd animl-py
20
+ pip install -e .
21
+ ```
22
+
23
+ ### From PyPi
24
+ ```
25
+ pip install animl
26
+ ```
27
+
28
+ ### Dependencies
29
+ We recommend running AniML on GPU-enabled hardware.
30
+ **If using an NVIDIA GPU, ensure driviers, cuda-toolkit and cudnn are installed.
31
+
32
+ **Python** >= 3.9
33
+
34
+ **Onnx** <br>
35
+ Animl currently depends on onnxruntime-gpu >= 1.23.2.
36
+
37
+ Python Package Dependencies
38
+ * numpy>=2.0.2
39
+ * onnxruntime-gpu>=1.23.2
40
+ * pandas>=2.2.2
41
+ * pillow>=11.0.0
42
+ * opencv-python>=4.12.0.88
43
+ * tqdm>=4.66.5
44
+
45
+
46
+ ### Verify Install
47
+ We recommend you download the [examples](https://github.com/conservationtechlab/animl-py/blob/main/examples/Southwest.zip) folder within this repository.
48
+ Download and unarchive the zip folder. Then with the conda environment active:
49
+ ```
50
+ python -m animl /path/to/example/folder
51
+ ```
52
+ This should create an Animl-Directory subfolder within
53
+ the example folder.
54
+
55
+ Or, if using your own data/models, animl can be given the paths to those files:
56
+ Download and unarchive the zip folder. Then with the conda environment active:
57
+ ```
58
+ python -m animl /example/folder --detector /path/to/megadetector --classifier /path/to/classifier --classlist /path/to/classlist.txt
59
+ ```
60
+ You can use animl in this fashion on any image directory.
61
+
62
+ Finally you can use the animl.yml config file to specify parameters:
63
+ ```
64
+ python -m animl /path/to/animl.yml
65
+ ```
66
+
67
+ ## Usage
68
+
69
+ ### Inference
70
+ The functionality of animl can be parcelated into its individual functions to suit your data and scripting needs.
71
+ The sandbox.ipynb notebook has all of these steps available for further exploration.
72
+
73
+ 1. It is recommended that you use the animl working directory for storing intermediate steps.
74
+ ```python
75
+ import animl
76
+ workingdir = animl.WorkingDirectory('/path/to/save/data')
77
+ ```
78
+
79
+ 2. Build the file manifest of your given directory. This will find both images and videos.
80
+ ```python
81
+ files = animl.build_file_manifest('/path/to/images', out_file=workingdir.filemanifest, exif=True)
82
+ ```
83
+
84
+ 3. If there are videos, extract individual frames for processing.
85
+ Select either the number of frames or fps using the argumments.
86
+ The other option can be set to None or removed.
87
+ ```python
88
+ allframes = animl.extract_frames(files, out_dir=workingdir.vidfdir, out_file=workingdir.imageframes,
89
+ parallel=True, frames=3, fps=None)
90
+ ```
91
+
92
+ 4. Pass all images into MegaDetector. We recommend [MDv5a](https://github.com/agentmorris/MegaDetector/releases/download/v5.0/md_v5a.0.0.pt).
93
+ The function parse_MD will convert the json to a pandas DataFrame and merge detections with the original file manifest, if provided.
94
+
95
+ ```python
96
+ detector = animl.load_detector('/path/to/mdmodel.pt', model_type="MDV5", device='cuda:0')
97
+ mdresults = animl.detect(detector, allframes, resize_width=animl.MEGADETECTORv5_SIZE, resize_height=animl.MEGADETECTORv5_SIZE,
98
+ letterbox=True, file_col="frame", checkpoint_path=working_dir.mdraw, quiet=True)
99
+ detections = animl.parse_detections(mdresults, manifest=all_frames, out_file=workingdir.detections)
100
+ ```
101
+
102
+ 5. For speed and efficiency, extract the empty/human/vehicle detections before classification.
103
+ ```python
104
+ animals = animl.get_animals(detections)
105
+ empty = animl.get_empty(detections)
106
+ ```
107
+ 6. Classify using the appropriate species model. Merge the output with the rest of the detections
108
+ if desired.
109
+ ```python
110
+ class_list = animl.load_class_list('/path/to/classlist.txt')
111
+ classifier = animl.load_classifier('/path/to/model', len(class_list), device='cuda:0')
112
+ raw_predictions = animl.classify(classifier, animals, resize_width=480, resize_height=480,
113
+ file_col="frame", batch_size=4, out_file=working_dir.predictions)
114
+ ```
115
+
116
+ 7. Apply labels from class list with or without utilizing timestamp-based sequences.
117
+ ```python
118
+ manifest = animl.single_classification(animals, empty, raw_predictions, class_list['class'])
119
+
120
+ ```
121
+ or
122
+ ```python
123
+ manifest = animl.sequence_classification(animals, empty,
124
+ raw_predictions,
125
+ class_list['class'],
126
+ station_col='station',
127
+ empty_class="",
128
+ sort_columns=None,
129
+ file_col="filepath",
130
+ maxdiff=60)
131
+ ```
132
+
133
+ 8. (OPTIONAL) Save the Pandas DataFrame's required columns to csv and then use it to create json for TimeLapse compatibility
134
+ ```python
135
+ csv_loc = animl.export_timelapse(animals, empty, imagedir, only_animal = True)
136
+ animl.export_megadetector(csv_loc, imagedir + "final_result.json")
137
+ ```
138
+
139
+ 9. (OPTIONAL) Create symlinks within a given directory for file browser access.
140
+ ```python
141
+ manifest = animl.export_folders(manifest, out_dir=working_dir.linkdir, out_file=working_dir.results)
142
+ ```
143
+
144
+ ---
145
+ ### Training
146
+
147
+ Training workflows are still under development. Please submit Issues as you come upon them.
148
+
149
+ 1. Assuming a file manifest of training data with species labels, first split the data into training, validation and test splits.
150
+ This function splits each label proportionally by the given percentages, by default 0.7 training, 0.2 validation, 0.1 Test.
151
+ ```python
152
+ train, val, test, stats = animl.train_val_test(manifest, out_dir='path/to/save/data/', label_col="species",
153
+ percentage=(0.7, 0.2, 0.1), seed=None)
154
+ ```
155
+
156
+ 2. Set up training configuration file. Specify the paths to the data splits from the previous step. See [config README]()
157
+
158
+ 3. (Optional) Update train.py to include MLOPS connection.
159
+
160
+ 4. Using the config file, begin training
161
+ ```bash
162
+ python -m animl.train --config /path/to/config.yaml
163
+ ```
164
+ Every 10 epochs (or define custom 'checkpoint_frequency'), the model will be checkpointed to the 'experiment_folder' parameter in the config file, and will contain performance metrics for selection.
165
+
166
+
167
+ 5. Testing of a model checkpoint can be done with the "test.py" module. Add an 'active_model' parameter to the config file that contains the path of the checkpoint to test.
168
+ This will produce a confusion matrix of the test dataset as well as a csv containing predicted and ground truth labels for each image.
169
+ ```bash
170
+ python -m animl.test --config /path/to/config.yaml
171
+ ```
172
+
173
+ # Models
174
+
175
+ The Conservation Technology Lab has several models available for use.
176
+ You can use the download function within animl or access them here:
177
+ ```python
178
+ animl.download_model(animl.CLASSIFIER['SDZWA_Andes_v1'], out_dir: str = 'models/')
179
+ ```
180
+
181
+ * Southwest United States [v3](https://sandiegozoo.box.com/s/0mait8k3san3jvet8251mpz8svqyjnc3)
182
+ * [Amazon](https://sandiegozoo.box.com/s/dfc3ozdslku1ekahvz635kjloaaeopfl)
183
+ * [Savannah](https://sandiegozoo.box.com/s/ai6yu45jgvc0to41xzd26moqh8amb4vw)
184
+ * [Andes](https://sandiegozoo.box.com/s/kvg89qh5xcg1m9hqbbvftw1zd05uwm07)
185
+ * [MegaDetector](https://github.com/agentmorris/MegaDetector/releases/download/v5.0/md_v5a.0.0.pt)
@@ -0,0 +1,43 @@
1
+ [project]
2
+ name = "animl-lite"
3
+ version = "3.1.0"
4
+ description = "Tools for classifying camera trap images"
5
+
6
+ readme = "README.md"
7
+ license = {file = "LICENSE.txt"}
8
+ keywords = ["camera trap", "ecology", "conservation", "zoo", "SDZWA", "conservationtechlab"]
9
+
10
+ authors = [{name = "Kyra Swanson", email = "tswanson@sdzwa.org" }]
11
+
12
+ requires-python = ">=3.12"
13
+ dependencies = [
14
+ "numpy>=2.0.2",
15
+ "onnxruntime-gpu>=1.23.2",
16
+ "pandas>=2.2.2",
17
+ "pillow>=11.0.0",
18
+ "pyyaml>=6.0.3",
19
+ "opencv-python>=4.12.0.88",
20
+ "tqdm>=4.66.5",
21
+ ]
22
+
23
+ [project.urls] # Optional
24
+ "Homepage" = "https://github.com/conservationtechlab/animl-py"
25
+
26
+
27
+ # The following would provide a command line executable called `sample`
28
+ # which executes the function `main` from this package when invoked.
29
+ #[project.scripts] # Optional
30
+ #sample = "sample:main"
31
+
32
+ # This is configuration specific to the `setuptools` build backend.
33
+ # If you are using a different build backend, you will need to change this.
34
+ #[tool.setuptools]
35
+ # If there are data files included in your packages that need to be
36
+ # installed, specify them here.
37
+ #package-data = {"sample" = ["*.dat"]}
38
+
39
+ [build-system]
40
+ # These are the assumed default build requirements from pip:
41
+ # https://pip.pypa.io/en/stable/reference/pip/#pep-517-and-518-support
42
+ requires = ["setuptools>=42"]
43
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,68 @@
1
+ __version__ = '3.1.0'
2
+ from animl import classification
3
+ from animl import detection
4
+ from animl import export
5
+ from animl import file_management
6
+ from animl import generator
7
+ from animl import pipeline
8
+ from animl import reid
9
+ from animl import split
10
+ from animl import utils
11
+ from animl import video_processing
12
+
13
+ from animl.classification import (SDZWA_CLASSIFIER_SIZE, classify,
14
+ load_class_list, load_classifier,
15
+ sequence_classification,
16
+ single_classification,)
17
+ from animl.detection import (MEGADETECTORv5_SIZE, convert_onnx_detections,
18
+ detect, load_detector, parse_detections,)
19
+ from animl.export import (export_coco, export_folders, export_megadetector,
20
+ export_timelapse, remove_link,
21
+ update_labels_from_folders,)
22
+ from animl.file_management import (IMAGE_EXTENSIONS, VALID_EXTENSIONS,
23
+ VIDEO_EXTENSIONS, WorkingDirectory,
24
+ active_times, build_file_manifest,
25
+ check_file, load_data, load_json, save_data,
26
+ save_detection_checkpoint, save_json,)
27
+ from animl.generator import (Letterbox, ManifestGenerator, Normalize,
28
+ manifest_dataloader, pil_to_numpy_array,)
29
+ from animl.pipeline import (from_config, from_paths,)
30
+ from animl.reid import (compute_batched_distance_matrix,
31
+ compute_distance_matrix, cosine_distance, distance,
32
+ euclidean_squared_distance, extract_miew_embeddings,
33
+ inference, load_miew, remove_diagonal,)
34
+ from animl.split import (get_animals, get_empty, train_val_test,)
35
+ from animl.utils import (MD_COLORS, MD_LABELS, clip_coords,
36
+ convert_minxywh_to_absxyxy, general, get_device,
37
+ letterbox, normalize_boxes, plot_all_bounding_boxes,
38
+ plot_box, plot_from_file, scale_letterbox, softmax,
39
+ tensor_to_onnx, visualization, xyn2xy, xywh2xyxy,
40
+ xywhc2xyxy, xywhn2xyxy, xyxy2xywh, xyxyc2xywh,
41
+ xyxyc2xywhn,)
42
+ from animl.video_processing import (count_frames, extract_frames,
43
+ get_frame_as_image,)
44
+
45
+ __all__ = ['IMAGE_EXTENSIONS', 'Letterbox', 'MD_COLORS', 'MD_LABELS',
46
+ 'MEGADETECTORv5_SIZE', 'ManifestGenerator', 'Normalize',
47
+ 'SDZWA_CLASSIFIER_SIZE', 'VALID_EXTENSIONS', 'VIDEO_EXTENSIONS',
48
+ 'WorkingDirectory', 'active_times', 'build_file_manifest',
49
+ 'check_file', 'classification', 'classify', 'clip_coords',
50
+ 'compute_batched_distance_matrix', 'compute_distance_matrix',
51
+ 'convert_minxywh_to_absxyxy', 'convert_onnx_detections',
52
+ 'cosine_distance', 'count_frames', 'detect', 'detection',
53
+ 'distance', 'euclidean_squared_distance', 'export', 'export_coco',
54
+ 'export_folders', 'export_megadetector', 'export_timelapse',
55
+ 'extract_frames', 'extract_miew_embeddings', 'file_management',
56
+ 'from_config', 'from_paths', 'general', 'generator', 'get_animals',
57
+ 'get_device', 'get_empty', 'get_frame_as_image', 'inference',
58
+ 'letterbox', 'load_class_list', 'load_classifier', 'load_data',
59
+ 'load_detector', 'load_json', 'load_miew', 'manifest_dataloader',
60
+ 'normalize_boxes', 'parse_detections', 'pil_to_numpy_array',
61
+ 'pipeline', 'plot_all_bounding_boxes', 'plot_box', 'plot_from_file',
62
+ 'reid', 'remove_diagonal', 'remove_link', 'save_data',
63
+ 'save_detection_checkpoint', 'save_json', 'scale_letterbox',
64
+ 'sequence_classification', 'single_classification', 'softmax',
65
+ 'split', 'tensor_to_onnx', 'train_val_test',
66
+ 'update_labels_from_folders', 'utils', 'video_processing',
67
+ 'visualization', 'xyn2xy', 'xywh2xyxy', 'xywhc2xyxy', 'xywhn2xyxy',
68
+ 'xyxy2xywh', 'xyxyc2xywh', 'xyxyc2xywhn']
@@ -0,0 +1,70 @@
1
+ '''
2
+ Main script.
3
+
4
+ Runs full animl workflow on a given directory.
5
+ User must provide MegaDetector, Classifier, and Class list files,
6
+ otherwise will pull MDv5 and the CTL Southwest v2 models by default.
7
+
8
+ Usage example
9
+ > python -m animl /home/usr/animl-py/examples/Southwest/
10
+
11
+ OR
12
+
13
+ > python -m animl /image/dir megadetector.pt classifier.pt class_file.csv
14
+
15
+ Paths to model files must be edited to local machine.
16
+
17
+ @ Kyra Swanson, 2023
18
+ '''
19
+ import time
20
+ import argparse
21
+ from pathlib import Path
22
+
23
+ from animl import pipeline
24
+ import animl.models.download as models
25
+
26
+ # Start timer
27
+ start_time = time.time()
28
+
29
+ # IF RUN FROM COMMAND LINE
30
+ parser = argparse.ArgumentParser(description='Folder locations for the main script')
31
+ home = Path.cwd() / 'models'
32
+ # Create and parse arguements
33
+ parser.add_argument('imagedir_config', type=str,
34
+ help='Path to Image Directory or Config File')
35
+ parser.add_argument('--detector', type=str, nargs='?',
36
+ help='Path to MD model',
37
+ default=Path(home / 'md_v5a.0.0.pt'))
38
+ parser.add_argument('--classifier', type=str, nargs='?',
39
+ help='Path to Class model',
40
+ default=Path(home / 'sdzwa_southwest_v3.pt'))
41
+ parser.add_argument('--classlist', type=str, nargs='?',
42
+ help='Path to class list',
43
+ default=Path(home / 'sdzwa_southwest_v3_classes.csv'))
44
+ args = parser.parse_args()
45
+
46
+ # first argument is config file
47
+ if Path(args.imagedir_config).is_file():
48
+ pipeline.from_config(args.imagedir_config)
49
+
50
+ # first argument is a directory
51
+ else:
52
+ if not Path(args.detector).is_file():
53
+ prompt = "MegaDetector not found, would you like to download? y/n: "
54
+ if input(prompt).lower() == "y":
55
+ models.download_model(models.MEGADETECTOR['MDV5a'], out_dir=home)
56
+
57
+ if not Path(args.classifier).is_file():
58
+ prompt = "Classifier not found, would you like to download Southwest_v3? y/n: "
59
+ if input(prompt).lower() == "y":
60
+ models.download_model(models.CLASSIFIER['SDZWA_Southwest_v3'], out_dir=home)
61
+
62
+ if not Path(args.classlist).is_file():
63
+ prompt = "Class list not found, would you like to download Southwest_v3? y/n: "
64
+ if input(prompt).lower() == "y":
65
+ models.download_model(models.CLASS_LIST['SDZWA_Southwest_v3'], out_dir=home)
66
+
67
+ # Call the main function
68
+ pipeline.from_paths(args.imagedir_config, args.detector, args.classifier, args.classlist)
69
+
70
+ print(f"Pipeline took {time.time() - start_time:.2f} seconds")