PytorchWildlife 1.0.2.11__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.
Files changed (30) hide show
  1. PytorchWildlife-1.0.2.11/LICENSE +21 -0
  2. PytorchWildlife-1.0.2.11/PKG-INFO +367 -0
  3. PytorchWildlife-1.0.2.11/PW_FT_classification/__init__.py +1 -0
  4. PytorchWildlife-1.0.2.11/PW_FT_classification/main.py +178 -0
  5. PytorchWildlife-1.0.2.11/PytorchWildlife/__init__.py +10 -0
  6. PytorchWildlife-1.0.2.11/PytorchWildlife/data/__init__.py +2 -0
  7. PytorchWildlife-1.0.2.11/PytorchWildlife/data/datasets.py +121 -0
  8. PytorchWildlife-1.0.2.11/PytorchWildlife/data/transforms.py +159 -0
  9. PytorchWildlife-1.0.2.11/PytorchWildlife/models/__init__.py +2 -0
  10. PytorchWildlife-1.0.2.11/PytorchWildlife/models/classification/__init__.py +1 -0
  11. PytorchWildlife-1.0.2.11/PytorchWildlife/models/classification/resnet/__init__.py +4 -0
  12. PytorchWildlife-1.0.2.11/PytorchWildlife/models/classification/resnet/amazon.py +105 -0
  13. PytorchWildlife-1.0.2.11/PytorchWildlife/models/classification/resnet/base_classifier.py +155 -0
  14. PytorchWildlife-1.0.2.11/PytorchWildlife/models/classification/resnet/opossum.py +70 -0
  15. PytorchWildlife-1.0.2.11/PytorchWildlife/models/classification/resnet/serengeti.py +79 -0
  16. PytorchWildlife-1.0.2.11/PytorchWildlife/models/detection/__init__.py +1 -0
  17. PytorchWildlife-1.0.2.11/PytorchWildlife/models/detection/yolov5/__init__.py +2 -0
  18. PytorchWildlife-1.0.2.11/PytorchWildlife/models/detection/yolov5/base_detector.py +169 -0
  19. PytorchWildlife-1.0.2.11/PytorchWildlife/models/detection/yolov5/megadetector.py +47 -0
  20. PytorchWildlife-1.0.2.11/PytorchWildlife/utils/__init__.py +2 -0
  21. PytorchWildlife-1.0.2.11/PytorchWildlife/utils/misc.py +53 -0
  22. PytorchWildlife-1.0.2.11/PytorchWildlife/utils/post_process.py +306 -0
  23. PytorchWildlife-1.0.2.11/PytorchWildlife.egg-info/PKG-INFO +367 -0
  24. PytorchWildlife-1.0.2.11/PytorchWildlife.egg-info/SOURCES.txt +28 -0
  25. PytorchWildlife-1.0.2.11/PytorchWildlife.egg-info/dependency_links.txt +1 -0
  26. PytorchWildlife-1.0.2.11/PytorchWildlife.egg-info/requires.txt +10 -0
  27. PytorchWildlife-1.0.2.11/PytorchWildlife.egg-info/top_level.txt +2 -0
  28. PytorchWildlife-1.0.2.11/README.md +336 -0
  29. PytorchWildlife-1.0.2.11/setup.cfg +4 -0
  30. PytorchWildlife-1.0.2.11/setup.py +40 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2023] [Microsoft]
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,367 @@
1
+ Metadata-Version: 2.1
2
+ Name: PytorchWildlife
3
+ Version: 1.0.2.11
4
+ Summary: a PyTorch Collaborative Deep Learning Framework for Conservation.
5
+ Home-page: https://github.com/microsoft/CameraTraps/
6
+ Author: Andres Hernandez, Zhongqi Miao
7
+ Author-email: v-herandres@microsoft.com, zhongqimiao@microsoft.com
8
+ License: MIT
9
+ Keywords: pytorch_wildlife,pytorch,wildlife,megadetector,conservation,animal,detection,classification
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.6
15
+ Classifier: Programming Language :: Python :: 3.7
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Requires-Python: >=3.8
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: numpy
22
+ Requires-Dist: torch==1.10.1
23
+ Requires-Dist: torchvision==0.11.2
24
+ Requires-Dist: torchaudio==0.10.1
25
+ Requires-Dist: tqdm==4.66.1
26
+ Requires-Dist: Pillow==10.1.0
27
+ Requires-Dist: supervision==0.16.0
28
+ Requires-Dist: gradio==4.8.0
29
+ Requires-Dist: ultralytics-yolov5
30
+ Requires-Dist: chardet
31
+
32
+ ![image](https://microsoft.github.io/CameraTraps/assets/Pytorch_Banner_transparentbk.png)
33
+
34
+ <div align="center">
35
+ <font size="6"> A Collaborative Deep Learning Framework for Conservation </font>
36
+ <br>
37
+ <hr>
38
+ <a href="https://pypi.org/project/PytorchWildlife"><img src="https://img.shields.io/pypi/v/PytorchWildlife?color=limegreen" /></a>
39
+ <a href="https://pypi.org/project/PytorchWildlife"><img src="https://static.pepy.tech/badge/pytorchwildlife" /></a>
40
+ <a href="https://pypi.org/project/PytorchWildlife"><img src="https://img.shields.io/pypi/pyversions/PytorchWildlife" /></a>
41
+ <a href="https://huggingface.co/spaces/ai4g-biodiversity/pytorch-wildlife"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Demo-blue" /></a>
42
+ <a href="https://colab.research.google.com/drive/1rjqHrTMzEHkMualr4vB55dQWCsCKMNXi?usp=sharing"><img src="https://img.shields.io/badge/Colab-Demo-blue?logo=GoogleColab" /></a>
43
+ <!-- <a href="https://colab.research.google.com/drive/16-OjFVQ6nopuP-gfqofYBBY00oIgbcr1?usp=sharing"><img src="https://img.shields.io/badge/Colab-Video detection-blue?logo=GoogleColab" /></a> -->
44
+ <a href="https://cameratraps.readthedocs.io/en/latest/"><img src="https://img.shields.io/badge/read-docs-yellow?logo=ReadtheDocs" /></a>
45
+ <a href="https://github.com/microsoft/CameraTraps/blob/main/LICENSE"><img src="https://img.shields.io/pypi/l/PytorchWildlife" /></a>
46
+ <a href="https://discord.gg/TeEVxzaYtm"><img src="https://img.shields.io/badge/any_text-Join_us!-blue?logo=discord&label=Discord" /></a>
47
+ <br><br>
48
+ </div>
49
+
50
+
51
+ ## ✅ Update highlights (Version 1.0.2.9)
52
+ - [x] 🥳 Added Timelapse compatibility! Check the [Gradio interface](INSTALLATION.md) or [notebooks](https://github.com/microsoft/CameraTraps/tree/main/demo).
53
+ - [x] Added Google Colab demos.
54
+ - [x] Added Snapshot Serengeti classification model into the model zoo.
55
+ - [x] Added Classification fine-tuning module.
56
+ - [x] Added a Docker Image for ease of installation.
57
+
58
+ ## 🔥 Future highlights
59
+ - [ ] MegaDetectorV6 with multiple model sizes for both optimized performance and low-budget devices like camera systems.
60
+ - [ ] A detection model fine-tuning module to fine-tune your own detection model for Pytorch-Wildlife.
61
+ - [ ] Direct LILA connection for more training/validation data.
62
+ - [ ] More pretrained detection and classification models to expand the current model zoo.
63
+
64
+ To check the full version of the roadmap with completed tasks and long term goals, please click [here!](roadmaps.md).
65
+
66
+ ## 🐾 Introduction
67
+
68
+ At the core of our mission is the desire to create a harmonious space where conservation scientists from all over the globe can unite. Where they're able to share, grow, use datasets and deep learning architectures for wildlife conservation.
69
+ We've been inspired by the potential and capabilities of Megadetector, and we deeply value its contributions to the community. As we forge ahead with Pytorch-Wildlife, under which Megadetector now resides, please know that we remain committed to supporting, maintaining, and developing Megadetector, ensuring its continued relevance, expansion, and utility.
70
+
71
+ Pytorch-Wildlife is pip installable:
72
+ ```
73
+ pip install PytorchWildlife
74
+ ```
75
+
76
+ To use the newest version of MegaDetector with all the existing functionalities, you can use our [Hugging Face interface](https://huggingface.co/spaces/AndresHdzC/pytorch-wildlife) or simply load the model with **Pytorch-Wildlife**. The weights will be automatically downloaded:
77
+ ```python
78
+ from PytorchWildlife.models import detection as pw_detection
79
+ detection_model = pw_detection.MegaDetectorV5()
80
+ ```
81
+
82
+ For those interested in accessing the previous MegaDetector repository, which utilizes the same `MegaDetector v5` model weights and was primarily developed by Dan Morris during his time at Microsoft, please visit the [archive](https://github.com/microsoft/CameraTraps/blob/main/archive) directory, or you can visit this [forked repository](https://github.com/agentmorris/MegaDetector/tree/main) that Dan Morris is actively maintaining.
83
+
84
+ >[!TIP]
85
+ >If you have any questions regarding MegaDetector and Pytorch-Wildlife, please [email us](zhongqimiao@microsoft.com) or join us in our discord channel: [![](https://img.shields.io/badge/any_text-Join_us!-blue?logo=discord&label=PytorchWildife)](https://discord.gg/TeEVxzaYtm)
86
+
87
+ ## 👋 Welcome to Pytorch-Wildlife Version 1.0
88
+
89
+ **PyTorch-Wildlife** is a platform to create, modify, and share powerful AI conservation models. These models can be used for a variety of applications, including camera trap images, overhead images, underwater images, or bioacoustics. Your engagement with our work is greatly appreciated, and we eagerly await any feedback you may have.
90
+
91
+
92
+ The **Pytorch-Wildlife** library allows users to directly load the `MegaDetector v5` model weights for animal detection. We've fully refactored our codebase, prioritizing ease of use in model deployment and expansion. In addition to `MegaDetector v5`, **Pytorch-Wildlife** also accommodates a range of classification weights, such as those derived from the Amazon Rainforest dataset and the Opossum classification dataset. Explore the codebase and functionalities of **Pytorch-Wildlife** through our interactive [HuggingFace web app](https://huggingface.co/spaces/AndresHdzC/pytorch-wildlife) or local [demos and notebooks](https://github.com/microsoft/CameraTraps/tree/main/demo), designed to showcase the practical applications of our enhancements at [PyTorchWildlife](https://github.com/microsoft/CameraTraps/blob/main/INSTALLATION.md). You can find more information in our [documentation](https://cameratraps.readthedocs.io/en/latest/).
93
+
94
+ 👇 Here is a brief example on how to perform detection and classification on a single image using `PyTorch-wildlife`
95
+ ```python
96
+ import torch
97
+ from PytorchWildlife.models import detection as pw_detection
98
+ from PytorchWildlife.models import classification as pw_classification
99
+
100
+ img = torch.randn((3, 1280, 1280))
101
+
102
+ # Detection
103
+ detection_model = pw_detection.MegaDetectorV5() # Model weights are automatically downloaded.
104
+ detection_result = detection_model.single_image_detection(img)
105
+
106
+ #Classification
107
+ classification_model = pw_classification.AI4GAmazonRainforest() # Model weights are automatically downloaded.
108
+ classification_results = classification_model.single_image_classification(img)
109
+ ```
110
+
111
+ ## ⚙️ Install Pytorch-Wildlife
112
+ ```
113
+ pip install PytorchWildlife
114
+ ```
115
+ Please refer to our [installation guide](https://github.com/microsoft/CameraTraps/blob/main/INSTALLATION.md) for more installation information.
116
+
117
+ ## 🕵️ Explore Pytorch-Wildlife and MegaDetector with our Demo User Interface
118
+
119
+ If you want to directly try **Pytorch-Wildlife** with the AI models available, including `MegaDetector v5`, you can use our [**Gradio** interface](https://github.com/microsoft/CameraTraps/tree/main/demo). This interface allows users to directly load the `MegaDetector v5` model weights for animal detection. In addition, **Pytorch-Wildlife** also has two classification models in our initial version. One is trained from an Amazon Rainforest camera trap dataset and the other from a Galapagos opossum classification dataset (more details of these datasets will be published soon). To start, please follow the [installation instructions](https://github.com/microsoft/CameraTraps/blob/main/INSTALLATION.md) on how to run the Gradio interface! We also provide multiple [**Jupyter** notebooks](https://github.com/microsoft/CameraTraps/tree/main/demo) for demonstration.
120
+
121
+ ![image](https://microsoft.github.io/CameraTraps/assets/gradio_UI.png)
122
+
123
+
124
+ ## 🛠️ Core Features
125
+ What are the core components of Pytorch-Wildlife?
126
+ ![Pytorch-core-diagram](https://microsoft.github.io/CameraTraps/assets/Pytorch_Wildlife_core_figure.jpg)
127
+
128
+
129
+ ### 🌐 Unified Framework:
130
+ Pytorch-Wildlife integrates **four pivotal elements:**
131
+
132
+ ▪ Machine Learning Models<br>
133
+ ▪ Pre-trained Weights<br>
134
+ ▪ Datasets<br>
135
+ ▪ Utilities<br>
136
+
137
+ ### 👷 Our work:
138
+ In the provided graph, boxes outlined in red represent elements that will be added and remained fixed, while those in blue will be part of our development.
139
+
140
+
141
+ ### 🚀 Inaugural Model:
142
+ We're kickstarting with YOLO as our first available model, complemented by pre-trained weights from `MegaDetector v5`. This is the same `MegaDetector v5` model from the previous repository.
143
+
144
+
145
+ ### 📚 Expandable Repository:
146
+ As we move forward, our platform will welcome new models and pre-trained weights for camera traps and bioacoustic analysis. We're excited to host contributions from global researchers through a dedicated submission platform.
147
+
148
+
149
+ ### 📊 Datasets from LILA:
150
+ Pytorch-Wildlife will also incorporate the vast datasets hosted on LILA, making it a treasure trove for conservation research.
151
+
152
+
153
+ ### 🧰 Versatile Utilities:
154
+ Our set of utilities spans from visualization tools to task-specific utilities, many inherited from Megadetector.
155
+
156
+
157
+ ### 💻 User Interface Flexibility:
158
+ While we provide a foundational user interface, our platform is designed to inspire. We encourage researchers to craft and share their unique interfaces, and we'll list both existing and new UIs from other collaborators for the community's benefit.
159
+
160
+
161
+ Let's shape the future of wildlife research, together! 🙌
162
+
163
+
164
+ ### 📈 Progress on core tasks
165
+
166
+ <details>
167
+ <summary> <font size="3"> ▪️ Packaging </font> </summary>
168
+
169
+ - [ ] Animal detection fine-tuning<br>
170
+ - [x] MegaDetectorV5 integration<br>
171
+ - [ ] MegaDetectorV6 integration<br>
172
+ - [x] User submitted weights<br>
173
+ - [x] Animal classification fine-tuning<br>
174
+ - [x] Amazon Rainforest classification<br>
175
+ - [x] Amazon Opossum classification<br>
176
+ - [ ] User submitted weights<br>
177
+ </details><br>
178
+
179
+ <details>
180
+ <summary><font size="3">▪️ Utility Toolkit</font></summary>
181
+
182
+ - [x] Visualization tools<br>
183
+ - [x] MegaDetector utils<br>
184
+ - [ ] User submitted utils<br>
185
+ </details><br>
186
+
187
+ <details>
188
+ <summary><font size="3">▪️ Datasets</font></summary>
189
+
190
+ - [ ] Animal Datasets<br>
191
+ - [ ] LILA datasets<br>
192
+ </details><br>
193
+
194
+ <details>
195
+ <summary><font size="3">▪️ Accessibility</font></summary>
196
+
197
+ - [x] Basic user interface for demonstration<br>
198
+ - [ ] UI Dev tools<br>
199
+ - [ ] List of available UIs<br>
200
+ </details><br>
201
+
202
+
203
+ ## 🖼️ Examples
204
+
205
+ ### Image detection using `MegaDetector v5`
206
+ <img src="https://microsoft.github.io/CameraTraps/assets/animal_det_1.JPG" alt="animal_det_1" width="400"/><br>
207
+ *Credits to Universidad de los Andes, Colombia.*
208
+
209
+ ### Image classification with `MegaDetector v5` and `AI4GAmazonRainforest`
210
+ <img src="https://microsoft.github.io/CameraTraps/assets/animal_clas_1.png" alt="animal_clas_1" width="500"/><br>
211
+ *Credits to Universidad de los Andes, Colombia.*
212
+
213
+ ### Opossum ID with `MegaDetector v5` and `AI4GOpossum`
214
+ <img src="https://microsoft.github.io/CameraTraps/assets/opossum_det.png" alt="opossum_det" width="500"/><br>
215
+ *Credits to the Agency for Regulation and Control of Biosecurity and Quarantine for Galápagos (ABG), Ecuador.*
216
+
217
+
218
+ ## 🤝 Contributing
219
+ This project is open to your ideas and contributions. If you want to submit a pull request, we'll have some guidelines available soon.
220
+
221
+ We have adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [us](zhongqimiao@microsoft.com) with any additional questions or comments.
222
+
223
+ ## License
224
+ This repository is licensed with the [MIT license](https://github.com/Microsoft/dotnet/blob/main/LICENSE).
225
+
226
+
227
+ ## 👥 Existing Collaborators
228
+
229
+ The extensive collaborative efforts of Megadetector have genuinely inspired us, and we deeply value its significant contributions to the community. As we continue to advance with Pytorch-Wildlife, our commitment to delivering technical support to our existing partners on MegaDetector remains the same.
230
+
231
+ Here we list a few of the organizations that have used MegaDetector. We're only listing organizations who have given us permission to refer to them here or have posted publicly about their use of MegaDetector.
232
+
233
+ <details>
234
+ <summary><font size="3">👉 Full list of organizations</font></summary>
235
+
236
+ (Newly Added) [TerrOïko](https://www.terroiko.fr/) ([OCAPI platform](https://www.terroiko.fr/ocapi))
237
+
238
+ [Arizona Department of Environmental Quality](http://azdeq.gov/)
239
+
240
+ [Blackbird Environmental](https://blackbirdenv.com/)
241
+
242
+ [Camelot](https://camelotproject.org/)
243
+
244
+ [Canadian Parks and Wilderness Society (CPAWS) Northern Alberta Chapter](https://cpawsnab.org/)
245
+
246
+ [Conservation X Labs](https://conservationxlabs.com/)
247
+
248
+ [Czech University of Life Sciences Prague](https://www.czu.cz/en)
249
+
250
+ [EcoLogic Consultants Ltd.](https://www.consult-ecologic.com/)
251
+
252
+ [Estación Biológica de Doñana](http://www.ebd.csic.es/inicio)
253
+
254
+ [Idaho Department of Fish and Game](https://idfg.idaho.gov/)
255
+
256
+ [Island Conservation](https://www.islandconservation.org/)
257
+
258
+ [Myall Lakes Dingo Project](https://carnivorecoexistence.info/myall-lakes-dingo-project/)
259
+
260
+ [Point No Point Treaty Council](https://pnptc.org/)
261
+
262
+ [Ramat Hanadiv Nature Park](https://www.ramat-hanadiv.org.il/en/)
263
+
264
+ [SPEA (Portuguese Society for the Study of Birds)](https://spea.pt/en/)
265
+
266
+ [Synthetaic](https://www.synthetaic.com/)
267
+
268
+ [Taronga Conservation Society](https://taronga.org.au/)
269
+
270
+ [The Nature Conservancy in Wyoming](https://www.nature.org/en-us/about-us/where-we-work/united-states/wyoming/)
271
+
272
+ [TrapTagger](https://wildeyeconservation.org/trap-tagger-about/)
273
+
274
+ [Upper Yellowstone Watershed Group](https://www.upperyellowstone.org/)
275
+
276
+ [Applied Conservation Macro Ecology Lab](http://www.acmelab.ca/), University of Victoria
277
+
278
+ [Banff National Park Resource Conservation](https://www.pc.gc.ca/en/pn-np/ab/banff/nature/conservation), Parks Canada(https://www.pc.gc.ca/en/pn-np/ab/banff/nature/conservation)
279
+
280
+ [Blumstein Lab](https://blumsteinlab.eeb.ucla.edu/), UCLA
281
+
282
+ [Borderlands Research Institute](https://bri.sulross.edu/), Sul Ross State University
283
+
284
+ [Capitol Reef National Park](https://www.nps.gov/care/index.htm) / Utah Valley University
285
+
286
+ [Center for Biodiversity and Conservation](https://www.amnh.org/research/center-for-biodiversity-conservation), American Museum of Natural History
287
+
288
+ [Centre for Ecosystem Science](https://www.unsw.edu.au/research/), UNSW Sydney
289
+
290
+ [Cross-Cultural Ecology Lab](https://crossculturalecology.net/), Macquarie University
291
+
292
+ [DC Cat Count](https://hub.dccatcount.org/), led by the Humane Rescue Alliance
293
+
294
+ [Department of Fish and Wildlife Sciences](https://www.uidaho.edu/cnr/departments/fish-and-wildlife-sciences), University of Idaho
295
+
296
+ [Department of Wildlife Ecology and Conservation](https://wec.ifas.ufl.edu/), University of Florida
297
+
298
+ [Ecology and Conservation of Amazonian Vertebrates Research Group](https://www.researchgate.net/lab/Fernanda-Michalski-Lab-4), Federal University of Amapá
299
+
300
+ [Gola Forest Programma](https://www.rspb.org.uk/our-work/conservation/projects/scientific-support-for-the-gola-forest-programme/), Royal Society for the Protection of Birds (RSPB)
301
+
302
+ [Graeme Shannon's Research Group](https://wildliferesearch.co.uk/group-1), Bangor University
303
+
304
+ [Hamaarag](https://hamaarag.org.il/), The Steinhardt Museum of Natural History, Tel Aviv University
305
+
306
+ [Institut des Science de la Forêt Tempérée (ISFORT)](https://isfort.uqo.ca/), Université du Québec en Outaouais
307
+
308
+ [Lab of Dr. Bilal Habib](https://bhlab.in/about), the Wildlife Institute of India
309
+
310
+ [Mammal Spatial Ecology and Conservation Lab](https://labs.wsu.edu/dthornton/), Washington State University
311
+
312
+ [McLoughlin Lab in Population Ecology](http://mcloughlinlab.ca/lab/), University of Saskatchewan
313
+
314
+ [National Wildlife Refuge System, Southwest Region](https://www.fws.gov/about/region/southwest), U.S. Fish & Wildlife Service
315
+
316
+ [Northern Great Plains Program](https://nationalzoo.si.edu/news/restoring-americas-prairie), Smithsonian
317
+
318
+ [Quantitative Ecology Lab](https://depts.washington.edu/sefsqel/), University of Washington
319
+
320
+ [Santa Monica Mountains Recreation Area](https://www.nps.gov/samo/index.htm), National Park Service
321
+
322
+ [Seattle Urban Carnivore Project](https://www.zoo.org/seattlecarnivores), Woodland Park Zoo
323
+
324
+ [Serra dos Órgãos National Park](https://www.icmbio.gov.br/parnaserradosorgaos/), ICMBio
325
+
326
+ [Snapshot USA](https://emammal.si.edu/snapshot-usa), Smithsonian
327
+
328
+ [Wildlife Coexistence Lab](https://wildlife.forestry.ubc.ca/), University of British Columbia
329
+
330
+ [Wildlife Research](https://www.dfw.state.or.us/wildlife/research/index.asp), Oregon Department of Fish and Wildlife
331
+
332
+ [Wildlife Division](https://www.michigan.gov/dnr/about/contact/wildlife), Michigan Department of Natural Resources
333
+
334
+ Department of Ecology, TU Berlin
335
+
336
+ Ghost Cat Analytics
337
+
338
+ Protected Areas Unit, Canadian Wildlife Service
339
+
340
+ [School of Natural Sciences](https://www.utas.edu.au/natural-sciences), University of Tasmania [(story)](https://www.utas.edu.au/about/news-and-stories/articles/2022/1204-innovative-camera-network-keeps-close-eye-on-tassie-wildlife)
341
+
342
+ [Kenai National Wildlife Refuge](https://www.fws.gov/refuge/kenai), U.S. Fish & Wildlife Service [(story)](https://www.peninsulaclarion.com/sports/refuge-notebook-new-technology-increases-efficiency-of-refuge-cameras/)
343
+
344
+ [Australian Wildlife Conservancy](https://www.australianwildlife.org/) [(blog](https://www.australianwildlife.org/cutting-edge-technology-delivering-efficiency-gains-in-conservation/), [blog)](https://www.australianwildlife.org/efficiency-gains-at-the-cutting-edge-of-technology/)
345
+
346
+ [Felidae Conservation Fund](https://felidaefund.org/) [(WildePod platform)](https://wildepod.org/) [(blog post)](https://abhaykashyap.com/blog/ai-powered-camera-trap-image-annotation-system/)
347
+
348
+ [Alberta Biodiversity Monitoring Institute (ABMI)](https://www.abmi.ca/home.html) [(WildTrax platform)](https://www.wildtrax.ca/) [(blog post)](https://wildcams.ca/blog/the-abmi-visits-the-zoo/)
349
+
350
+ [Shan Shui Conservation Center](http://en.shanshui.org/) [(blog post)](https://mp.weixin.qq.com/s/iOIQF3ckj0-rEG4yJgerYw?fbclid=IwAR0alwiWbe3udIcFvqqwm7y5qgr9hZpjr871FZIa-ErGUukZ7yJ3ZhgCevs) [(translated blog post)](https://mp-weixin-qq-com.translate.goog/s/iOIQF3ckj0-rEG4yJgerYw?fbclid=IwAR0alwiWbe3udIcFvqqwm7y5qgr9hZpjr871FZIa-ErGUukZ7yJ3ZhgCevs&_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp)
351
+
352
+ [Irvine Ranch Conservancy](http://www.irconservancy.org/) [(story)](https://www.ocregister.com/2022/03/30/ai-software-is-helping-researchers-focus-on-learning-about-ocs-wild-animals/)
353
+
354
+ [Wildlife Protection Solutions](https://wildlifeprotectionsolutions.org/) [(story](https://customers.microsoft.com/en-us/story/1384184517929343083-wildlife-protection-solutions-nonprofit-ai-for-earth), [story)](https://www.enterpriseai.news/2023/02/20/ai-helps-wildlife-protection-solutions-safeguard-endangered-species/)
355
+
356
+ [Road Ecology Center](https://roadecology.ucdavis.edu/), University of California, Davis [(Wildlife Observer Network platform)](https://wildlifeobserver.net/)
357
+
358
+ [The Nature Conservancy in California](https://www.nature.org/en-us/about-us/where-we-work/united-states/california/) [(Animl platform)](https://github.com/tnc-ca-geo/animl-frontend)
359
+
360
+ [San Diego Zoo Wildlife Alliance](https://science.sandiegozoo.org/) [(Animl R package)](https://github.com/conservationtechlab/animl)
361
+
362
+ </details><br>
363
+
364
+
365
+ >[!IMPORTANT]
366
+ >If you would like to be added to this list or have any questions regarding MegaDetector and Pytorch-Wildlife, please [email us](zhongqimiao@microsoft.com) or join us in our Discord channel: [![](https://img.shields.io/badge/any_text-Join_us!-blue?logo=discord&label=PytorchWildife)](https://discord.gg/TeEVxzaYtm)
367
+
@@ -0,0 +1 @@
1
+ from batch_detection_cropping import *
@@ -0,0 +1,178 @@
1
+ # %%
2
+ # Importing libraries
3
+ import os
4
+ import yaml
5
+ import typer
6
+ from munch import Munch
7
+ # %%
8
+ import torch
9
+ import pytorch_lightning as pl
10
+ from pytorch_lightning.callbacks import ModelCheckpoint
11
+ from pytorch_lightning.callbacks import LearningRateMonitor
12
+ from pytorch_lightning.loggers import CSVLogger, CometLogger, TensorBoardLogger, WandbLogger
13
+ # %%
14
+ from src import algorithms
15
+ from src import datasets
16
+ # %%
17
+ from src.utils import batch_detection_cropping
18
+ from src.utils import data_splitting
19
+ #app = typer.Typer()
20
+ # %%
21
+ #@app.command()
22
+ def main(
23
+ config:str='./configs/Raw/Crop_res50_plain_082723.yaml',
24
+ project:str='Custom-classification',
25
+ gpus:str='0',
26
+ logger_type:str='csv',
27
+ evaluate:str=None,
28
+ np_threads:str='32',
29
+ session:int=0,
30
+ seed:int=0,
31
+ dev:bool=False,
32
+ val:bool=False,
33
+ predict:bool=False,
34
+ predict_root:str=""
35
+ ):
36
+ """
37
+ Main function for training or evaluating a ResNet-50 model using PyTorch Lightning.
38
+ It loads configurations, initializes the model, logger, and other components based on provided arguments.
39
+
40
+ Args:
41
+ config (str): Path to the configuration file.
42
+ project (str): Name of the project for logging.
43
+ gpus (str): Comma-separated GPU ids for training.
44
+ logger_type (str): Type of logger to use (wandb, comet, tensorboard, csv).
45
+ evaluate (str): Path to the model checkpoint for evaluation.
46
+ np_threads (str): Number of numpy threads to use.
47
+ session (int): Session number for logging purposes.
48
+ seed (int): Random seed for reproducibility.
49
+ dev (bool): Development mode flag.
50
+ val (bool): Validation mode flag.
51
+ predict (bool): Prediction mode flag.
52
+ predict_root (str): Root directory for prediction outputs.
53
+ """
54
+
55
+ # GPU configuration: set up GPUs based on availability and user specification
56
+ gpus = gpus if torch.cuda.is_available() else None
57
+ gpus = [int(i) for i in gpus.split(',')]
58
+
59
+ # Environment variable setup for numpy multi-threading
60
+ os.environ["OMP_NUM_THREADS"] = str(np_threads)
61
+ os.environ["OPENBLAS_NUM_THREADS"] = str(np_threads)
62
+ os.environ["MKL_NUM_THREADS"] = str(np_threads)
63
+ os.environ["VECLIB_MAXIMUM_THREADS"] = str(np_threads)
64
+ os.environ["NUMEXPR_NUM_THREADS"] = str(np_threads)
65
+ # Load and set configurations from the YAML file
66
+ with open(config) as f:
67
+ conf = Munch(yaml.load(f, Loader=yaml.FullLoader))
68
+ conf.evaluate = evaluate
69
+ conf.val = val
70
+ conf.predict = predict
71
+ conf.predict_root = predict_root
72
+
73
+ # Set a global seed for reproducibility
74
+ pl.seed_everything(seed)
75
+
76
+
77
+ # If the annotation directory does not have a data split, split the data first
78
+ if conf.split_data:
79
+ # Replace annotation dir from config with the directory containing the split files
80
+ conf.annotation_dir = os.path.dirname(conf.split_path)
81
+ # Split the data according to the split type
82
+ if conf.split_type == 'location':
83
+ data_splitting.split_by_location(conf.split_path, conf.annotation_dir, conf.test_size, conf.val_size)
84
+ elif conf.split_type == 'sequence':
85
+ data_splitting.split_by_seq(conf.split_path, conf.annotation_dir, conf.test_size, conf.val_size)
86
+ elif conf.split_type == 'random':
87
+ data_splitting.create_splits(conf.split_path, conf.annotation_dir, conf.test_size, conf.val_size)
88
+ else:
89
+ raise ValueError('Invalid split type: {}. Available options: random, location, sequence.'.format(conf.split_type))
90
+
91
+ # Get the path to the annotation files
92
+ train_annotations = os.path.join(conf.dataset_root, 'train_annotations.csv')
93
+ test_annotations = os.path.join(conf.dataset_root, 'test_annotations.csv')
94
+ val_annotations = os.path.join(conf.dataset_root, 'val_annotations.csv')
95
+ # Split training data
96
+
97
+ batch_detection_cropping.batch_detection_cropping(conf.dataset_root, os.path.join(conf.dataset_root, "cropped_resized"), train_annotations)
98
+ # Split validation and test data
99
+ batch_detection_cropping.batch_detection_cropping(conf.dataset_root, os.path.join(conf.dataset_root, "cropped_resized"), val_annotations)
100
+ batch_detection_cropping.batch_detection_cropping(conf.dataset_root, os.path.join(conf.dataset_root, "cropped_resized"), test_annotations)
101
+
102
+
103
+ # Dataset and algorithm loading based on the configuration
104
+ dataset = datasets.__dict__[conf.dataset_name](conf=conf)
105
+ learner = algorithms.__dict__[conf.algorithm](conf=conf,
106
+ train_class_counts=dataset.train_class_counts,
107
+ id_to_labels=dataset.id_to_labels)
108
+
109
+ # Logger setup based on the specified logger type
110
+ log_folder = 'log_dev' if dev else 'log'
111
+ logger = None
112
+ if logger_type == 'csv':
113
+ logger = CSVLogger(
114
+ save_dir='./{}/{}/{}'.format(log_folder, conf.log_dir, conf.algorithm),
115
+ prefix=project,
116
+ name='{}_{}'.format(conf.algorithm, conf.conf_id),
117
+ version=session
118
+ )
119
+ elif logger_type == 'tensorboard':
120
+ logger = TensorBoardLogger(
121
+ save_dir='./{}/{}/{}'.format(log_folder, conf.log_dir, conf.algorithm),
122
+ prefix=project,
123
+ name='{}_{}'.format(conf.algorithm, conf.conf_id),
124
+ version=session
125
+ )
126
+ elif logger_type == 'comet':
127
+ logger = CometLogger(
128
+ api_key=os.environ.get("COMET_API_KEY"),
129
+ save_dir='./{}/{}/{}'.format(log_folder, conf.log_dir, conf.algorithm),
130
+ project_name=project,
131
+ experiment_name='{}_{}_{}'.format(conf.algorithm, conf.conf_id, session),
132
+ )
133
+ elif logger_type == 'wandb':
134
+ logger = WandbLogger(
135
+ save_dir='./{}/{}/{}'.format(log_folder, conf.log_dir, conf.algorithm),
136
+ project=project,
137
+ name='{}_{}_{}'.format(conf.algorithm, conf.conf_id, session),
138
+ )
139
+
140
+ # Callbacks for model checkpointing and learning rate monitoring
141
+ weights_folder = 'weights_dev' if dev else 'weights'
142
+ checkpoint_callback = ModelCheckpoint(
143
+ monitor='valid_mac_acc', mode='max', dirpath='./{}/{}/{}'.format(weights_folder, conf.log_dir, conf.algorithm),
144
+ save_top_k=1, filename='{}-{}'.format(conf.conf_id, session) + '-{epoch:02d}-{valid_mac_acc:.2f}', verbose=True
145
+ )
146
+
147
+ lr_monitor = LearningRateMonitor(logging_interval='step')
148
+
149
+ # Trainer configuration in PyTorch Lightning
150
+ trainer = pl.Trainer(
151
+ max_epochs=conf.num_epochs,
152
+ check_val_every_n_epoch=1,
153
+ log_every_n_steps = conf.log_interval,
154
+ accelerator='gpu',
155
+ devices=gpus,
156
+ logger=None if evaluate is not None else logger,
157
+ callbacks=[lr_monitor, checkpoint_callback],
158
+ strategy='ddp',
159
+ num_sanity_val_steps=0,
160
+ profiler=None
161
+ )
162
+ # Training, validation, or evaluation execution based on the mode
163
+ if evaluate is not None:
164
+ if val:
165
+ trainer.validate(learner, dataloaders=[dataset.val_dataloader()], ckpt_path=evaluate)
166
+ elif predict:
167
+ trainer.predict(learner, dataloaders=[dataset.predict_dataloader()], ckpt_path=evaluate)
168
+ else:
169
+ trainer.test(learner, dataloaders=[dataset.test_dataloader()], ckpt_path=evaluate)
170
+ else:
171
+ trainer.fit(learner, datamodule=dataset)
172
+ # %%
173
+ if __name__ == '__main__':
174
+ main()
175
+
176
+
177
+
178
+ # %%
@@ -0,0 +1,10 @@
1
+ import importlib.metadata as importlib_metadata
2
+ try:
3
+ # This will read version from pyproject.toml
4
+ __version__ = importlib_metadata.version(__package__ or __name__)
5
+ except importlib_metadata.PackageNotFoundError:
6
+ __version__ = "development"
7
+
8
+ from .data import *
9
+ from .models import *
10
+ from .utils import *
@@ -0,0 +1,2 @@
1
+ from .datasets import *
2
+ from .transforms import *