# pbaa : Prompt-Based Automatic Annotation
[![PyPI - Version](https://img.shields.io/pypi/v/pbaa.svg)](https://pypi.org/project/pbaa)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pbaa.svg)](https://pypi.org/project/pbaa)
Easy inference implementation of [Grounded-SAM](https://github.com/IDEA-Research/Grounded-Segment-Anything) for
**Prompt-based automatic annotation**
-----
**Table of Contents**
- [Installation](#installation)
- [Usage](#usage)
- [Gradio](#gradio)
- [Demo](#demo)
- [License](#license)
- [Acknowledgements](#acknowledgements)
## Installation
### Docker (Recommend)
```console
git clone https://github.com/dh031200/pbaa.git
docker build docker -t pbaa:latest
docker run --gpus all -it --ipc=host -v `pwd`:/workspace -p 7860:7860 pbaa:latest
```
### Without docker
The code requires `python>=3.8`, `CUDA==11.7`.
```console
pip install pbaa
```
## Usage
### Options
```console
Usage: pbaa [OPTIONS]
Options:
--version Show the version and exit.
-s, --src TEXT Source image or directory path
-p, --prompt <TEXT TEXT>... Space-separated a pair of prompt and target
classe. (Multi)
-b, --box_threshold FLOAT Threshold for Object Detection (default: 0.25)
-n, --nms_threshold FLOAT Threshold for NMS (default: 0.8)
-o, --output_dir TEXT Path to result data (default: 'outputs')
-g, --gradio Launch gradio app
-h, --help Show this message and exit.
```
### CLI
```console
# pbaa -s <Source> -p <prompt> <class> -p <prompt> <class> ...
pbaa -s source_image.jpg -p "black dog" dog
pbaa -s source_image.jpg -p "black dog" dog -p "white cat" cat
```
### Python
```python
from pbaa import PBAA
annotator = PBAA()
# inference(<Source path>, <prompt:class dict>, box_threshold=0.25, nms_threshold=0.8, save=None, output_dir="outputs")
annotator("path/to/source_image.jpg", {"black dog": "dog", "white cat": "cat"})
```
## Gradio
Run the [gradio](https://github.com/gradio-app/gradio) demo with a simple command
```console
pbaa -g
```
Output
```
Launch gradio app
Running on local URL: http://0.0.0.0:7860
```
You can now access Gradio demos using your browser.
[localhost:7860](http://localhost:7860)
![gradio_demo](https://github.com/dh031200/pbaa/blob/main/assets/gradio_demo.png?raw=true)
## Demo
```console
# Source : assets/demo9.jpg
# prompts : {"plant" : "plant", "picture" : "picture", "dog": "dog", "lamp" : "lamp", "carpet" : "carpet", "sofa" : "sofa"}
pbaa -s assets/demo9.jpg -p plant plant -p picture picture -p dog dog -p lamp lamp -p carpet carpet -p sofa sofa
```
| Origin | Detection | Segmentation |
|:-------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------:|
| ![Before](https://github.com/dh031200/pbaa/blob/main/assets/demo9.jpg?raw=true) | ![detection](https://github.com/dh031200/pbaa/blob/main/assets/demo9_det.jpg?raw=true) | ![segmentation](https://github.com/dh031200/pbaa/blob/main/assets/demo9_seg.jpg?raw=true) |
### Result data
[demo9.json](https://github.com/dh031200/pbaa/blob/main/assets/demo9.json)<br>
```console
json structure
filename
prompt
index
├ cls : class name
├ conf : confidence score
├ box : bounding box coordinates
└ poly : polygon coordinates
```
## License
`pbaa` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.
## Acknowledgements
Grounded-Segment-Anything : [https://github.com/IDEA-Research/Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything)<br>
Grounding DINO : [https://github.com/IDEA-Research/GroundingDINO](https://github.com/IDEA-Research/GroundingDINO)<br>
Segment-anything : [https://github.com/facebookresearch/segment-anything](https://github.com/facebookresearch/segment-anything)<br>
Raw data
{
"_id": null,
"home_page": "",
"name": "pbaa",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "Prompt based automatic annotation,grounded-sam,groundingdino,pbaa,segment-anything",
"author": "",
"author_email": "dh031200 <imbird0312@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/92/01/31d452675f8a7fc35238554a1bcc706c87644c516178711f39a8191e702d/pbaa-1.0.4.tar.gz",
"platform": null,
"description": "# pbaa : Prompt-Based Automatic Annotation\n\n[![PyPI - Version](https://img.shields.io/pypi/v/pbaa.svg)](https://pypi.org/project/pbaa)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pbaa.svg)](https://pypi.org/project/pbaa)\n\nEasy inference implementation of [Grounded-SAM](https://github.com/IDEA-Research/Grounded-Segment-Anything) for\n**Prompt-based automatic annotation**\n\n-----\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Gradio](#gradio)\n- [Demo](#demo)\n- [License](#license)\n- [Acknowledgements](#acknowledgements)\n\n## Installation\n\n### Docker (Recommend)\n\n```console\ngit clone https://github.com/dh031200/pbaa.git\ndocker build docker -t pbaa:latest\ndocker run --gpus all -it --ipc=host -v `pwd`:/workspace -p 7860:7860 pbaa:latest\n```\n\n### Without docker\n\nThe code requires `python>=3.8`, `CUDA==11.7`.\n\n```console\npip install pbaa\n```\n\n## Usage\n\n### Options\n\n```console\nUsage: pbaa [OPTIONS]\n\nOptions:\n --version Show the version and exit.\n -s, --src TEXT Source image or directory path\n -p, --prompt <TEXT TEXT>... Space-separated a pair of prompt and target\n classe. (Multi)\n -b, --box_threshold FLOAT Threshold for Object Detection (default: 0.25)\n -n, --nms_threshold FLOAT Threshold for NMS (default: 0.8)\n -o, --output_dir TEXT Path to result data (default: 'outputs')\n -g, --gradio Launch gradio app\n -h, --help Show this message and exit.\n```\n\n### CLI\n\n```console\n# pbaa -s <Source> -p <prompt> <class> -p <prompt> <class> ...\n\npbaa -s source_image.jpg -p \"black dog\" dog\npbaa -s source_image.jpg -p \"black dog\" dog -p \"white cat\" cat\n```\n\n### Python\n\n```python\nfrom pbaa import PBAA\n\nannotator = PBAA()\n# inference(<Source path>, <prompt:class dict>, box_threshold=0.25, nms_threshold=0.8, save=None, output_dir=\"outputs\")\nannotator(\"path/to/source_image.jpg\", {\"black dog\": \"dog\", \"white cat\": \"cat\"})\n```\n\n## Gradio\n\nRun the [gradio](https://github.com/gradio-app/gradio) demo with a simple command\n\n```console\npbaa -g\n```\n\nOutput\n\n```\nLaunch gradio app\nRunning on local URL: http://0.0.0.0:7860\n```\n\nYou can now access Gradio demos using your browser.\n[localhost:7860](http://localhost:7860)\n\n![gradio_demo](https://github.com/dh031200/pbaa/blob/main/assets/gradio_demo.png?raw=true)\n\n## Demo\n\n```console\n# Source : assets/demo9.jpg\n# prompts : {\"plant\" : \"plant\", \"picture\" : \"picture\", \"dog\": \"dog\", \"lamp\" : \"lamp\", \"carpet\" : \"carpet\", \"sofa\" : \"sofa\"}\n\npbaa -s assets/demo9.jpg -p plant plant -p picture picture -p dog dog -p lamp lamp -p carpet carpet -p sofa sofa\n```\n\n| Origin | Detection | Segmentation |\n|:-------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------:|\n| ![Before](https://github.com/dh031200/pbaa/blob/main/assets/demo9.jpg?raw=true) | ![detection](https://github.com/dh031200/pbaa/blob/main/assets/demo9_det.jpg?raw=true) | ![segmentation](https://github.com/dh031200/pbaa/blob/main/assets/demo9_seg.jpg?raw=true) |\n\n### Result data\n\n[demo9.json](https://github.com/dh031200/pbaa/blob/main/assets/demo9.json)<br>\n\n```console\njson structure\n\nfilename\nprompt\nindex\n \u251c cls : class name\n \u251c conf : confidence score\n \u251c box : bounding box coordinates\n \u2514 poly : polygon coordinates\n```\n\n## License\n\n`pbaa` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.\n\n## Acknowledgements\n\nGrounded-Segment-Anything : [https://github.com/IDEA-Research/Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything)<br>\nGrounding DINO : [https://github.com/IDEA-Research/GroundingDINO](https://github.com/IDEA-Research/GroundingDINO)<br>\nSegment-anything : [https://github.com/facebookresearch/segment-anything](https://github.com/facebookresearch/segment-anything)<br>\n",
"bugtrack_url": null,
"license": "",
"summary": "Prompt based automatic annotation",
"version": "1.0.4",
"project_urls": {
"Documentation": "https://github.com/dh031200/pbaa#readme",
"Issues": "https://github.com/dh031200/pbaa/issues",
"Source": "https://github.com/dh031200/pbaa"
},
"split_keywords": [
"prompt based automatic annotation",
"grounded-sam",
"groundingdino",
"pbaa",
"segment-anything"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a5a759955ecd6545dccb7277c76015bdddd8bc2dbecc1083f325bdbe594c4b91",
"md5": "d483a88be670a7ca9ff8c4886035dd37",
"sha256": "d3e528fa2d2dee15a350dfde6c2c0feda6f1755ec4d9bdbd80f052b57aa19315"
},
"downloads": -1,
"filename": "pbaa-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d483a88be670a7ca9ff8c4886035dd37",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 15159,
"upload_time": "2023-06-20T05:47:19",
"upload_time_iso_8601": "2023-06-20T05:47:19.931061Z",
"url": "https://files.pythonhosted.org/packages/a5/a7/59955ecd6545dccb7277c76015bdddd8bc2dbecc1083f325bdbe594c4b91/pbaa-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "920131d452675f8a7fc35238554a1bcc706c87644c516178711f39a8191e702d",
"md5": "d71ae386338f07fe0a0fb6b536e1d0ca",
"sha256": "d5f599de03f5c3a7603f676af431264920e2df08fee3fc4927a15e2de60f5366"
},
"downloads": -1,
"filename": "pbaa-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "d71ae386338f07fe0a0fb6b536e1d0ca",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9031277,
"upload_time": "2023-06-20T05:47:23",
"upload_time_iso_8601": "2023-06-20T05:47:23.317944Z",
"url": "https://files.pythonhosted.org/packages/92/01/31d452675f8a7fc35238554a1bcc706c87644c516178711f39a8191e702d/pbaa-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-20 05:47:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dh031200",
"github_project": "pbaa#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pbaa"
}