documentation update
This commit is contained in:
Родитель
46928b4dc9
Коммит
2d661b519b
|
@ -17,3 +17,4 @@ PytorchWildlife.egg-info/
|
|||
*annotations.csv
|
||||
*cropped_resized*
|
||||
*log*
|
||||
MDV6b-yolov9c.pt
|
||||
|
|
|
@ -84,11 +84,11 @@ docker run -p 80:80 andreshdz/pytorchwildlife:1.0.2.3 python demo/gradio_demo.py
|
|||
Here is a brief example on how to perform detection and classification on a single image using `PyTorch-wildlife`:
|
||||
|
||||
```python
|
||||
import torch
|
||||
import numpy as np
|
||||
from PytorchWildlife.models import detection as pw_detection
|
||||
from PytorchWildlife.models import classification as pw_classification
|
||||
|
||||
img = torch.randn((3, 1280, 1280))
|
||||
img = np.random.randn(3, 1280, 1280)
|
||||
|
||||
# Detection
|
||||
detection_model = pw_detection.MegaDetectorV5() # Model weights are automatically downloaded.
|
||||
|
@ -110,9 +110,9 @@ python image_demo.py
|
|||
# For the video demo
|
||||
python video_demo.py
|
||||
# For the gradio app
|
||||
python demo_gradio.py
|
||||
python gradio_demo.py
|
||||
```
|
||||
The `demo_gradio.py` will launch a Gradio interface where you can:
|
||||
The `gradio_demo.py` will launch a Gradio interface where you can:
|
||||
- Perform Single Image Detection: Upload an image and set a confidence threshold to get detections.
|
||||
- Perform Batch Image Detection: Upload a zip file containing multiple images to get detections in a JSON format.
|
||||
- Perform Video Detection: Upload a video and get a processed video with detected animals.
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"id": "8f622040",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
@ -82,7 +82,7 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"DEVICE = \"cuda\" # Use \"cuda\" if GPU is available \"cpu\" if no GPU is available\n",
|
||||
"detection_model = pw_detection.MegaDetectorV5(device=DEVICE, pretrained=True)"
|
||||
"detection_model = pw_detection.MegaDetectorV5(device=DEVICE, pretrained=True, version=\"a\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -116,18 +116,15 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 6,
|
||||
"id": "0d730b20",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tgt_img_path = os.path.join(demo_path, \"demo_data\", \"imgs\", \"10050028_0.JPG\")\n",
|
||||
"img = np.array(Image.open(tgt_img_path).convert(\"RGB\"))\n",
|
||||
"transform = pw_trans.MegaDetector_v5_Transform(target_size=detection_model.IMAGE_SIZE,\n",
|
||||
" stride=detection_model.STRIDE)\n",
|
||||
"results = detection_model.single_image_detection(transform(img), img.shape, tgt_img_path)\n",
|
||||
"pw_utils.save_detection_images(results, os.path.join(demo_path,\"demo_output\"))\n",
|
||||
"print(demo_path)"
|
||||
"results = detection_model.single_image_detection(tgt_img_path)\n",
|
||||
"pw_utils.save_detection_images(results, os.path.join(demo_path,\"demo_output\"), overwrite=False)\n",
|
||||
"pw_utils.save_crop_images(results, os.path.join(\".\",\"crop_output\"), overwrite=False)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -147,16 +144,7 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"tgt_folder_path = os.path.join(demo_path, \"demo_data\", \"imgs\")\n",
|
||||
"\n",
|
||||
"dataset = pw_data.DetectionImageFolder(\n",
|
||||
" tgt_folder_path,\n",
|
||||
" transform=pw_trans.MegaDetector_v5_Transform(target_size=detection_model.IMAGE_SIZE,\n",
|
||||
" stride=detection_model.STRIDE),\n",
|
||||
" extension='JPG' # Can be other extensions based on your own data, such as png. And this argument is case sensitive.\n",
|
||||
")\n",
|
||||
"loader = DataLoader(dataset, batch_size=32, shuffle=False, \n",
|
||||
" pin_memory=True, num_workers=0, drop_last=False)\n",
|
||||
"results = detection_model.batch_image_detection(loader)"
|
||||
"results = detection_model.batch_image_detection(tgt_folder_path, batch_size=16, extension=\"JPG\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -173,7 +161,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 8,
|
||||
"id": "f63310ab",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
@ -192,7 +180,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 9,
|
||||
"id": "13653739",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
@ -211,7 +199,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 10,
|
||||
"id": "b627280b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
@ -233,7 +221,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 11,
|
||||
"id": "eff35a43",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"id": "24b2cf06",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
@ -108,27 +108,6 @@
|
|||
"classification_model = pw_classification.AI4GOpossum(device=DEVICE, pretrained=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "fa4913d8",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Transformations\n",
|
||||
"Define transformations for both detection and classification. These transformations preprocess the video frames for the models."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "cc6377ee",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"trans_det = pw_trans.MegaDetector_v5_Transform(target_size=detection_model.IMAGE_SIZE,\n",
|
||||
" stride=detection_model.STRIDE)\n",
|
||||
"trans_clf = pw_trans.Classification_Inference_Transform(target_size=224)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3cd6262a",
|
||||
|
@ -145,16 +124,18 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"box_annotator = sv.BoundingBoxAnnotator(thickness=4)\n",
|
||||
"box_annotator = sv.BoxAnnotator(thickness=4)\n",
|
||||
"lab_annotator = sv.LabelAnnotator(text_color=sv.Color.BLACK, text_thickness=4, text_scale=2)\n",
|
||||
"\n",
|
||||
"def callback(frame: np.ndarray, index: int) -> np.ndarray:\n",
|
||||
" results_det = detection_model.single_image_detection(trans_det(frame), frame.shape, index)\n",
|
||||
" results_det = detection_model.single_image_detection(frame, img_path=index)\n",
|
||||
" labels = []\n",
|
||||
"\n",
|
||||
" for xyxy in results_det[\"detections\"].xyxy:\n",
|
||||
" cropped_image = sv.crop_image(image=frame, xyxy=xyxy)\n",
|
||||
" results_clf = classification_model.single_image_classification(trans_clf(Image.fromarray(cropped_image)))\n",
|
||||
" results_clf = classification_model.single_image_classification(cropped_image)\n",
|
||||
" labels.append(\"{} {:.2f}\".format(results_clf[\"prediction\"], results_clf[\"confidence\"]))\n",
|
||||
"\n",
|
||||
" annotated_frame = lab_annotator.annotate(\n",
|
||||
" scene=box_annotator.annotate(\n",
|
||||
" scene=frame,\n",
|
||||
|
@ -163,9 +144,10 @@
|
|||
" detections=results_det[\"detections\"],\n",
|
||||
" labels=labels,\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" return annotated_frame \n",
|
||||
"\n",
|
||||
"pw_utils.process_video(source_path=SOURCE_VIDEO_PATH, target_path=TARGET_VIDEO_PATH, callback=callback, target_fps=5)"
|
||||
"pw_utils.process_video(source_path=SOURCE_VIDEO_PATH, target_path=TARGET_VIDEO_PATH, callback=callback, target_fps=10)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -24,6 +24,6 @@ Tutorials
|
|||
|
||||
To help you get hands-on with the package, we provide detailed tutorials that walk you through various functionalities of PytorchWildlife:
|
||||
|
||||
3. **Gradio Interface**: Dive into an interactive demo using Gradio, which provides a user-friendly interface for quick demonstrations. [Link to the tutorial](./demo/gradio_demo.ipynb)
|
||||
3. **Gradio Interface**: Dive into an interactive demo using Gradio, which provides a user-friendly interface for quick demonstrations. `Link to the tutorial <./demo/gradio_demo.ipynb>`_
|
||||
|
||||
We recommend starting with the Gradio Interface tutorial for out-of-the-box inference and then progressing to the others as you become more familiar with the package.
|
||||
|
|
|
@ -39,8 +39,6 @@ We are also working on an extra-large version of MegaDetectorV6 for optimal perf
|
|||
### 🎉 Pytorch-Wildlife ready for citation
|
||||
In addition, we have recently published a [summary paper on Pytorch-Wildlife](https://arxiv.org/abs/2405.12930). The paper has been accepted as an oral presentation at the [CV4Animals workshop](https://www.cv4animals.com/) at this year's CVPR. Please feel free to [cite us!](#cite-us)
|
||||
|
||||
### 🛠️ Compatibility with CUDA 12.x
|
||||
The new version of PytorchWildlife uses the latest version of Pytorch (currently 2.3.1), which is compatible with CUDA 12.x.
|
||||
|
||||
## ✅ Feature highlights (Version 1.0.2.15)
|
||||
- [x] Added a file separation function. You can now automatically separate your files between animals and non-animals into different folders using our `detection_folder_separation` function. Please see the [Python demo file](demo/image_separation_demo.py) and [Jupyter demo](demo/image_separation_demo.ipynb)!
|
||||
|
@ -376,3 +374,5 @@ Protected Areas Unit, Canadian Wildlife Service
|
|||
>[!IMPORTANT]
|
||||
>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)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,4 +6,7 @@ Pillow
|
|||
supervision==0.23.0
|
||||
gradio
|
||||
ultralytics-yolov5
|
||||
chardet
|
||||
chardet
|
||||
wget
|
||||
ultralytics
|
||||
setuptools==59.5.0
|
6
setup.py
6
setup.py
|
@ -24,7 +24,10 @@ setup(
|
|||
'gradio==4.8.0',
|
||||
'ultralytics-yolov5',
|
||||
'ultralytics',
|
||||
'chardet'
|
||||
'chardet',
|
||||
'wget',
|
||||
'ultralytics',
|
||||
'setuptools==59.5.0'
|
||||
],
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Alpha',
|
||||
|
@ -35,6 +38,7 @@ setup(
|
|||
'Programming Language :: Python :: 3.7',
|
||||
'Programming Language :: Python :: 3.8',
|
||||
'Programming Language :: Python :: 3.9',
|
||||
'Programming Language :: Python :: 3.10+',
|
||||
],
|
||||
keywords='pytorch_wildlife, pytorch, wildlife, megadetector, conservation, animal, detection, classification',
|
||||
python_requires='>=3.8',
|
||||
|
|
Загрузка…
Ссылка в новой задаче