Skip to content

Commit

Permalink
update docs and output images
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-medeiros committed Oct 12, 2024
1 parent 5b68588 commit 29940a2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 56 deletions.
73 changes: 20 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# Language Segment-Anything

Language Segment-Anything is an open-source project that combines the power of instance segmentation and text prompts to generate masks for specific objects in images. Built on the recently released Meta model, segment-anything, and the GroundingDINO detection model, it's an easy-to-use and effective tool for object detection and image segmentation.
Language Segment-Anything is an open-source project that combines the power of instance segmentation and text prompts to generate masks for specific objects in images. Built on the recently released Meta model, Segment Anything Model 2, and the GroundingDINO detection model, it's an easy-to-use and effective tool for object detection and image segmentation.

![person.png](/assets/outputs/person.png)

## Features

- Zero-shot text-to-bbox approach for object detection.
- GroundingDINO detection model integration.
- Easy deployment using the Lightning AI app platform.
- SAM 2.
- Batch inference support.
- Easy endpoint deployment using the Lightning AI litserve platform.
- Customizable text prompts for precise object segmentation.

## Getting Started

### Prerequisites

- Python 3.7 or higher
- torch (tested 2.0)
- torchvision
- Python 3.11 or higher

### Installation

```
pip install torch torchvision
pip install -U git+https://github.com/luca-medeiros/lang-segment-anything.git
```

Expand All @@ -31,34 +30,26 @@ Clone the repository and install the required packages:

```
git clone https://github.com/luca-medeiros/lang-segment-anything && cd lang-segment-anything
pip install torch torchvision
pip install -e .
```
Or use Conda
Create a Conda environment from the `environment.yml` file:
```
conda env create -f environment.yml
# Activate the new environment:
conda activate lsa
```

#### Docker Installation

Build and run the image.

```
docker build --tag lang-segment-anything:latest .
docker run --gpus all -it lang-segment-anything:latest
```

If you want a shared folder you can add a volume with `-v <host_source_dir>:<container_dest_dir>` example: `-v ./data:/workspace/data`
```
git clone https://github.com/luca-medeiros/lang-segment-anything && cd lang-segment-anything
docker build --tag lang-segment-anything:latest .
docker run --gpus all -p 8000:8000 lang-segment-anything:latest
```


### Usage

To run the Lightning AI APP:
To run the gradio APP:

`lightning run app app.py`
`python app.py`
And open `http://0.0.0.0:8000/gradio`

Use as a library:

Expand All @@ -68,49 +59,25 @@ from lang_sam import LangSAM

model = LangSAM()
image_pil = Image.open("./assets/car.jpeg").convert("RGB")
text_prompt = "wheel"
masks, boxes, phrases, logits = model.predict(image_pil, text_prompt)
```

Use with custom checkpoint:

First download a model checkpoint.

```python
from PIL import Image
from lang_sam import LangSAM

model = LangSAM("<model_type>", "<path/to/checkpoint>")
image_pil = Image.open("./assets/car.jpeg").convert("RGB")
text_prompt = "wheel"
masks, boxes, phrases, logits = model.predict(image_pil, text_prompt)
text_prompt = "wheel."
results = model.predict([image_pil], [text_prompt])
```

## Examples

![car.png](/assets/outputs/car.png)

![kiwi.png](/assets/outputs/kiwi.png)

![person.png](/assets/outputs/person.png)

## Roadmap

Future goals for this project include:

1. **FastAPI integration**: To streamline deployment even further, we plan to add FastAPI code to our project, making it easier for users to deploy and interact with the model.

1. **Labeling pipeline**: We want to create a labeling pipeline that allows users to input both the text prompt and the image and receive labeled instance segmentation outputs. This would help users efficiently generate results for further analysis and training.
![fruits.png](/assets/outputs/fruits.png)

1. **Implement CLIP version**: To (maybe) enhance the model's capabilities and performance, we will explore the integration of OpenAI's CLIP model. This could provide improved language understanding and potentially yield better instance segmentation results.

## Acknowledgments

This project is based on the following repositories:
This project is based on/used the following repositories:

- [GroundingDINO](https://github.com/IDEA-Research/GroundingDINO)
- [Segment-Anything](https://github.com/facebookresearch/segment-anything)
- [Lightning AI](https://github.com/Lightning-AI/lightning)
- [Segment-Anything](https://github.com/facebookresearch/segment-anything-2)
- [LitServe](https://github.com/Lightning-AI/LitServe/)
- [Supervision](https://github.com/roboflow/supervision)

## License

Expand Down
Binary file modified assets/outputs/car.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/outputs/fruits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/outputs/kiwi.png
Binary file not shown.
Binary file modified assets/outputs/person.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/person.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
gradio==4.44.0
litserve==0.2.2
gradio==5.0.2
litserve==0.2.3
opencv-python-headless==4.10.0.84
pydantic==2.9.2
sam-2 @ git+https://github.com/facebookresearch/segment-anything-2@7e1596c0b6462eb1d1ba7e1492430fed95023598
Expand All @@ -10,5 +10,5 @@ uvloop==0.20.0

--extra-index-url https://download.pytorch.org/whl/cu124
torch==2.4.1
--extra-index-url https://download.pytorch.org/whl/cu113
--extra-index-url https://download.pytorch.org/whl/cu124
torchvision==0.19.1

0 comments on commit 29940a2

Please sign in to comment.